Skip to content

Instantly share code, notes, and snippets.

@JParkinson1991
Last active April 1, 2020 08:25
Show Gist options
  • Save JParkinson1991/777ba1df79a41d5c2fdee1c7beeecbb1 to your computer and use it in GitHub Desktop.
Save JParkinson1991/777ba1df79a41d5c2fdee1c7beeecbb1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# For current version see:
# https://github.com/JParkinson1991/bin/blob/master/google-chrome
# Wraps cli usage of google chrome on MacOS
#
# Requirments: Google Chrome
#
# Run in default mode, open/visible browser, environment defined address/port
# $ google-chrome
#
# Run in default headless mode, environment defined address/port
# $ google-chrome headless
#
# Run as standard, all arguments passed to this script forward to executable
# $ google-chrome [arguments]
if [[ ! -f "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" ]]; then
echo "Google chrome not found"
exit
fi
if [[ $# -eq 0 ]] || [[ $# -eq 1 && "$*" == "headless" ]]; then
debugAddress=${CHROME_DEBUG_ADDRESS:-0.0.0.0}
debugPort=${CHROME_DEBUG_PORT:-9222}
echo "Running in default headless"
echo "Debug Address: ${debugAddress}"
echo "Debug Port: ${debugPort}"
echo ""
args="--remote-debugging-address=$debugAddress --remote-debugging-port=$debugPort"
if [[ "$*" == "headless" ]]; then
args="$args --disable-gpu --headless"
fi
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome $args
else
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome $@
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment