microsoft/playwright · error · Error
Creating new API request contexts is not allowed.
Error message
Creating new API request contexts is not allowed.
What it means
When Playwright runs as a server in a restricted (denyLaunch) mode — typical for sandboxed MCP servers and `playwright run-server` with launch disabled — creating a standalone GlobalAPIRequestContext is forbidden. The PlaywrightDispatcher.newRequest method checks the _denyLaunch flag and rejects the call to prevent unbounded outbound HTTP from a locked-down server.
Source
Thrown at packages/playwright-core/src/server/dispatchers/playwrightDispatcher.ts:89
browserDispatcher = new BrowserDispatcher(browserTypeDispatcher, options.preLaunchedBrowser, {
ignoreStopAndKill: true,
isolateContexts: !options.sharedBrowser,
});
initializer.preLaunchedBrowser = browserDispatcher;
}
if (options.preLaunchedAndroidDevice)
initializer.preConnectedAndroidDevice = new AndroidDeviceDispatcher(android, options.preLaunchedAndroidDevice);
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) };
}
async cleanup() {
// Cleanup contexts upon disconnect.
await this._browserDispatcher?.cleanupContexts();
}
}
class SocksSupportDispatcher extends Dispatcher<SdkObject, channels.SocksSupportChannel, RootDispatcher> implements channels.SocksSupportChannel {
_type_SocksSupport: boolean;
private _socksProxy: SocksProxy;
private _socksListeners: RegisteredListener[];
constructor(scope: RootDispatcher, parent: SdkObject, socksProxy: SocksProxy) {
super(scope, new SdkObject(parent, 'socksSupport'), 'SocksSupport', {});
this._type_SocksSupport = true;View on GitHub (pinned to c8fc3bf8d3)
Solutions
- Issue API requests through a browser context instead: use context.request / page.request, which are permitted because they are scoped to an existing context.
- If you genuinely need global request contexts, launch the Playwright server WITHOUT the denyLaunch restriction.
- Use the local (non-server) Playwright entry point where newRequest is always allowed.
Example fix
// before — fails against a restricted server
const request = await playwright.request.newContext();
// after — scope the request to a browser context
const browser = await playwright.chromium.launch();
const context = await browser.newContext();
const response = await context.request.get('https://example.com/api'); Defensive patterns
Strategy: fallback
Validate before calling
// Prefer a browser-context-scoped request when connected to a restricted server.
const context = await browser.newContext();
const response = await context.request.get('https://example.com/api');
// context.request is allowed even when global playwright.request is denied. Prevention
- Use context.request / page.request instead of playwright.request against restricted servers.
- If you need global request contexts, launch the server without denyLaunch.
- Document which server modes permit newRequest.
When it happens
Trigger: Connecting to a Playwright server launched with denyLaunch and calling playwright.request.newContext() (or the newRequest channel) to make standalone HTTP requests not bound to any browser context.
Common situations: Using the Playwright MCP server configured in a restricted/remote mode where the user only wants browser-driven requests; assuming request.newContext() works identically against a remote server as it does locally.
Related errors
- ${this._closeReason}
- Unknown permission: ${permission}
- ${response.status} ${response.statusText}${responseText}
- Request context disposed.
- Method not implemented.
AI-assisted analysis of microsoft/playwright@c8fc3bf8d3 (2026-08-12).
Data as JSON: /api/errors/73343640a8593f5b.
Report an issue: GitHub.