Skip to content

Commit

Permalink
fix: ensure fission.bfcacheInParent is disabled for cdp in Firefox (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
OrKoN committed Dec 8, 2023
1 parent 04b8799 commit b4a6524
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 15 deletions.
57 changes: 57 additions & 0 deletions 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<string, unknown> = 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<string, unknown> = FirefoxLauncher.getPreferences(
{
test: 1,
},
'webDriverBiDi'
);
expect(prefs['test']).toBe(1);
expect(prefs['fission.bfcacheInParent']).toBe(undefined);
expect(prefs['fission.webContentIsolationStrategy']).toBe(0);
});
});
});
41 changes: 26 additions & 15 deletions packages/puppeteer-core/src/node/FirefoxLauncher.ts
Expand Up @@ -45,6 +45,28 @@ export class FirefoxLauncher extends ProductLauncher {
constructor(puppeteer: PuppeteerNode) {
super(puppeteer, 'firefox');
}

static getPreferences(
extraPrefsFirefox?: Record<string, unknown>,
protocol?: 'cdp' | 'webDriverBiDi'
): Record<string, unknown> {
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
*/
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit b4a6524

Please sign in to comment.