microsoft/playwright · error · Error

CDP session is only available in Chromium

Error message

CDP session is only available in Chromium

What it means

Thrown by BrowserDispatcher.newBrowserCDPSession() when the browser's browserType is not chromium. This is the browser-level (not page/frame) CDP session, used for browser-wide DevTools targets; like the context variant it is Chromium-only and rejected for firefox/webkit before any CDP work begins.

Source

Thrown at packages/playwright-core/src/server/dispatchers/browserDispatcher.ts:115

    if (this._options.ignoreStopAndKill)
      return;
    await this._object.close(progress, params);
  }

  async killForTests(params: channels.BrowserKillForTestsParams, progress: Progress): Promise<void> {
    if (this._options.ignoreStopAndKill)
      return;
    await this._object.killForTests(progress);
  }

  async defaultUserAgentForTest(): Promise<channels.BrowserDefaultUserAgentForTestResult> {
    return { userAgent: this._object.userAgent() };
  }

  async newBrowserCDPSession(params: channels.BrowserNewBrowserCDPSessionParams, progress: Progress): Promise<channels.BrowserNewBrowserCDPSessionResult> {
    // Note: progress is ignored because this operation is not cancellable and should not block in the browser anyway.
    if (this._object.options.browserType !== 'chromium')
      throw new Error(`CDP session is only available in Chromium`);
    const crBrowser = this._object as CRBrowser;
    return { session: new CDPSessionDispatcher(this, await progress.race(crBrowser.newBrowserCDPSession())) };
  }

  async startTracing(params: channels.BrowserStartTracingParams, progress: Progress): Promise<void> {
    // Note: progress is ignored because this operation is not cancellable and should not block in the browser anyway.
    if (this._object.options.browserType !== 'chromium')
      throw new Error(`Tracing is only available in Chromium`);
    const crBrowser = this._object as CRBrowser;
    await progress.race(crBrowser.startTracing(params.page ? (params.page as PageDispatcher)._object : undefined, params));
  }

  async stopTracing(params: channels.BrowserStopTracingParams, progress: Progress): Promise<channels.BrowserStopTracingResult> {
    // Note: progress is ignored because this operation is not cancellable and should not block in the browser anyway.
    if (this._object.options.browserType !== 'chromium')
      throw new Error(`Tracing is only available in Chromium`);
    const crBrowser = this._object as CRBrowser;
    return { artifact: ArtifactDispatcher.from(this, await progress.race(crBrowser.stopTracing())) };

View on GitHub (pinned to c8fc3bf8d3)

Solutions

  1. Gate the call on browserType name: if (browser.browserType().name() === 'chromium') { const cdp = await browser.newBrowserCDPSession(); }.
  2. Scope the test/project to chromium when it depends on browser-level CDP.
  3. Prefer context/page-level Playwright APIs that work cross-browser where they exist.

Example fix

// before: throws on firefox/webkit
const cdp = await browser.newBrowserCDPSession();

// after: chromium guard
if (browser.browserType().name() !== 'chromium')
  test.skip();
const cdp = await browser.newBrowserCDPSession();
Defensive patterns

Strategy: type-guard

Validate before calling

if (browser.browserType().name() !== 'chromium') {
  throw new Error('browser.newBrowserCDPSession() requires chromium');
}

Type guard

function isChromiumBrowser(b): b is Browser {
  return b.browserType().name() === 'chromium';
}

Prevention

When it happens

Trigger: Calling browser.newBrowserCDPSession() on a firefox or webkit browser object: e.g. const browser = await firefox.launch(); await browser.newBrowserCDPSession();. Cross-browser helpers that unconditionally open a browser-level CDP channel hit this on non-chromium projects.

Common situations: Tooling that uses browser-level CDP (e.g. to enumerate targets, browser-wide tracing/permissions) and is run against the firefox/webkit projects; tests assumed to be chromium-only that later got multi-browser config.

Related errors


AI-assisted analysis of microsoft/playwright@c8fc3bf8d3 (2026-08-12). Data as JSON: /api/errors/e60d7cb13ba747b2. Report an issue: GitHub.