fix: ensure fission.bfcacheInParent is disabled for cdp in Firefox (#11522)

This commit is contained in:
Alex Rudenko 2023-12-08 12:40:46 +01:00 committed by GitHub
parent 04b879944a
commit b4a65245b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 83 additions and 15 deletions

View File

@ -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);
});
});
});

View File

@ -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
*/
@ -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;