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

[🐛 Bug]: Selenium Manager binary not executing on Apple Sillicon #12423

Closed
stephannv opened this issue Jul 26, 2023 · 24 comments
Closed

[🐛 Bug]: Selenium Manager binary not executing on Apple Sillicon #12423

stephannv opened this issue Jul 26, 2023 · 24 comments

Comments

@stephannv
Copy link

stephannv commented Jul 26, 2023

What happened?

When SeleniumManager tries to download Firefox driver for MacOS, it is downloading wrong version. I'm getting " Bad CPU type in executable" error (same error message from this issue mozilla/geckodriver#1984).

On release page has two versions https://github.com/mozilla/geckodriver/releases

  • geckodriver-v0.33.0-macos-aarch64.tar.gz
  • geckodriver-v0.33.0-macos.tar.gz

For Apple Silicon machines, it should download aarch64 version.

Last year I solved this problem on webdrivers gem on this PR: titusfortner/webdrivers#234
Basically: System.apple_m1_architecture? ? 'macos-aarch64.tar.gz' : 'macos.tar.gz'

The apple_m1_architecture? method (I would recommend to change method name to apple_silicon?:

def apple_m1_architecture?
  if platform == 'mac' && RUBY_PLATFORM.include?('arm64-darwin')
    Webdrivers.logger.debug 'Apple architecture: M1 (arm64-darwin)'
    return true
  end

  Webdrivers.logger.debug 'Apple architecture: Intel (mac64)'
  false
end

How can we reproduce the issue?

I'm not sure, I'm using capybara on a Rails project, and just removed `webdrivers` gem to use SeleniumManager automatically.

Relevant log output

Selenium::WebDriver::Error::NoSuchDriverError:
            Unable to obtain geckodriver using Selenium Manager; Unsuccessful command executed: ["/Users/stephann/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.10.0/bin/macos/selenium-manager", "--browser", "firefox", "--output", "json"]; Bad CPU type in executable - /Users/stephann/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.10.0/bin/macos/selenium-manager; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location

# ./spec/system/checkout/add_items_to_cart_spec.rb:42:in `block (3 levels) in <top (required)>'
          # ------------------
          # --- Caused by: ---
          # Errno::EBADARCH:
          #   Bad CPU type in executable - /Users/stephann/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.10.0/bin/macos/selenium-manager
          #   ./spec/system/checkout/add_items_to_cart_spec.rb:42:in `block (3 levels) in <top (required)>'


### Operating System

MacOS Monterey 12.6.7 (21G651)

### Selenium version

selenium-webdriver-4.10.0

### What are the browser(s) and version(s) where you see this issue?

Firefox 115.0.2 (64-bit)

### What are the browser driver(s) and version(s) where you see this issue?

geckodriver

### Are you using Selenium Grid?

I'm not sure, I don't think so
@github-actions
Copy link

@stephannv, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@diemol
Copy link
Member

diemol commented Jul 27, 2023

We have seen this reported in the past, and in all cases the cause was either Rosetta was in use or the Ruby/Python installation was using x86 binaries. We have double checked this and the code in SM is fine. I do have an M1 and it works well.

Please double check and let us know.

@stephannv
Copy link
Author

stephannv commented Jul 27, 2023

Hi @diemol.
I run ruby -v and I got ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin21]. And I don't have any Rosetta versions installed on my MacOS.

Now I downloaded selenium manager from here: https://github.com/SeleniumHQ/selenium/blob/trunk/common/manager/macos/selenium-manager
And executed: ~/Downloads/selenium-manager
I got: zsh: bad CPU type in executable: /Users/stephann/Downloads/selenium-manager
Now I'm not sure if this is related with Geckdriver, it can be related with selenium-manager itself.

Ps.: My chip is M1 Max

@titusfortner
Copy link
Member

Run it with --trace and share the output, please

@stephannv
Copy link
Author

@titusfortner same results:

❯ ~/Downloads/selenium-manager --trace
zsh: bad CPU type in executable: /Users/stephann/Downloads/selenium-manager

❯ /Users/stephann/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.10.0/bin/macos/selenium-manager --trace
zsh: bad CPU type in executable: /Users/stephann/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.10.0/bin/macos/selenium-manager

❯ sudo dtruss ~/Downloads/selenium-manager
dtrace: system integrity protection is on, some features will not be available

dtrace: failed to execute /Users/stephann/Downloads/selenium-manager: Bad CPU type in executable

❯ uname -a
Darwin stephanns-Mac-Studio.local 21.6.0 Darwin Kernel Version 21.6.0: Thu Jun  8 23:56:13 PDT 2023; root:xnu-8020.240.18.701.6~1/RELEASE_ARM64_T6000 arm64

❯ ruby -v
ruby 3.2.1 (2023-02-08 revision 31819e82c8) [arm64-darwin21]

@titusfortner
Copy link
Member

Ah, sorry, your issue says:

Selenium Manager is downloading wrong Firefox driver

