Skip to content

Instantly share code, notes, and snippets.

@seanlinsley
Created March 14, 2019 00:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanlinsley/36a204862f08942b0667e941331f3a75 to your computer and use it in GitHub Desktop.
Save seanlinsley/36a204862f08942b0667e941331f3a75 to your computer and use it in GitHub Desktop.
Ensures that chromedriver always matches the version of Chrome that's currently installed
# https://github.com/flavorjones/chromedriver-helper/issues/79
# http://chromedriver.storage.googleapis.com/index.html
require 'open-uri'
require 'shellwords'
executable = if RUBY_PLATFORM =~ /darwin/
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
else
'google-chrome'
end
version = if system("which #{Shellwords.escape(executable)} > /dev/null 2>&1")
`#{Shellwords.escape(executable)} --version`
else
fail 'unable to determine Chrome binary location. Chrome must already be installed before installing chromedriver'
end
# Matches all except the last set of digits, as documented here:
# https://sites.google.com/a/chromium.org/chromedriver/downloads/version-selection
if /Google Chrome ([0-9,.]+)\.\d+ \n/ =~ version
version = Regexp.last_match(1)
else
fail "unexpected version string: #{version}"
end
chromedriver_version = open("https://chromedriver.storage.googleapis.com/LATEST_RELEASE_#{version}").read
Chromedriver.set_version chromedriver_version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment