I\'m trying to run headless chrome on Heroku with ruby. I\'ve installed the buildpacks https://github.com/heroku/heroku-buildpack-google-chrome/ and https://github.com/herok
If anyone else stumbles across this, there's a good example here: https://github.com/jormon/minimal-chrome-on-heroku
We also had the same problem due to the combination of configuration errors and passing the correct options hash to Watir::Browser.new
. We are using watir (6.10.3)
, selenium-webdriver (~> 3.4, >= 3.4.1)
and ruby '2.4.0'
.
To get everything working on Heroku we added the following buildpacks:
To successfully initialize the browser you need to pass the path to chromedriver bin within the options hash. heroku-buildpack-chromedriver provides an environment variable GOOGLE_CHROME_SHIM
for the bin search path. At the end the code which will work locally and on Heroku looks like this:
opts = {
headless: true
}
if (chrome_bin = ENV.fetch('GOOGLE_CHROME_SHIM', nil))
opts.merge!( options: {binary: chrome_bin})
end
browser = Watir::Browser.new :chrome, opts
browser.goto "your url"