karma-runner / karma-firefox-launcher

A Karma plugin. Launcher for Firefox.
MIT License
104 stars 54 forks source link

Cannot start Firefox (or FirefoxHeadless) 121 on macOS Sonoma 14.2.1 (23C71) #328

Closed mgol closed 5 months ago

mgol commented 6 months ago

I cannot start Firefox (or FirefoxHeadless) 121 on macOS Sonoma 14.2.1 (23C71). It used to work on that very OS a few weeks ago, possibly with Firefox 120. EDIT: confirmed - this issue will affect everyone on recent macOS running Firefox 121 or newer.

A very simple test case doesn't work, just follow instructions from https://github.com/mgol/karma-test. When doing so, I am getting:

$ npm test 

> test
> karma start

09 01 2024 00:04:55.436:INFO [karma-server]: Karma v6.4.2 server started at http://localhost:9876/
09 01 2024 00:04:55.437:INFO [launcher]: Launching browsers ChromeHeadless, FirefoxHeadless with concurrency unlimited
09 01 2024 00:04:55.439:INFO [launcher]: Starting browser ChromeHeadless
09 01 2024 00:04:55.441:INFO [launcher]: Starting browser FirefoxHeadless
09 01 2024 00:04:55.446:ERROR [launcher]: Cannot start FirefoxHeadless

09 01 2024 00:04:55.446:ERROR [launcher]: FirefoxHeadless stdout: 
09 01 2024 00:04:55.446:ERROR [launcher]: FirefoxHeadless stderr: 
09 01 2024 00:04:55.447:INFO [launcher]: Trying to start FirefoxHeadless again (1/2).
09 01 2024 00:04:55.451:ERROR [launcher]: Cannot start FirefoxHeadless

09 01 2024 00:04:55.451:ERROR [launcher]: FirefoxHeadless stdout: 
09 01 2024 00:04:55.451:ERROR [launcher]: FirefoxHeadless stderr: 
09 01 2024 00:04:55.451:INFO [launcher]: Trying to start FirefoxHeadless again (2/2).
09 01 2024 00:04:55.455:ERROR [launcher]: Cannot start FirefoxHeadless

09 01 2024 00:04:55.455:ERROR [launcher]: FirefoxHeadless stdout: 
09 01 2024 00:04:55.455:ERROR [launcher]: FirefoxHeadless stderr: 
09 01 2024 00:04:55.455:ERROR [launcher]: FirefoxHeadless failed 2 times (cannot start). Giving up.
09 01 2024 00:04:55.606:INFO [Chrome Headless 120.0.6099.199 (Mac OS 10.15.7)]: Connected on socket kepyKrJsYaeTHzTRAAAB with id 45000797
Chrome Headless 120.0.6099.199 (Mac OS 10.15.7): Executed 1 of 1 SUCCESS (0.001 secs / 0 secs)
TOTAL: 1 SUCCESS

The error message is the same as in #93. However, I am running it directly on a normal OS, not behind Docker.

Krinkle commented 6 months ago

I can reproduce this after upgrading to the latest Firefox, Firefox 121.0.1 (64-bit), with macOS 13, and an Apple M1 processor.

If you enable logLevel: 'DEBUG' in karma.conf.js, there is a bit more detail:

