feat: support firefoxUserPrefs in launchPersistentContext (#27840)

Fixes #27773.
This commit is contained in:
Dmitry Gozman 2023-10-27 09:24:41 -07:00 committed by GitHub
parent d395a38a63
commit 88f30d1ce2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 36 additions and 10 deletions

View File

@ -337,6 +337,12 @@ use a temporary directory instead.
### option: BrowserType.launchPersistentContext.-inline- = %%-shared-context-params-list-v1.8-%%
* since: v1.8
### option: BrowserType.launchPersistentContext.firefoxUserPrefs = %%-js-python-browser-option-firefoxuserprefs-%%
* since: v1.40
### option: BrowserType.launchPersistentContext.firefoxUserPrefs2 = %%-csharp-java-browser-option-firefoxuserprefs-%%
* since: v1.40
## async method: BrowserType.launchServer
* since: v1.8
* langs: js

View File

@ -76,14 +76,11 @@ type LaunchOverrides = {
ignoreDefaultArgs?: boolean | string[];
env?: Env;
logger?: Logger;
firefoxUserPrefs?: { [key: string]: string | number | boolean };
};
type FirefoxUserPrefs = {
firefoxUserPrefs?: { [key: string]: string | number | boolean },
};
type LaunchOptionsBase = Omit<channels.BrowserTypeLaunchOptions, 'ignoreAllDefaultArgs' | 'ignoreDefaultArgs' | 'env' | 'firefoxUserPrefs'> & LaunchOverrides;
export type LaunchOptions = LaunchOptionsBase & FirefoxUserPrefs;
export type LaunchPersistentContextOptions = Omit<LaunchOptionsBase & BrowserContextOptions, 'storageState'>;
export type LaunchOptions = Omit<channels.BrowserTypeLaunchOptions, 'ignoreAllDefaultArgs' | 'ignoreDefaultArgs' | 'env' | 'firefoxUserPrefs'> & LaunchOverrides;
export type LaunchPersistentContextOptions = Omit<LaunchOptions & BrowserContextOptions, 'storageState'>;
export type ConnectOptions = {
wsEndpoint: string,
@ -117,7 +114,8 @@ export type LaunchServerOptions = {
port?: number,
wsPath?: string,
logger?: Logger,
} & FirefoxUserPrefs;
firefoxUserPrefs?: { [key: string]: string | number | boolean };
};
export type LaunchAndroidServerOptions = {
deviceSerialNumber?: string,

View File

@ -521,6 +521,7 @@ scheme.BrowserTypeLaunchPersistentContextParams = tObject({
downloadsPath: tOptional(tString),
tracesDir: tOptional(tString),
chromiumSandbox: tOptional(tBoolean),
firefoxUserPrefs: tOptional(tAny),
noDefaultViewport: tOptional(tBoolean),
viewport: tOptional(tObject({
width: tNumber,

View File

@ -43,7 +43,7 @@ export class FFBrowser extends Browser {
const browser = new FFBrowser(parent, connection, options);
if ((options as any).__testHookOnConnectToBrowser)
await (options as any).__testHookOnConnectToBrowser();
let firefoxUserPrefs = options.persistent ? {} : options.originalLaunchOptions.firefoxUserPrefs ?? {};
let firefoxUserPrefs = options.originalLaunchOptions.firefoxUserPrefs ?? {};
if (Object.keys(kBandaidFirefoxUserPrefs).length)
firefoxUserPrefs = { ...kBandaidFirefoxUserPrefs, ...firefoxUserPrefs };
const promises: Promise<any>[] = [

View File

@ -12841,6 +12841,12 @@ export interface BrowserType<Unused = {}> {
*/
extraHTTPHeaders?: { [key: string]: string; };
/**
* Firefox user preferences. Learn more about the Firefox user preferences at
* [`about:config`](https://support.mozilla.org/en-US/kb/about-config-editor-firefox).
*/
firefoxUserPrefs?: { [key: string]: string|number|boolean; };
/**
* Emulates `'forced-colors'` media feature, supported values are `'active'`, `'none'`. See
* [page.emulateMedia([options])](https://playwright.dev/docs/api/class-page#page-emulate-media) for more details.

View File

@ -929,6 +929,7 @@ export type BrowserTypeLaunchPersistentContextParams = {
downloadsPath?: string,
tracesDir?: string,
chromiumSandbox?: boolean,
firefoxUserPrefs?: any,
noDefaultViewport?: boolean,
viewport?: {
width: number,
@ -1000,6 +1001,7 @@ export type BrowserTypeLaunchPersistentContextOptions = {
downloadsPath?: string,
tracesDir?: string,
chromiumSandbox?: boolean,
firefoxUserPrefs?: any,
noDefaultViewport?: boolean,
viewport?: {
width: number,

View File

@ -411,6 +411,7 @@ LaunchOptions:
downloadsPath: string?
tracesDir: string?
chromiumSandbox: boolean?
firefoxUserPrefs: json?
ContextOptions:
@ -868,7 +869,6 @@ BrowserType:
launch:
parameters:
$mixin: LaunchOptions
firefoxUserPrefs: json?
slowMo: number?
returns:
browser: Browser

View File

@ -52,7 +52,7 @@ export const LogTab: React.FunctionComponent<{
});
}
return entries;
}, [action]);
}, [action, isLive]);
if (!entries.length)
return <PlaceholderPanel text='No log entries' />;

View File

@ -30,3 +30,16 @@ it('should pass firefox user preferences', async ({ browserType, mode }) => {
expect(error.message).toContain('NS_ERROR_PROXY_CONNECTION_REFUSED');
await browser.close();
});
it('should pass firefox user preferences in persistent', async ({ mode, launchPersistent }) => {
it.skip(mode.startsWith('service'));
const { page } = await launchPersistent({
firefoxUserPrefs: {
'network.proxy.type': 1,
'network.proxy.http': '127.0.0.1',
'network.proxy.http_port': 3333,
}
});
const error = await page.goto('http://example.com').catch(e => e);
expect(error.message).toContain('NS_ERROR_PROXY_CONNECTION_REFUSED');
});