linuxshellgoogle-chrome

Easier way to download chrome driver


I have a set of tests that downloads the latest Google Chrome from https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb and then parses the contents on https://chromedriver.chromium.org/downloads to figure out the right chrome driver version to download. The Chrome version eg: 102.0.5005.115, does not always match the chrome driver version, eg: 102.0.5005.61.

Currently, I parse the contents of https://chromedriver.chromium.org/downloads and try to figure out the right version. This is brittle as the HTML contents may change.

#!/bin/sh
GOOGLE_CHROME_VERSION="$(google-chrome --version | cut -f 3 -d ' ')"

# https://www.chromium.org/developers/version-numbers/
GOOGLE_CHROME_VERSION_MAJOR=$(echo "${GOOGLE_CHROME_VERSION}" | cut -f 1 -d'.')
echo "GOOGLE_CHROME_VERSION_MAJOR => [${GOOGLE_CHROME_VERSION_MAJOR}]"

# https://chromedriver.chromium.org/downloads
GOOGLE_CHROME_DRIVER_LINE=$(curl https://chromedriver.chromium.org/downloads | grep "If you are using Chrome version ${GOOGLE_CHROME_VERSION_MAJOR}," | head -1)
GOOGLE_CHROME_DRIVER_VERSION=$(echo "${GOOGLE_CHROME_DRIVER_LINE}" | rev | cut -f 1 -d' ' | rev)

echo "GOOGLE_CHROME_DRIVER_VERSION => [${GOOGLE_CHROME_DRIVER_VERSION}]"
wget https://chromedriver.storage.googleapis.com/${GOOGLE_CHROME_DRIVER_VERSION}/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
rm chromedriver_linux64.zip
chmod a+x chromedriver
mv chromedriver /usr/local/bin

Is there a simpler way to download a chrome driver for a specific version of google chrome?


Solution

  • https://chromedriver.chromium.org/downloads/version-selection

    I hope this helps. Apparently, it supports some automated URL resolving:

    • First, find out which version of Chrome you are using. Let's say you have Chrome 72.0.3626.81.

    • Take the Chrome version number, remove the last part, and append the result to URL https://chromedriver.storage.googleapis.com/LATEST_RELEASE_. For example, with Chrome version 72.0.3626.81, you'd get a URL https://chromedriver.storage.googleapis.com/LATEST_RELEASE_72.0.3626.

    • Use the URL created in the last step to retrieve a small file containing the version of ChromeDriver to use. For example, the above URL will get your a file containing 72.0.3626.69. (The actual number may change in the future, of course.)

    • Use the version number retrieved from the previous step to construct the URL to download ChromeDriver. With version 72.0.3626.69, the URL would be https://chromedriver.storage.googleapis.com/index.html?path=72.0.3626.69/.

    • After the initial download, it is recommended that you occasionally go through the above process again to see if there are any bug fix releases.