but I see now that the selenium-manager binary isn't even executing on your machine.

It is puzzling because the binary is working for everyone else using an M1.
@p0deje do you have any idea what might cause this?

@stephannv
Copy link
Author

Yeah @titusfortner , at first I think it was related with geckodriver, but after downloading selenium manager from repo I could not run selenium-manager.

@titusfortner titusfortner changed the title [🐛 Bug]: Selenium Manager is downloading wrong Firefox driver version on Apple Sillicon [🐛 Bug]: Selenium Manager binary not executing on Apple Sillicon Jul 27, 2023
@sandeepsuryaprasad
Copy link
Contributor

@titusfortner , I do have Mac with Apple-M2, i did not observe this issue. selenium manager gets executed and downloads geckodriver in ~./cache/selenium. I am using python client.

@stephannv
Copy link
Author

@sandeepsuryaprasad do you have rosetta installed?

@sandeepsuryaprasad
Copy link
Contributor

@stephannv, Yes, it is installed. If I try to open an application built for Application (Intel), it works and it is not asking me to install rosetta (that means it is already installed). I can see the option "Open using Rosetta" for Application (Universal)
Apple say's Rosetta is pre-installed on all Mac's that uses apple silicon.
https://support.apple.com/en-us/HT211861

@stephannv
Copy link
Author

My OS is monterey and when I try to open any intel app it shows a dialog asking to install Rosetta.

@sandeepsuryaprasad
Copy link
Contributor

My Mac is running on Ventura. It's pre installed.

@p0deje
Copy link
Member

p0deje commented Jul 29, 2023

There is currently no arm64 version of Selenium-Manager. I suppose once you install Rosetta 2, x64 binaries will automatically be run via Rosetta.

@stephannv
Copy link
Author

I'm do not have experience with Mac OS building tools, so I don't know if generating universal apps are hard, but would be nice if selenium manager was an universal app: https://developer.apple.com/documentation/apple-silicon/building-a-universal-macos-binary

@titusfortner
Copy link
Member

Yes, Selenium Manager is built with Rust, not Swift. Since the binaries for all supported architectures must be included in each release (and checked into the repo), we are balancing the number of architecture-specific binaries and the total size of the packages / repo. For instance, the windows 32 bit binary is also used for both 32 & 64 bit architectures.

Please install Rosetta and seeing if that allows the binary to work for you. Perhaps everyone else already has it installed so it wasn't obvious that we needed to be explicit about it as a requirement.

@jonesdeini
Copy link

Yes, Selenium Manager is built with Rust, not Swift. Since the binaries for all supported architectures must be included in each release (and checked into the repo), we are balancing the number of architecture-specific binaries and the total size of the packages / repo. For instance, the windows 32 bit binary is also used for both 32 & 64 bit architectures.

Please install Rosetta and seeing if that allows the binary to work for you. Perhaps everyone else already has it installed so it wasn't obvious that we needed to be explicit about it as a requirement.

This worked for me. To save some googling for other folks, I installed Rosetta with softwareupdate --install-rosetta

@titusfortner
Copy link
Member

Thanks.
We probably should add a note about this in https://www.selenium.dev/documentation/selenium_manager/

@stephannv
Copy link
Author

By choosing not to make an universal build (or releasing 2 binaries), almost all projects using selenium/manager get a new OS dependency: rosetta. I'm not sure if this is a right decision, I think a universal app should be considered, at least for some time.

@titusfortner
Copy link
Member

  1. Yes, if we could have a universal app we'd love to have it
  2. Based on Mozilla numbers, Apple silicon is 5% of geckodriver downloads. If the choice is having that 5% depend on Rosetta (which is likely installed for other reasons), I'd prefer that to the 95% having to download an extra binary they don't need.

@stephannv
Copy link
Author

@titusfortner

  1. Why selenium manager cannot be a universal app? (Can lipo be used to merge two binaries?)
  2. About the other drivers (eg. chrome), do you know the distribution %?

I'm using M1 for 1+ year for web dev/game dev/audio tools/art software and I never needed to install rosetta, it's the first time a tool requires to install rosetta. And I could not upgrade my OS due to incompatiblity bugs on Ventura.

I saw webdrivers gem is planning migrate to use selenium manager too, so I think removing rosetta dependency it's a good thing. Extra binary size should be 3mb~4mb, nowdays this is less than an few image on a web page.

@titusfortner
Copy link
Member

Looks like Simon figured out how to make it a universal binary using our build system and existing tooling, so we'll probably end up doing that after all.

@p0deje
Copy link
Member

p0deje commented Jul 31, 2023

Follow up in #12455

@stephannv
Copy link
Author

@p0deje I replaced old selenium-manager with selenium-manager from PR artifacts and it's working 🥳:

Screen Shot 2023-07-31 at 19 37 38

And I tried to run directly and worked too:
Screen Shot 2023-07-31 at 19 40 22

Copy link

github-actions bot commented Dec 9, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants