jest-puppeteer icon indicating copy to clipboard operation
jest-puppeteer copied to clipboard

Firefox browser configuration fails on setup

Open gvanhorne opened this issue 10 months ago • 2 comments

🐛 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

  1. In jest-puppeteer.config.js, use the configuration
module.exports = {
  launch: {
    browser: 'firefox',
    headless: process.env.HEADLESS !== 'false',
  },
};
  1. 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.

gvanhorne avatar Jan 30 '25 23:01 gvanhorne

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

gregberge avatar Feb 01 '25 14:02 gregberge

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.

pyoor avatar Mar 31 '25 19:03 pyoor