Skip to content

Commit fdff2ae

Browse files
committed
launch-chrome: inform user about Chrome launch. refactor & cleanup.
1 parent 39ae86a commit fdff2ae

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed

lighthouse-core/scripts/launch-chrome.sh

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,44 @@
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+
311
CHROME_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+
529
launch_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

2544
launch_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-
4557
if [[ $(uname) == "Darwin" ]]; then
4658
launch_osx
4759
else

0 commit comments

Comments
 (0)