Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Chrome on Apple M1 architecture #191

Closed
MichaelHoste opened this issue Dec 30, 2020 · 10 comments · Fixed by #193
Closed

Google Chrome on Apple M1 architecture #191

MichaelHoste opened this issue Dec 30, 2020 · 10 comments · Fixed by #193

Comments

@MichaelHoste
Copy link
Contributor

MichaelHoste commented Dec 30, 2020

Maybe I'm not at the right place to submit this issue. Feel free to close and redirect me.

I have a new Macbook M1, and I installed the M1-specific Google Chrome on my system to avoid using the Rosetta emulation. It works well!

However, when I'm running my test suite, I can see in the Activity Monitor that the headless Chrome is not started with the correct architecture. We can see "Intel" instead of "Apple":

Screenshot 2020-12-30 at 16 32 37

I checked and Google Chrome seems to use Universal Binary, so either Intel or Apple, but the wrong one is started.

Would it be because chromedriver doesn't officially support M1 architecture? [1] And Google Chrome is forced to follow the same architecture?

Is there any way to fix this situation in webdrivers, and force Google Chrome with M1 architecture? It will certainly speed up significantly my test suite.

Or maybe I need to wait when (if?) a M1-specific chromedriver is released?

Any thoughts on this would be welcome 😄

[1] https://chromedriver.storage.googleapis.com/index.html?path=87.0.4280.88/

@kapoorlakshya
Copy link
Collaborator

Hmm... I don't have a M1 mac to reproduce this and I am not seeing any new, specific ChromeOptions or CLI switches to pick a specific one in https://peter.sh/experiments/chromium-command-line-switches/

Might be better to create this issue in the chromium issue tracker.

@MichaelHoste
Copy link
Contributor Author

Thank you for looking at this!

I found a M1 version of chromedriver here (darwin-arm64.zip): https://github.com/electron/electron/releases

I was able to test it, it started the correct Chrome and... holy cow, that was fast! My (parallel) test suite went from 2min20 to 1min30. And only 140 of my 900 specs use the browser. I knew they were the slowest specs but still, that was unexpected.

For reference, my high-end 2018 i7 MacBook ran the specs in 2min30. Apple is not kidding with this new CPU.

I have a naïve question: would it be possible to compile chromedriver directly with this gem?

Either way, I will open an issue on Chromium to ask for an ARM64 version.

Have a great New Year!

@kapoorlakshya
Copy link
Collaborator

kapoorlakshya commented Dec 31, 2020

I found a M1 version of chromedriver here (darwin-arm64.zip): https://github.com/electron/electron/releases

Nice! I am not seeing the darwin-arm64 version officially listed for v88 or v89 (beta), so let us know what you find out from the Chromium team. If they're not responsive then we could consider fetching it from that electron release page you shared until an official release is available.

My (parallel) test suite went from 2min20 to 1min30.

Wow that's really good.

would it be possible to compile chromedriver directly with this gem?

Nope. The gem simply reaches out to the download servers and fetches the binary matching your browser version.

I'll keep this issue open until we have implemented support for the M1 specific chromedriver.

@rubiety
Copy link

rubiety commented Dec 31, 2020

I also had success getting Chrome invoked natively (arm64) when using Electron v11.1.1's chromedriver build for darwin-arm64 and putting it in ~/.webdrivers/chromedriver.

However, unlike the original x86 one installed, for some reason this build was not able to find my Google Chrome application binary:

