apify/crawlee · error · Error

Function `newBrowserCDPSession()` is not available in incogn

Error message

Function `newBrowserCDPSession()` is not available in incognito mode

What it means

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.

Source

Thrown at packages/browser-pool/src/playwright/playwright-browser.ts:70

    /** @internal */
    setBrowserType(browserType: BrowserType): void {
        this.#browserType = browserType;
    }

    browserType(): BrowserType {
        return this.#browserType!;
    }

    async newPage(...args: Parameters<BrowserContext['newPage']>): ReturnType<BrowserContext['newPage']> {
        return this.#browserContext.newPage(...args);
    }

    async newContext(): Promise<never> {
        throw new Error('Function `newContext()` is not available in incognito mode');
    }

    async newBrowserCDPSession(): Promise<never> {
        throw new Error('Function `newBrowserCDPSession()` is not available in incognito mode');
    }

    async startTracing(): Promise<never> {
        throw new Error('Function `startTracing()` is not available in incognito mode');
    }

    async stopTracing(): Promise<never> {
        throw new Error('Function `stopTracing()` is not available in incognito mode');
    }
}

View on GitHub (pinned to dbe57fb09c)

Solutions

  1. Create a page-level CDP session instead: page.context().newCDPSession(page) via the underlying Playwright page.
  2. Switch to useIncognitoPages: false if a browser-level CDP session is strictly required.
  3. Guard the call: only invoke newBrowserCDPSession() when not in incognito mode.

Example fix

// before
const cdp = await browserController.newBrowserCDPSession();
// after
const client = await page.context().newCDPSession(page); // page-level CDP session
Defensive patterns

Strategy: fallback

Validate before calling

if (!launchContext.useIncognitoPages) {
  const cdp = await browserController.newBrowserCDPSession();
}

Type guard

function canUseBrowserCDP(useIncognitoPages: boolean): boolean {
  return !useIncognitoPages;
}

Try / catch

try {
  return await browserController.newBrowserCDPSession();
} catch (err) {
  if (err instanceof Error && err.message.includes('newBrowserCDPSession')) {
    return page.context().newCDPSession(page); // page-level fallback
  } throw err;
}

Prevention

When it happens

Trigger: Calling browserController.newBrowserCDPSession() while PlaywrightPlugin was configured with useIncognitoPages: true.

Common situations: 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.

Related errors


AI-assisted analysis of apify/crawlee@dbe57fb09c (2026-08-30). Data as JSON: /api/errors/abf7321274ba4e06. Report an issue: GitHub.