Skip to content

Commit

Permalink
feat: support firefoxUserPrefs in launchPersistentContext (#27840)
Browse files Browse the repository at this point in the history
Fixes #27773.
  • Loading branch information
dgozman authored Oct 27, 2023
1 parent d395a38 commit 88f30d1
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 10 deletions.
6 changes: 6 additions & 0 deletions docs/src/api/class-browsertype.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 5 additions & 7 deletions packages/playwright-core/src/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/playwright-core/src/protocol/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/server/firefox/ffBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>[] = [
Expand Down
6 changes: 6 additions & 0 deletions packages/playwright-core/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions packages/protocol/src/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,7 @@ export type BrowserTypeLaunchPersistentContextParams = {
downloadsPath?: string,
tracesDir?: string,
chromiumSandbox?: boolean,
firefoxUserPrefs?: any,
noDefaultViewport?: boolean,
viewport?: {
width: number,
Expand Down Expand Up @@ -1000,6 +1001,7 @@ export type BrowserTypeLaunchPersistentContextOptions = {
downloadsPath?: string,
tracesDir?: string,
chromiumSandbox?: boolean,
firefoxUserPrefs?: any,
noDefaultViewport?: boolean,
viewport?: {
width: number,
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/src/protocol.yml
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ LaunchOptions:
downloadsPath: string?
tracesDir: string?
chromiumSandbox: boolean?
firefoxUserPrefs: json?


ContextOptions:
Expand Down Expand Up @@ -868,7 +869,6 @@ BrowserType:
launch:
parameters:
$mixin: LaunchOptions
firefoxUserPrefs: json?
slowMo: number?
returns:
browser: Browser
Expand Down
2 changes: 1 addition & 1 deletion packages/trace-viewer/src/ui/logTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const LogTab: React.FunctionComponent<{
});
}
return entries;
}, [action]);
}, [action, isLive]);
if (!entries.length)
return <PlaceholderPanel text='No log entries' />;

Expand Down
13 changes: 13 additions & 0 deletions tests/library/firefox/launcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

0 comments on commit 88f30d1

Please sign in to comment.