Webdrivers::NetworkError - Mac64 M1 - ChromeDriver
Asked Answered
L

2

3

My Capybara Selenium Webdriver set up is failing when trying to make a connection to ChromeDriver - It appears they released a version without an M1 version to find at the Chromedriver API https://chromedriver.storage.googleapis.com/index.html?path=106.0.5249.61/

Error:

Webdrivers::NetworkError:
       Net::HTTPServerException: 404 "Not Found" with https://chromedriver.storage.googleapis.com/106.0.5249.61/chromedriver_mac64_m1.zip

CODE:

Capybara.register_driver :headless_chrome do |app|
  options.add_argument("--disable-gpu")
  options.add_argument("--headless")
  options.add_argument("--no-sandbox")
  options.add_argument("--window-size=1920,1080")

  driver = Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)

  ### Allow file downloads in Google Chrome when headless
  ### https://bugs.chromium.org/p/chromium/issues/detail?id=696481#c89 
  bridge = driver.browser.send(:bridge)

  path = "/session/:session_id/chromium/send_command"
  path[":session_id"] = bridge.session_id

  bridge.http.call(:post, path, cmd: "Page.setDownloadBehavior",
                                params: {
                                  behavior: "allow",
                                  downloadPath: "/tmp/downloads",
                                })
  ###

  driver
end

When the application calls driver.browser I get the error above and that is because the file it's looking for does not exist.

Can I set a specific version of chrome driver or what system to look for when initializing the driver?

Limber answered 29/9, 2022 at 18:54 Comment(0)
E
6

I got an apple silicon mac and still had the old (intel) chromedriver. To solve, I had to:

  1. Install the apple silicon chromedriver
  2. Update the webdrivers gem to >= 5.2.0

You may only need to do the second step, depending on whether you already have the apple silicon chromedriver installed. See below for how to check.

Check you have apple silicon (arm) chromedriver

Run these two commands and if the output looks like below, you have the apple silicon chromedriver installed and can skip to updating the webdrivers gem:

which chromedriver
# /opt/homebrew/bin/chromedriver

file $(which chromedriver)
# /opt/homebrew/bin/chromedriver: Mach-O 64-bit executable arm64

But if the output is something like this, you still have the intel version of chromedriver and need to update to the apple silicon version:

which chromedriver
# /usr/local/bin/chromedriver

file $(which chromedriver)
# /usr/local/bin/pandoc: Mach-O 64-bit executable x86_64

To install the apple silicon chromedriver:

brew install --cask chromedriver

In a new terminal window run which chromedriver and file $(which chromedriver) again to check it now shows apple silicon (arm) versions.

If you get an error from Apple:

“chromedriver” can’t be opened because Apple cannot check it for malicious software.

Just run this and try again:

xattr -d com.apple.quarantine $(which chromedriver)

Update webdrivers gem to >= 5.2.0

The webdrivers gem must be >= 5.2.0 so it knows where to look for the apple silicon chromedriver.

In my Gemfile was this:

gem "webdrivers"

so I changed it to:

gem "webdrivers", "~> 5.2.0"

bundle install, and everything works.

Engeddi answered 25/2, 2023 at 1:45 Comment(0)
L
1

Fix is posted here: https://github.com/titusfortner/webdrivers/pull/239 - This is a known issue in "webdrivers"

Limber answered 29/9, 2022 at 20:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.