Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(server): gate Playwright.newRequest behind denyLaunch (#40543)

Pavel Feldmanb80e42ec8d26
diff --git a/packages/playwright-core/src/server/dispatchers/playwrightDispatcher.ts b/packages/playwright-core/src/server/dispatchers/playwrightDispatcher.ts
index cc17b53934..f11677855f 100644
--- a/packages/playwright-core/src/server/dispatchers/playwrightDispatcher.ts
+++ b/packages/playwright-core/src/server/dispatchers/playwrightDispatcher.ts
@@ -46,6 +46,7 @@ export type PlaywrightDispatcherOptions = {
export class PlaywrightDispatcher extends Dispatcher<Playwright, channels.PlaywrightChannel, RootDispatcher> implements channels.PlaywrightChannel {
_type_Playwright;
private _browserDispatcher: BrowserDispatcher | undefined;
+ private _denyLaunch: boolean;
constructor(scope: RootDispatcher, playwright: Playwright, options: PlaywrightDispatcherOptions = {}) {
const denyLaunch = options.denyLaunch ?? false;
@@ -78,9 +79,12 @@ export class PlaywrightDispatcher extends Dispatcher<Playwright, channels.Playwr
super(scope, playwright, 'Playwright', initializer);
this._type_Playwright = true;
this._browserDispatcher = browserDispatcher;
+ this._denyLaunch = denyLaunch;
}
async newRequest(params: channels.PlaywrightNewRequestParams, progress: Progress): Promise<channels.PlaywrightNewRequestResult> {
+ if (this._denyLaunch)
+ throw new Error(`Creating new API request contexts is not allowed.`);
const request = new GlobalAPIRequestContext(this._object, params);
return { request: APIRequestContextDispatcher.from(this.parentScope(), request) };
}