10 01 2024 15:30:03.664:DEBUG [plugin]: Loading karma-* from /Users/krinkle/Temp/karma-test/node_modules
10 01 2024 15:30:03.666:DEBUG [plugin]: Loading plugin /Users/krinkle/Temp/karma-test/node_modules/karma-chrome-launcher.
10 01 2024 15:30:03.668:DEBUG [plugin]: Loading plugin /Users/krinkle/Temp/karma-test/node_modules/karma-firefox-launcher.
10 01 2024 15:30:03.670:DEBUG [plugin]: Loading plugin /Users/krinkle/Temp/karma-test/node_modules/karma-qunit.
10 01 2024 15:30:03.672:DEBUG [web-server]: Instantiating middleware
10 01 2024 15:30:03.682:INFO [karma-server]: Karma v6.4.2 server started at http://localhost:9876/
10 01 2024 15:30:03.682:INFO [launcher]: Launching browsers FirefoxHeadless with concurrency unlimited
10 01 2024 15:30:03.684:INFO [launcher]: Starting browser FirefoxHeadless
10 01 2024 15:30:03.684:DEBUG [launcher]: null -> BEING_CAPTURED
10 01 2024 15:30:03.684:DEBUG [temp-dir]: Creating temp dir at /var/folders/_5/khc4z6kx4nbg4mn5wxyzbsn40000gn/T/karma-8869174
10 01 2024 15:30:03.685:DEBUG [launcher]: /Applications/Firefox.app/Contents/MacOS/firefox-bin http://localhost:9876/?id=8869174 -profile /var/folders/_5/khc4z6kx4nbg4mn5wxyzbsn40000gn/T/karma-8869174 -no-remote -wait-for-browser -headless --start-debugger-server 6000
10 01 2024 15:30:03.721:DEBUG [launcher]: Process FirefoxHeadless exited with code null and signal SIGKILL
10 01 2024 15:30:03.721:ERROR [launcher]: Cannot start FirefoxHeadless

10 01 2024 15:30:03.721:ERROR [launcher]: FirefoxHeadless stdout: 
10 01 2024 15:30:03.721:ERROR [launcher]: FirefoxHeadless stderr: 
10 01 2024 15:30:03.721:DEBUG [temp-dir]: Cleaning temp dir /var/folders/_5/khc4z6kx4nbg4mn5wxyzbsn40000gn/T/karma-8869174
10 01 2024 15:30:03.723:INFO [launcher]: Trying to start FirefoxHeadless again (1/2).
[…]

This is reproducible even without Karma:

$ /Applications/Firefox.app/Contents/MacOS/firefox-bin
Killed: 9

Hence this is more about Firefox generally no longer working from the command-line, and not something Karma can do anything about. I suspect it has something to do with the security mechanisms in macOS disallowing the process to run from the Terminal application. Perhaps Mozilla changed the way it signs the Firefox binary? Or perhaps Firefox changed the way it replaces the binary during an upgrade that makes macOS treat it as suspicious.

Possibly related:

Krinkle commented 6 months ago

Resolution:

Selenium has the same issue:

mgol commented 6 months ago

This issue will affect everyone on recent macOS running Firefox 121 or newer.

JoeWhetzel commented 5 months ago

I've been able to patch a workaround by replacing the firefox-bin executable with a symlink that pointed to the firefox executable;

sudo mv /Applications/Firefox.app/Contents/MacOS/firefox-bin /Applications/Firefox.app/Contents/MacOS/firefox-bin.old sudo ln -s /Applications/Firefox.app/Contents/MacOS/firefox /Applications/Firefox.app/Contents/MacOS/firefox-bin

So my guess would be that if in karma-firefox-launcher/index.js the line const suffix = '.app/Contents/MacOS/firefox-bin' were replaced with const suffix = '.app/Contents/MacOS/firefox' it may work.

Finesse commented 5 months ago

This issue will affect everyone on recent macOS

It also happens on macOS 11.7.10 on an Intel processor

mgol commented 5 months ago

It also happens on macOS 11.7.10 on an Intel processor

Right; the issue is independent on the macOS version, it affects all Firefox versions from 121 on any macOS version. Basically, right now karma-firefox-launcher is completely broken for all macOS users.

@birtles @ewinslow I know this is not a security fix but considering that without PR #330 this package is not working at all on macOS and that the fix is a one-liner, is there any chance of merging it & releasing a new version?

mgol commented 5 months ago

@pmvald Thanks for merging #330. Any chance for a new release now so that we can use this fix?

Krinkle commented 4 months ago

@XhmikosR @pmvald Would you be able to publish a release for the above? Alternatively, I'd be happy to help myself if you'd be comfortable with me having Git write and npm co-owner access for this package (ref https://github.com/karma-runner/karma-qunit/pull/185).

XhmikosR commented 4 months ago

@Krinkle I don't even have rights myself 😛

IIRC I only had rights in karma-qunit.