diff --git a/docs/src/test-api/class-testoptions.md b/docs/src/test-api/class-testoptions.md index a7fa677a5d..df41058f36 100644 --- a/docs/src/test-api/class-testoptions.md +++ b/docs/src/test-api/class-testoptions.md @@ -679,7 +679,7 @@ export default defineConfig({ ## property: TestOptions.mockingProxy * since: v1.51 -- type: <[boolean]> Enables the mocking proxy. Playwright will inject the proxy URL into all outgoing requests under the `x-playwright-proxy` header. +- type: <[MockingProxyMode]<"off"|"inject-via-header">> Enables the mocking proxy. Playwright will inject the proxy URL into all outgoing requests under the `x-playwright-proxy` header. **Usage** @@ -688,7 +688,7 @@ import { defineConfig } from '@playwright/test'; export default defineConfig({ use: { - mockingProxy: true + mockingProxy: 'inject-via-header' }, }); ``` \ No newline at end of file diff --git a/packages/playwright-core/src/client/playwright.ts b/packages/playwright-core/src/client/playwright.ts index f60df580ed..f3124fb385 100644 --- a/packages/playwright-core/src/client/playwright.ts +++ b/packages/playwright-core/src/client/playwright.ts @@ -74,8 +74,8 @@ export class Playwright extends ChannelOwner { return (channel as any)._object; } - async _startMockingProxy(requestContextOptions: NewContextOptions) { - const requestContext = await this.request._newContext(requestContextOptions, this._connection.localUtils()._channel); + async _startMockingProxy() { + const requestContext = await this.request._newContext(undefined, this._connection.localUtils()._channel); const { mockingProxy } = await this._connection.localUtils()._channel.newMockingProxy({ requestContext: requestContext._channel }); return (mockingProxy as any)._object; } diff --git a/packages/playwright/src/index.ts b/packages/playwright/src/index.ts index 5665eb8fea..cd3d249ad0 100644 --- a/packages/playwright/src/index.ts +++ b/packages/playwright/src/index.ts @@ -125,7 +125,7 @@ const playwrightFixtures: Fixtures = ({ }, { scope: 'worker', timeout: 0 }], _mockingProxy: [async ({ mockingProxy: mockingProxyOption, playwright }, use) => { - if (!mockingProxyOption) + if (mockingProxyOption !== 'inject-via-header') return await use(undefined); const mockingProxy = await (playwright as PlaywrightImpl)._startMockingProxy(); await use(mockingProxy); diff --git a/packages/playwright/types/test.d.ts b/packages/playwright/types/test.d.ts index 67df822010..391d9f56ab 100644 --- a/packages/playwright/types/test.d.ts +++ b/packages/playwright/types/test.d.ts @@ -6166,18 +6166,19 @@ export interface PlaywrightWorkerOptions { * * export default defineConfig({ * use: { - * mockingProxy: true + * mockingProxy: 'inject-via-header' * }, * }); * ``` * */ - mockingProxy: boolean | undefined; + mockingProxy: MockingProxyMode | undefined; } export type ScreenshotMode = 'off' | 'on' | 'only-on-failure' | 'on-first-failure'; export type TraceMode = 'off' | 'on' | 'retain-on-failure' | 'on-first-retry' | 'on-all-retries' | 'retain-on-first-failure'; export type VideoMode = 'off' | 'on' | 'retain-on-failure' | 'on-first-retry'; +export type MockingProxyMode = 'off' | 'inject-via-header'; /** * Playwright Test provides many options to configure test environment, diff --git a/utils/generate_types/overrides-test.d.ts b/utils/generate_types/overrides-test.d.ts index b9c144a132..10475b5649 100644 --- a/utils/generate_types/overrides-test.d.ts +++ b/utils/generate_types/overrides-test.d.ts @@ -236,12 +236,13 @@ export interface PlaywrightWorkerOptions { screenshot: ScreenshotMode | { mode: ScreenshotMode } & Pick; trace: TraceMode | /** deprecated */ 'retry-with-trace' | { mode: TraceMode, snapshots?: boolean, screenshots?: boolean, sources?: boolean, attachments?: boolean }; video: VideoMode | /** deprecated */ 'retry-with-video' | { mode: VideoMode, size?: ViewportSize }; - mockingProxy: boolean | undefined; + mockingProxy: MockingProxyMode | undefined; } export type ScreenshotMode = 'off' | 'on' | 'only-on-failure' | 'on-first-failure'; export type TraceMode = 'off' | 'on' | 'retain-on-failure' | 'on-first-retry' | 'on-all-retries' | 'retain-on-first-failure'; export type VideoMode = 'off' | 'on' | 'retain-on-failure' | 'on-first-retry'; +export type MockingProxyMode = 'off' | 'inject-via-header'; export interface PlaywrightTestOptions { acceptDownloads: boolean;