Skip to content

Conversation

@pyoor
Copy link
Contributor

@pyoor pyoor commented Jul 29, 2025

Summary

Closes #609.

Support for CDP was removed in Firefox v141, leaving WebDriver BiDi as the only supported automation protocol. However, Firefox currently does not support multiple concurrent WebDriver BiDi sessions.

To work around this limitation, the setup has been modified to:

  • Launch the browser once
  • Record the wsEndpoint
  • Immediately disconnect

Subsequent access to the browser is handled via puppeteer.connect() using the saved wsEndpoint, ensuring only a single active connection at any time.

Note: I made the minimal changes necessary in order to re-enable support for Firefox. This PR could likely be cleaned up further.

Test Plan

Firefox-specific tests were added and can be run via the test:firefox npm script.

Note: These tests only pass when using jest-environment-puppeteer.
expect-puppeteer is currently incompatible with WebDriver BiDi and supports only CDP, as noted in issue #614.

@pyoor pyoor force-pushed the fix-firefox-webdriver-bidi branch from cdbe8d6 to 8b5a2a5 Compare July 29, 2025 19:52
Copy link
Member

@gregberge gregberge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the concept of this PR sorry. We are now disconnecting all browsers instantely and we connect / disconnect into the close browsers function. Something is not clear to me.

);
const wsEndpoints = browsers.map((browser) => browser.wsEndpoint());
saveWsEndpoints(wsEndpoints);
browsers.forEach((browser) => browser.disconnect());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why disconnecting directly?

Comment on lines +120 to +135
while (wsEndpoints.length) {
const wsEndpoint = wsEndpoints.pop()!;
closeRequests.push(
puppeteer
.connect({
...(config.launch?.browser === "firefox" && {
protocol: "webDriverBiDi",
}),
...config.connect,
...config.launch,
browserURL: undefined,
browserWSEndpoint: wsEndpoint,
})
.then((browser) => browser.close()),
);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you just do a map instead of doing a loop like that?

Comment on lines +125 to +127
...(config.launch?.browser === "firefox" && {
protocol: "webDriverBiDi",
}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have a hack here?

Comment on lines +123 to +124
puppeteer
.connect({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we connecting into the closeBrowsers

@pyoor
Copy link
Contributor Author

pyoor commented Jul 31, 2025

@gregberge I decided to reply here rather than in-line as you may prefer an alternative approach.

Firefox 141+ no longer works because it dropped supported for CDP (puppeteer also remove CDP support for Firefox) and it does not support multiple connections over WebDriver BiDi (CDP did). The easiest way to re-enable support for Firefox is to first launch the browser and record the wsEndpoint. We have to disconnect after the initial setup as other connections are made during connectBrowserFromWorker.

export const connectBrowserFromWorker = async (
config: JestPuppeteerConfig,
): Promise<Browser> => {
const wsEndpoint = getWorkerWsEndpoint();
const puppeteer = getPuppeteer();
return puppeteer.connect({
...config.connect,
...config.launch,
browserURL: undefined,
browserWSEndpoint: wsEndpoint,
});
};

This will throw in firefox. See #609.

I suppose an alternative (and cleaner) fix here would be to return the existing browser instance from globalThis.__jestPptr.browsers in connectBrowserFromWorker? I don't see why it wouldn't work but I also don't know the reasoning for the original multiple connections.

@pyoor
Copy link
Contributor Author

pyoor commented Aug 12, 2025

@gregberge Just following up on this. Is there one approach you'd prefer over the other?

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 this pull request may close these issues.

Firefox browser configuration fails on setup

2 participants