11#! /usr/bin/env bash
22
3+ # Running:
4+ # npm run chrome
5+ # or
6+ # npm explore -g lighthouse -- npm run chrome
7+
8+ # You can also add custom cmd line flags for Chrome:
9+ # npm run chrome -- --show-paint-rects
10+
311CHROME_ARGS=$@
412
13+ INITIAL_URL=" about:blank"
14+ TMP_PROFILE_DIR=$( mktemp -d -t lighthouse.XXXXXXXXXX)
15+ CHROME_FLAGS=" --remote-debugging-port=9222 --user-data-dir=$TMP_PROFILE_DIR --no-first-run $CHROME_ARGS "
16+ CHROME_PATH=" "
17+
18+ log_warning () {
19+ green=" \e[38;5;121m"
20+ reset=" \e[0m"
21+ read -d ' ' warning << EOF
22+ ; Launching Chrome w/ flags from path: $CHROME_PATH
23+ ;
24+ ; Run Lighthouse from another Terminal tab or window. Ctrl-C here will terminate Chrome
25+ EOF
26+ printf " %b$warning %b\n\n" " $green " " $reset "
27+ }
28+
529launch_osx () {
630 LSREGISTER=/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister
731 CHROME_CANARY_PATH=${CHROME_CANARY_PATH:- $($LSREGISTER -dump | grep -i " google chrome canary.app$" | awk ' {$1=""; print $0}' | head -n1 | xargs)}
832 CHROME_CANARY_EXEC_PATH=" ${CHROME_CANARY_PATH} /Contents/MacOS/Google Chrome Canary"
9- echo " Using Chrome Canary from path ${CHROME_CANARY_PATH} "
33+ CHROME_PATH=" $CHROME_CANARY_PATH "
34+ log_warning
1035 if [ ! -f " $CHROME_CANARY_EXEC_PATH " ]; then
1136 echo " You must install Google Chrome Canary to use lighthouse"
1237 echo " You can download it from https://www.google.com/chrome/browser/canary.html"
1338 exit 1
1439 fi
15- TMP_PROFILE_DIR=$( mktemp -d -t lighthouse)
16- " $CHROME_CANARY_EXEC_PATH " \
17- --remote-debugging-port=9222 \
18- --no-first-run \
19- --user-data-dir=$TMP_PROFILE_DIR \
20- $CHROME_ARGS \
21- " about:blank"
22- rm -r $TMP_PROFILE_DIR
40+ " $CHROME_CANARY_EXEC_PATH " $CHROME_FLAGS " $INITIAL_URL "
41+ rm -r " $TMP_PROFILE_DIR "
2342}
2443
2544launch_linux () {
@@ -29,19 +48,12 @@ launch_linux() {
2948 exit 1
3049 fi
3150
32- TMP_PROFILE_DIR=$( mktemp -d -t lighthouse.XXXXXXXXXX)
33- echo " Launching Google Chrome from $LIGHTHOUSE_CHROMIUM_PATH "
34- " $LIGHTHOUSE_CHROMIUM_PATH " \
35- --disable-setuid-sandbox \
36- --remote-debugging-port=9222 \
37- --no-first-run \
38- --user-data-dir=$TMP_PROFILE_DIR \
39- $CHROME_ARGS \
40- " about:blank"
41- rm -r $TMP_PROFILE_DIR
51+ CHROME_PATH=" $LIGHTHOUSE_CHROMIUM_PATH "
52+ log_warning
53+ " $LIGHTHOUSE_CHROMIUM_PATH " --disable-setuid-sandbox $CHROME_FLAGS " $INITIAL_URL "
54+ rm -r " $TMP_PROFILE_DIR "
4255}
4356
44-
4557if [[ $( uname) == " Darwin" ]]; then
4658 launch_osx
4759else
0 commit comments