Skip to content

Instantly share code, notes, and snippets.

@markkcc
Last active November 23, 2023 07:00
Show Gist options
  • Save markkcc/017a9977a01dec7410c4d9cd4f188ba2 to your computer and use it in GitHub Desktop.
Save markkcc/017a9977a01dec7410c4d9cd4f188ba2 to your computer and use it in GitHub Desktop.
Fixing Chromedriver compatibility issues in Heroku

Fixing Selenium Webdriver Compatibility Errors in Heroku

The Problem

If you are using the chromedriver and Google Chrome Heroku buildpacks together, you may run into a driver compatibility issue with the version of chrome installed.

Example error:

Selenium::WebDriver::Error::SessionNotCreatedError (session not created: This version of ChromeDriver only supports Chrome version 83):

The Solution

Use the webdrivers Ruby Gem instead of the chromedriver buildpack. It detects the version of Chrome you have installed, and then installs the appropriate version of chromedriver.

To use the gem, include it in your Gemfile:

gem 'webdrivers'

Once the gem is set, you need to tell it where Chrome is installed. If you are using the Chome buildpack, it adds environment variables you can use to get tha path to the installed Chrome binary.

Here is some sample Ruby code to initialize the driver:

options = Selenium::WebDriver::Chrome::Options.new

# Point the Chrome binary path to what's set in the envar
Selenium::WebDriver::Chrome.path = ENV['GOOGLE_CHROME_SHIM'] if ENV['GOOGLE_CHROME_SHIM'].present?

# Log the path for easy debugging
logger.info "Chrome binary path (if any): " + ENV.fetch('GOOGLE_CHROME_SHIM', "nil")

options.add_argument "--window-size=1280x1024"
options.add_argument "--headless"
options.add_argument "--disable-gpu"

driver = Selenium::WebDriver.for :chrome, options: options

Note the GOOGLE_CHROME_SHIM envar is automatically set by your Chrome Heroku Buildpack, which you should make sure is running on your Heroku instance. Once you've switched to using the webdrivers gem, you can safely remove the heroku chromedriver buildpack from your app.

Additional Resources

https://github.com/titusfortner/webdrivers/wiki/Heroku-buildpack-google-chrome

Heroku CLI Cheatsheet

Taking Screenshots with Selenium

@ozifirebrand
Copy link

I have this same problem of compatibility between chrome and Chromedriver in my Java app. I'm using Heroku's Chrome and Chromedriver buildpacks and app crashes everytime there's a new update on Chrome's version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment