diff --git a/packages/puppeteer-core/src/node/FirefoxLauncher.test.ts b/packages/puppeteer-core/src/node/FirefoxLauncher.test.ts new file mode 100644 index 00000000000..ec11967dec8 --- /dev/null +++ b/packages/puppeteer-core/src/node/FirefoxLauncher.test.ts @@ -0,0 +1,57 @@ +/** + * Copyright 2023 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {describe, it} from 'node:test'; + +import expect from 'expect'; + +import {FirefoxLauncher} from './FirefoxLauncher.js'; + +describe('FirefoxLauncher', function () { + describe('getPreferences', function () { + it('should return preferences for CDP', async () => { + const prefs: Record = FirefoxLauncher.getPreferences( + { + test: 1, + }, + undefined + ); + expect(prefs['test']).toBe(1); + expect(prefs['fission.bfcacheInParent']).toBe(false); + expect(prefs['fission.webContentIsolationStrategy']).toBe(0); + expect(prefs).toEqual( + FirefoxLauncher.getPreferences( + { + test: 1, + }, + 'cdp' + ) + ); + }); + + it('should return preferences for WebDriver BiDi', async () => { + const prefs: Record = FirefoxLauncher.getPreferences( + { + test: 1, + }, + 'webDriverBiDi' + ); + expect(prefs['test']).toBe(1); + expect(prefs['fission.bfcacheInParent']).toBe(undefined); + expect(prefs['fission.webContentIsolationStrategy']).toBe(0); + }); + }); +}); diff --git a/packages/puppeteer-core/src/node/FirefoxLauncher.ts b/packages/puppeteer-core/src/node/FirefoxLauncher.ts index cd610d24516..f91f613fe74 100644 --- a/packages/puppeteer-core/src/node/FirefoxLauncher.ts +++ b/packages/puppeteer-core/src/node/FirefoxLauncher.ts @@ -45,6 +45,28 @@ export class FirefoxLauncher extends ProductLauncher { constructor(puppeteer: PuppeteerNode) { super(puppeteer, 'firefox'); } + + static getPreferences( + extraPrefsFirefox?: Record, + protocol?: 'cdp' | 'webDriverBiDi' + ): Record { + return { + ...extraPrefsFirefox, + ...(protocol === 'webDriverBiDi' + ? {} + : { + // Temporarily force disable BFCache in parent (https://bit.ly/bug-1732263) + 'fission.bfcacheInParent': false, + }), + // Force all web content to use a single content process. TODO: remove + // this once Firefox supports mouse event dispatch from the main frame + // context. Once this happens, webContentIsolationStrategy should only + // be set for CDP. See + // https://bugzilla.mozilla.org/show_bug.cgi?id=1773393 + 'fission.webContentIsolationStrategy': 0, + }; + } + /** * @internal */ @@ -113,21 +135,10 @@ export class FirefoxLauncher extends ProductLauncher { await createProfile(SupportedBrowsers.FIREFOX, { path: userDataDir, - preferences: { - ...extraPrefsFirefox, - ...(options.protocol === 'cdp' - ? { - // Temporarily force disable BFCache in parent (https://bit.ly/bug-1732263) - 'fission.bfcacheInParent': false, - } - : {}), - // Force all web content to use a single content process. TODO: remove - // this once Firefox supports mouse event dispatch from the main frame - // context. Once this happens, webContentIsolationStrategy should only - // be set for CDP. See - // https://bugzilla.mozilla.org/show_bug.cgi?id=1773393 - 'fission.webContentIsolationStrategy': 0, - }, + preferences: FirefoxLauncher.getPreferences( + extraPrefsFirefox, + options.protocol + ), }); let firefoxExecutable: string;