{"record":{"id":"73343640a8593f5b","repo":"microsoft/playwright","slug":"creating-new-api-request-contexts-is-not-allowed","errorCode":null,"errorMessage":"Creating new API request contexts is not allowed.","messagePattern":"Creating new API request contexts is not allowed\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/server/dispatchers/playwrightDispatcher.ts","lineNumber":89,"sourceCode":"      browserDispatcher = new BrowserDispatcher(browserTypeDispatcher, options.preLaunchedBrowser, {\n        ignoreStopAndKill: true,\n        isolateContexts: !options.sharedBrowser,\n      });\n      initializer.preLaunchedBrowser = browserDispatcher;\n    }\n\n    if (options.preLaunchedAndroidDevice)\n      initializer.preConnectedAndroidDevice = new AndroidDeviceDispatcher(android, options.preLaunchedAndroidDevice);\n\n    super(scope, playwright, 'Playwright', initializer);\n    this._type_Playwright = true;\n    this._browserDispatcher = browserDispatcher;\n    this._denyLaunch = denyLaunch;\n  }\n\n  async newRequest(params: channels.PlaywrightNewRequestParams, progress: Progress): Promise<channels.PlaywrightNewRequestResult> {\n    if (this._denyLaunch)\n      throw new Error(`Creating new API request contexts is not allowed.`);\n    const request = new GlobalAPIRequestContext(this._object, params);\n    return { request: APIRequestContextDispatcher.from(this.parentScope(), request) };\n  }\n\n  async cleanup() {\n    // Cleanup contexts upon disconnect.\n    await this._browserDispatcher?.cleanupContexts();\n  }\n}\n\nclass SocksSupportDispatcher extends Dispatcher<SdkObject, channels.SocksSupportChannel, RootDispatcher> implements channels.SocksSupportChannel {\n  _type_SocksSupport: boolean;\n  private _socksProxy: SocksProxy;\n  private _socksListeners: RegisteredListener[];\n\n  constructor(scope: RootDispatcher, parent: SdkObject, socksProxy: SocksProxy) {\n    super(scope, new SdkObject(parent, 'socksSupport'), 'SocksSupport', {});\n    this._type_SocksSupport = true;","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-core/src/server/dispatchers/playwrightDispatcher.ts#L71-L107","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before — fails against a restricted server\nconst request = await playwright.request.newContext();\n// after — scope the request to a browser context\nconst browser = await playwright.chromium.launch();\nconst context = await browser.newContext();\nconst response = await context.request.get('https://example.com/api');","handlingStrategy":"fallback","validationCode":"// Prefer a browser-context-scoped request when connected to a restricted server.\nconst context = await browser.newContext();\nconst response = await context.request.get('https://example.com/api');\n// context.request is allowed even when global playwright.request is denied.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["api-request","server-mode","permissions"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}