jest-puppeteer
jest-puppeteer copied to clipboard
Firefox browser configuration fails on setup
🐛 Bug Report
On puppeteer 24.1.1, and jest-puppeteer 11.0.0, using the firefox configuration from the README fails to initialize. See error below:
> [email protected] test
> jest
FAIL ./google.test.js
● Test suite failed to run
ProtocolError: Protocol error (Target.getBrowserContexts): undefined
at Callback.<instance_members_initializer> (node_modules/puppeteer-core/src/common/CallbackRegistry.ts:125:12)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.161 s
Ran all test suites.
To Reproduce
- In
jest-puppeteer.config.js, use the configuration
module.exports = {
launch: {
browser: 'firefox',
headless: process.env.HEADLESS !== 'false',
},
};
- Run test script (i.e.
npm run test) and check if browser launches successfully.
A minimal repo is included below
Expected behavior
Firefox browser launches and connects for tests.
Link to repl or repo
https://github.com/gvanhorne/jest-puppeteer-firefox
Environment
## System:
- OS: Linux 5.15 Ubuntu 22.04.3 LTS 22.04.3 LTS (Jammy Jellyfish)
- CPU: (8) x64 Intel(R) Xeon(R) E-2174G CPU @ 3.80GHz
- Memory: 9.74 GB / 15.54 GB
- Container: Yes
- Shell: 5.1.16 - /bin/bash
## Binaries:
- Node: 22.5.1 - ~/.nvm/versions/node/v22.5.1/bin/node
- npm: 10.8.2 - ~/.nvm/versions/node/v22.5.1/bin/npm
## npmPackages:
- jest-puppeteer: ^11.0.0 => 11.0.0
Anything I'm missing here as to why this wouldn't work? The same configuration replacing firefox with chrome runs without complaint.
Hi @gvanhorne, thanks for submitting the issue.
If someone could help fix this it's welcome, here is a Stackoverflow post about the issue: https://stackoverflow.com/questions/57572062/puppeteer-web-protocol-error-target-getbrowsercontexts-not-allowed
I just did some digging around this and the issue is two-fold. First, CDP is no longer maintained in Firefox. When launching Firefox via puppeteer, it automatically sets the protocol to webdriver-bidi. https://github.com/puppeteer/puppeteer/blob/462b8cb2053f780be036cecc445020a6118a718f/packages/puppeteer-core/src/node/BrowserLauncher.ts#L92-L95
Therefore, when connecting to a running instance, you'll need to set the protocol to webDriverBiDi as well.
https://github.com/argos-ci/jest-puppeteer/blob/ddb3fb9d80b2d38d27b327c0d857280edf877f3e/packages/jest-environment-puppeteer/src/browsers.ts#L125-L135
The biggest issue however, is that Firefox does not currently support multiple sessions via webdriver-bidi (launch and connect each count as 1). This can be avoided by using the @puppeteer/browsers. See https://github.com/puppeteer/puppeteer/issues/13267#issuecomment-2459832059.