{"record":{"id":"abf7321274ba4e06","repo":"apify/crawlee","slug":"function-newbrowsercdpsession-is-not-available","errorCode":null,"errorMessage":"Function `newBrowserCDPSession()` is not available in incognito mode","messagePattern":"Function `newBrowserCDPSession\\(\\)` is not available in incognito mode","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/browser-pool/src/playwright/playwright-browser.ts","lineNumber":70,"sourceCode":"    /** @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":52,"sourceCodeEnd":81,"githubUrl":"https://github.com/apify/crawlee/blob/dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c/packages/browser-pool/src/playwright/playwright-browser.ts#L52-L81","documentation":"In incognito mode the Playwright wrapper holds an incognito BrowserContext, not a full Browser instance, so a browser-level CDP session cannot be created. newBrowserCDPSession() is intentionally disabled and always throws. Create a CDP session from the page instead if you need low-level protocol access.","triggerScenarios":"Calling browserController.newBrowserCDPSession() while PlaywrightPlugin was configured with useIncognitoPages: true.","commonSituations":"Needing raw Chrome DevTools Protocol access (network interception, performance metrics) in an incognito-pages setup; copying CDP code written for a full Puppeteer/Playwright browser handle.","solutions":["Create a page-level CDP session instead: page.context().newCDPSession(page) via the underlying Playwright page.","Switch to useIncognitoPages: false if a browser-level CDP session is strictly required.","Guard the call: only invoke newBrowserCDPSession() when not in incognito mode."],"exampleFix":"// before\nconst cdp = await browserController.newBrowserCDPSession();\n// after\nconst client = await page.context().newCDPSession(page); // page-level CDP session","handlingStrategy":"fallback","validationCode":"if (!launchContext.useIncognitoPages) {\n  const cdp = await browserController.newBrowserCDPSession();\n}","typeGuard":"function canUseBrowserCDP(useIncognitoPages: boolean): boolean {\n  return !useIncognitoPages;\n}","tryCatchPattern":"try {\n  return await browserController.newBrowserCDPSession();\n} catch (err) {\n  if (err instanceof Error && err.message.includes('newBrowserCDPSession')) {\n    return page.context().newCDPSession(page); // page-level fallback\n  } throw err;\n}","preventionTips":["Use page.context().newCDPSession(page) for CDP needs in incognito setups.","Gate browser-level CDP calls behind a useIncognitoPages check.","Document in team code that CDP is page-scoped when incognito pages are on."],"tags":["browser-pool","playwright","incognito","cdp"],"backgroundTag":"api-not-supported-in-mode","analyzedSha":"dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c","analyzedAt":"2026-08-30T22:22:28.328Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}