Selenium::WebDriver::Error::UnknownError:
  unknown error: cannot find Chrome binary
    (Driver info: chromedriver=87.0.4280.88 (b66d19be4d887361d1cfaa4bf22fe2cdc2361496-refs/heads/master@{#829380}),platform=Mac OS X 11.0.0 arm64)

I was able to fix this by manually specifying the binary path on my machine with something like this, in the context of capybara / selenium webdriver (where SELENIUM_CHROME_BINARY_PATH is set in my .env):

Capybara.register_driver :headless_chrome do |app|
  client = Selenium::WebDriver::Remote::Http::Default.new
  client.read_timeout = 240

  capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
    chromeOptions: {
      args: %w(headless disable-gpu window-size=1440,900),
      prefs: chrome_preferences,
      w3c: false,
      binary: ENV["SELENIUM_CHROME_BINARY_PATH"]
    }
  )

  Capybara::Selenium::Driver.new(app,
    browser: :chrome,
    desired_capabilities: capabilities,
    http_client: client
  )
end

For me, capybara feature specs are running about 20% faster under native arm64 Chrome / chromedriver.

@MichaelHoste
Copy link
Contributor Author

I opened an issue on the Chromium bugtracker: https://bugs.chromium.org/p/chromium/issues/detail?id=1162906

Feel free to upvote it to increase the chances someone sees it (62361 opened issues 😄 ).

@rubiety:
for some reason this build was not able to find my Google Chrome application binary

I had the same issue with the path to Chrome, maybe Electron built the binary with another default path?
I fixed it by using this line:

Selenium::WebDriver::Chrome.path = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'

@rubiety:
For me, capybara feature specs are running about 20% faster under native arm64 Chrome / chromedriver.

I have noticed that in my case, the improvements were way better using multi-core than single-core. Are you already using something like https://github.com/grosser/parallel_tests ?

@kapoorlakshya:
If they're not responsive then we could consider fetching it from that electron release page you shared until an official release is available.
I'll keep this issue open until we have implemented support for the M1 specific chromedriver.

Thank you! It's really appreciated! 👍

@MichaelHoste
Copy link
Contributor Author

I just found out that ChromeDriver uses a separate bugtracker, and a similar ticket is already open: https://bugs.chromium.org/p/chromedriver/issues/detail?id=3688

Thanks for reporting the issue. We have plan to release the ChromeDriver binary that would supports Apple m1 early next year. It would be a separate binary.

🎉

@kapoorlakshya
Copy link
Collaborator

@MichaelHoste That's good to know. I have left a comment in that ticket. Thanks!

@MichaelHoste
Copy link
Contributor Author

MichaelHoste commented Jan 7, 2021

I just opened a pull request to be able to download the correct chromedriver for your Mac from the official storage (like this one: https://chromedriver.storage.googleapis.com/index.html?path=87.0.4280.88/).

Apparently, with the official M1 chromedriver version, it's not anymore needed to define the Google Chrome path manually like described by @rubiety or myself. It just works! 🍾

kapoorlakshya pushed a commit that referenced this issue Jan 12, 2021
* Add support for Apple M1 architecture (chromedriver). Fixes #191

* Code Improvements
@pawelnguyen
Copy link

Thanks a lot Michael for fixing that! 🎉

In case someone ends up here trying to switch their Intel chromedriver to M1 chromedriver to speed up tests like I did - you need to delete the existing driver and the new one will be downloaded. In my case it shaved off 40% of test run time.
https://github.com/titusfortner/webdrivers#chrome-and-edge-on-apple-m1-arm64

@danilokleber
Copy link

Hi. I don't know if I'm doing anything wrong but chromedriver appears in Activity Monitor as Intel and not Apple (also the logs are saying so). I removed everything in ~/.webdrivers before running tests for the matter.

Debug Info

Webdrivers version: 4.6.1
Ruby version: 2.4.10
Operating system / CI Environment: macOS 12.5
Browser and version: Chromium version 104.0.5112.81 (Official Build, ungoogled-chromium) (arm64)

Debug Output

2022-08-16 16:19:37 DEBUG Webdrivers Checking current version
2022-08-16 16:19:37 DEBUG Webdrivers /Users/bytes/.webdrivers/chromedriver is not already downloaded
2022-08-16 16:19:37 DEBUG Webdrivers Selenium::WebDriver::Chrome.path: /Applications/Chromium.app/Contents/MacOS/Chromium
2022-08-16 16:19:37 DEBUG Webdrivers making System call: ["/Applications/Chromium.app/Contents/MacOS/Chromium", "--version"]
2022-08-16 16:19:37 DEBUG Webdrivers System call returned: Chromium 104.0.5112.81

2022-08-16 16:19:37 DEBUG Webdrivers Browser version: Chromium 104.0.5112.81
2022-08-16 16:19:37 DEBUG Webdrivers Selenium::WebDriver::Chrome.path: /Applications/Chromium.app/Contents/MacOS/Chromium
2022-08-16 16:19:37 DEBUG Webdrivers making System call: ["/Applications/Chromium.app/Contents/MacOS/Chromium", "--version"]
2022-08-16 16:19:37 DEBUG Webdrivers System call returned: Chromium 104.0.5112.81

2022-08-16 16:19:37 DEBUG Webdrivers Browser version: Chromium 104.0.5112.81
2022-08-16 16:19:37 DEBUG Webdrivers Making network call to https://chromedriver.storage.googleapis.com/LATEST_RELEASE_104.0.5112
2022-08-16 16:19:37 DEBUG Webdrivers Get response: #<Net::HTTPOK 200 OK readbody=true>
2022-08-16 16:19:37 DEBUG Webdrivers Latest version available: 104.0.5112.79
2022-08-16 16:19:37 DEBUG Webdrivers Apple architecture: Intel (mac64)
2022-08-16 16:19:37 DEBUG Webdrivers chromedriver version is NOT Apple M1 compatible. Required >= 87.0.4280.88
2022-08-16 16:19:37 DEBUG Webdrivers chromedriver URL: https://chromedriver.storage.googleapis.com/104.0.5112.79/chromedriver_mac64.zip
2022-08-16 16:19:37 DEBUG Webdrivers Making network call to https://chromedriver.storage.googleapis.com/104.0.5112.79/chromedriver_mac64.zip
2022-08-16 16:19:38 DEBUG Webdrivers Get response: #<Net::HTTPOK 200 OK readbody=true>
2022-08-16 16:19:38 DEBUG Webdrivers Successfully downloaded /var/folders/dz/3r5lkh5d1y39h26ht91x36lr0000gn/T/20220816-91087-1rke9avchromedriver_mac64.zip
2022-08-16 16:19:38 DEBUG Webdrivers Decompressing /var/folders/dz/3r5lkh5d1y39h26ht91x36lr0000gn/T/20220816-91087-1rke9avchromedriver_mac64.zip
2022-08-16 16:19:38 DEBUG Webdrivers Completed download and processing of /Users/bytes/.webdrivers/chromedriver

Thanks for any help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants