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 BrowserContextDispatcher.newCDPSession() unless the context's browser type is chromium. Chrome DevTools Protocol (CDP) is a Chromium-only feature; Firefox and WebKit have no equivalent exposed by Playwright, so requesting a CDP session against them is rejected up front. The browserType check uses this._object._browser.options.browserType.
Source
Thrown at packages/playwright-core/src/server/dispatchers/browserContextDispatcher.ts:378
}
async disableRecorder(params: channels.BrowserContextDisableRecorderParams, progress: Progress): Promise<void> {
const recorder = await progress.race(Recorder.existingForContext(this._context));
if (recorder)
await progress.race(recorder.setMode('none'));
}
async exposeConsoleApi(params: channels.BrowserContextExposeConsoleApiParams, progress: Progress): Promise<void> {
await this._context.exposeConsoleApi(progress);
}
async pause(params: channels.BrowserContextPauseParams, progress: Progress) {
// Debugger will take care of this.
}
async newCDPSession(params: channels.BrowserContextNewCDPSessionParams, progress: Progress): Promise<channels.BrowserContextNewCDPSessionResult> {
if (this._object._browser.options.browserType !== 'chromium')
throw new Error(`CDP session is only available in Chromium`);
if (!params.page && !params.frame || params.page && params.frame)
throw new Error(`CDP session must be initiated with either Page or Frame, not none or both`);
const crBrowserContext = this._object as CRBrowserContext;
return { session: new CDPSessionDispatcher(this, await progress.race(crBrowserContext.newCDPSession((params.page ? params.page as PageDispatcher : params.frame as FrameDispatcher)._object))) };
}
async clockFastForward(params: channels.BrowserContextClockFastForwardParams, progress: Progress): Promise<channels.BrowserContextClockFastForwardResult> {
await progress.race(this._context.clock.fastForward(params.ticksString ?? params.ticksNumber ?? 0));
}
async clockInstall(params: channels.BrowserContextClockInstallParams, progress: Progress): Promise<channels.BrowserContextClockInstallResult> {
await progress.race(this._context.clock.install(params.timeString ?? params.timeNumber ?? undefined));
}
async clockPauseAt(params: channels.BrowserContextClockPauseAtParams, progress: Progress): Promise<channels.BrowserContextClockPauseAtResult> {
await progress.race(this._context.clock.pauseAt(params.timeString ?? params.timeNumber ?? 0));
this._clockPaused = true;
}View on GitHub (pinned to c8fc3bf8d3)
Solutions
- Guard the CDP call with a browser-type check: const isChromium = context.browser().browserType().name() === 'chromium'; only call newCDPSession when true.
- In the Playwright test runner, scope CDP-using code to the chromium project (test.configure / test.use) or branch on browserName from the fixture.
- Replace the CDP dependency with a cross-browser Playwright API where one exists (e.g. context.tracing, route, addInitScript).
Example fix
// before: crashes on firefox/webkit const cdp = await context.newCDPSession(page); // after: chromium-only branch if (page.context().browser().browserType().name() !== 'chromium') test.skip(true, 'CDP only available in chromium'); const cdp = await context.newCDPSession(page);
Defensive patterns
Strategy: type-guard
Validate before calling
function isChromium(browserOrContext): boolean {
const bt = browserOrContext.browser?.()?.browserType?.() ?? browserOrContext.browserType?.();
return bt?.name?.() === 'chromium';
}
if (!isChromium(context)) throw new Error('newCDPSession requires chromium'); Type guard
function isChromiumContext(ctx): ctx is BrowserContext {
return ctx.browser()?.browserType().name() === 'chromium';
} Prevention
- Centralize CDP usage in a helper that early-returns or skips on non-chromium browsers.
- In the test runner, scope CDP-dependent tests to the chromium project.
- Prefer Playwright's cross-browser APIs (context.tracing, route, addInitScript) over raw CDP.
When it happens
Trigger: Calling browserContext.newCDPSession(pageOrFrame) (or the newCDPSession RPC) on a context launched under firefox or webkit: chromium.firefox.launch() / webkit.launch() followed by context.newCDPSession(). Also triggered by cross-browser test code that calls newCDPSession unconditionally without checking the project.
Common situations: Shared helpers that drop down to CDP for performance/tracing/emulation and run across all browser projects; tests migrated from a chromium-only suite to a multi-browser config; conditionals missing for the firefox/webkit projects.
Related errors
- CDP session must be initiated with either Page or Frame, not
- CDP session is only available in Chromium
- PDF creation is only working with Chromium
- CDP connections are only supported by Chromium
- Could not connect to ${channel}.\n${remoteDebuggingHint(chan
AI-assisted analysis of microsoft/playwright@c8fc3bf8d3 (2026-08-12).
Data as JSON: /api/errors/3c514db3ed6894c6.
Report an issue: GitHub.