Skip to content

Commit 8b3c864

Browse files
committed
Restore ChromeDriver script (useful for local dev)
1 parent ea0597f commit 8b3c864

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

scripts/chromedriver.sh

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env bash
2+
3+
# installs the appropriate version of ChromeDriver for a given Chrome version
4+
5+
TEMPDIR=$(mktemp -d)
6+
trap 'rm -rf $TEMPDIR' EXIT
7+
8+
# one of google-chrome, google-chrome-stable,
9+
# google-chrome-beta, or google-chrome-unstable
10+
CHROME="${1:-google-chrome}"
11+
12+
major_version=$("$CHROME" --product-version | cut -d . -f 1)
13+
14+
if [ -z "$major_version" ]; then
15+
echo "Failed to look up version of $CHROME"
16+
exit 1
17+
fi
18+
19+
if [ "$major_version" -lt 115 ]; then
20+
echo "This script supports installing ChromeDriver for Chrome 115+ only"
21+
exit 1
22+
fi
23+
24+
channel=Stable
25+
case "$CHROME" in
26+
*beta*)
27+
channel=Beta
28+
;;
29+
*unstable*)
30+
channel=Dev
31+
;;
32+
esac
33+
json_url=https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json
34+
json=$(wget "$json_url" -q -O -)
35+
chromedriver_version=$(echo "$json" | python3 -c "import sys, json; print(json.load(sys.stdin)['channels']['$channel']['version'])")
36+
chromedriver_url=$(echo "$json" | python3 -c "import sys, json; print(next(i['url'] for i in json.load(sys.stdin)['channels']['$channel']['downloads']['chromedriver'] if i['platform'] == 'linux64'))")
37+
38+
if [ -z "$chromedriver_version" ]; then
39+
echo "Failed to retrieve ChromeDriver version"
40+
exit 1
41+
fi
42+
43+
echo "Setting up ChromeDriver version $chromedriver_version ..."
44+
45+
wget -q -O "$TEMPDIR/chromedriver.zip" "$chromedriver_url" \
46+
&& unzip -q -o "$TEMPDIR/chromedriver.zip" chromedriver-linux64/chromedriver -d "$TEMPDIR" \
47+
&& sudo mv "$TEMPDIR/chromedriver-linux64/chromedriver" /usr/local/bin/chromedriver \
48+
&& sudo chmod a+x /usr/local/bin/chromedriver
49+
50+
# check that chromedriver is now present
51+
type chromedriver >/dev/null 2>&1 || {
52+
echo "Failed to install ChromeDriver!"
53+
exit 1
54+
}
55+
56+
chromedriver --version

0 commit comments

Comments
 (0)