{"record":{"id":"42fa24f4a8794861","repo":"apify/crawlee","slug":"function-newcontext-is-not-available-in-incogn","errorCode":null,"errorMessage":"Function `newContext()` is not available in incognito mode","messagePattern":"Function `newContext\\(\\)` is not available in incognito mode","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/browser-pool/src/playwright/playwright-browser.ts","lineNumber":66,"sourceCode":"    version(): string {\n        return this.#version;\n    }\n\n    /** @internal */\n    setBrowserType(browserType: BrowserType): void {\n        this.#browserType = browserType;\n    }\n\n    browserType(): BrowserType {\n        return this.#browserType!;\n    }\n\n    async newPage(...args: Parameters<BrowserContext['newPage']>): ReturnType<BrowserContext['newPage']> {\n        return this.#browserContext.newPage(...args);\n    }\n\n    async newContext(): Promise<never> {\n        throw new Error('Function `newContext()` is not available in incognito mode');\n    }\n\n    async newBrowserCDPSession(): Promise<never> {\n        throw new Error('Function `newBrowserCDPSession()` is not available in incognito mode');\n    }\n\n    async startTracing(): Promise<never> {\n        throw new Error('Function `startTracing()` is not available in incognito mode');\n    }\n\n    async stopTracing(): Promise<never> {\n        throw new Error('Function `stopTracing()` is not available in incognito mode');\n    }\n}\n","sourceCodeStart":48,"sourceCodeEnd":81,"githubUrl":"https://github.com/apify/crawlee/blob/dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c/packages/browser-pool/src/playwright/playwright-browser.ts#L48-L81","documentation":"When a Playwright browser is opened in incognito mode, the wrapper represents the incognito BrowserContext itself, so there is no separate browser-level context to create. Calling newContext() on it is therefore unsupported and always throws. Use newPage() to create pages directly within the existing incognito context.","triggerScenarios":"Using PlaywrightPlugin with useIncognitoPages: true and then calling browserController.newContext() (on the wrapped incognito context) to make a nested browser context.","commonSituations":"Porting code from a non-incognito setup where newContext() worked; trying to isolate pages into separate contexts while also using incognito pages; framework code that generically calls newContext() for isolation.","solutions":["Call newPage() on the controller instead of newContext() — each page already gets the context options applied in incognito mode.","If you need real separate contexts, set useIncognitoPages: false and use the regular browser's newContext().","Restructure isolation needs around per-page context options (cookie/storage setup via contextOptions passed to newPage)."],"exampleFix":"// before\nconst context = await browserController.newContext();\nconst page = await context.newPage();\n// after\nconst page = await browserController.newPage(); // incognito context handles isolation","handlingStrategy":"validation","validationCode":"if (launchContext.useIncognitoPages && typeof browserController.newContext === 'function') {\n  // in incognito mode newContext() throws; use newPage() instead\n}","typeGuard":"function supportsNewContext(bc: unknown): bc is { newContext: () => Promise<unknown> } {\n  return typeof (bc as { newContext?: unknown }).newContext === 'function';\n}","tryCatchPattern":"try {\n  await browserController.newContext();\n} catch (err) {\n  if (err instanceof Error && err.message.includes('not available in incognito mode')) {\n    await browserController.newPage(); // fallback\n  } else throw err;\n}","preventionTips":["Remember: useIncognitoPages: true means each page IS the isolated context.","Branch isolation logic on the useIncognitoPages flag before calling context APIs.","Prefer newPage() with contextOptions for per-page isolation."],"tags":["browser-pool","playwright","incognito","unsupported-api"],"backgroundTag":"api-not-supported-in-mode","analyzedSha":"dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c","analyzedAt":"2026-08-30T22:22:28.328Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}