title: How to run Selenium Webdriver correctly on Heroku with a Rails app
body: <p>I’m implementing a very basic <strong>scraper</strong> on my app with the watir gem. It runs perfectly fine locally but when I run it on heroku, it triggers this error : <code>Webdrivers::BrowserNotFound: Failed to find Chrome binary.</code></p>
  <p>I added google-chrome and chromedriver buildpacks to my app to tell Selenium where to find Chrome on Heroku but it still doest not work. Moreover, when I print the options, the binary seems to be correctly set:</p>
  <p><code>#&lt;Selenium::WebDriver::Chrome::Options:0x0000558bdf7ecc30 @args=#&lt;Set: {&quot;--user-data-dir=/app/tmp/chrome&quot;, &quot;--no-sandbox&quot;, &quot;--window-size=1200x600&quot;, &quot;--headless&quot;, &quot;--disable-gpu&quot;}&gt;, @binary=&quot;/app/.apt/usr/bin/google-chrome-stable&quot;, @prefs={}, @extensions=[], @options={}, @emulation={}, @encoded_extensions=[]&gt;</code></p>
  <p>This is my app Buildpack URLs :</p>
  <pre><code>1. heroku/ruby
  2. heroku/google-chrome
  3. heroku/chromedriver
  </code></pre>
  <p>This is my code :</p>
  <pre><code>def new_browser(downloads: false)
  
    options = Selenium::WebDriver::Chrome::Options.new
  
    chrome_dir = File.join Dir.pwd, %w(tmp chrome)
    FileUtils.mkdir_p chrome_dir
    user_data_dir = &quot;--user-data-dir=#{chrome_dir}&quot;
    options.add_argument user_data_dir
  
    if chrome_bin = ENV[&quot;GOOGLE_CHROME_SHIM&quot;]
      options.add_argument &quot;--no-sandbox&quot;
      options.binary = chrome_bin
    end
  
    options.add_argument &quot;--window-size=1200x600&quot;
    options.add_argument &quot;--headless&quot;
    options.add_argument &quot;--disable-gpu&quot;
  
    browser = Watir::Browser.new :chrome, options: options
  
    if downloads
      downloads_dir = File.join Dir.pwd, %w(tmp downloads)
      FileUtils.mkdir_p downloads_dir
  
      bridge = browser.driver.send :bridge
      path = &quot;/session/#{bridge.session_id}/chromium/send_command&quot;
      params = { behavior: &quot;allow&quot;, downloadPath: downloads_dir }
      bridge.http.call(:post, path, cmd: &quot;Page.setDownloadBehavior&quot;,
                                    params: params)
    end
    browser
  end
  </code></pre>
  <p>Any idea how to fix this ? I checked many similar issues on different websites but I did not find anything.</p>