vitest-dev/vitest · error · Error

CDP is not supported by the provider

Error message

CDP is not supported by the provider "${provider.name}".

What it means

ensureCDPHandler requires provider.getCDPSession to exist. Not every browser provider implements CDP: the preview provider and some WebDriverIO configurations do not expose getCDPSession, so requesting CDP through them is unsupported.

Solutions

  1. Switch to a provider that supports CDP (typically playwright) if you need CDP debugging.
  2. Avoid CDP-dependent APIs (browser command 'cdp', the devtools panel) when on the preview provider.
  3. If authoring a custom provider and CDP is required, implement getCDPSession(sessionId) on the provider class.

Example fix

// before
browser: { provider: 'preview' } // then call cdp APIs
// after
browser: { provider: 'playwright' }
Defensive patterns

Strategy: type-guard

Validate before calling

function providerSupportsCdp(provider?: { getCDPSession?: unknown }): boolean {
  return !!provider && typeof provider.getCDPSession === 'function'
}

Type guard

function isCdpCapable(provider: unknown): provider is { getCDPSession(sessionId: string): Promise<unknown> } {
  return !!provider && typeof (provider as any).getCDPSession === 'function'
}

Prevention

When it happens

Trigger: Calling CDP tooling (the browser UI's network inspector, custom CDP commands, the serverTester CDP path) while using provider: 'preview', or a webdriverio setup that does not wire CDP. The check `if (!provider.getCDPSession)` is what gates this.

Common situations: Defaulting to the preview provider and then trying to use CDP-based debugging; switching providers without realising the new one lacks CDP; using a third-party provider that does not implement the optional getCDPSession method.

Related errors


AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11). Data as JSON: /api/errors/31b59bd799c31650. Report an issue: GitHub.

Appendix: source

Thrown at packages/browser/src/node/projectParent.ts:208

  private cdpSessionsPromises = new Map<string, Promise<CDPSession>>()

  async ensureCDPHandler(sessionId: string, rpcId: string): Promise<BrowserServerCDPHandler> {
    const cachedHandler = this.cdps.get(rpcId)
    if (cachedHandler) {
      return cachedHandler
    }
    const browserSession = this.vitest._browserSessions.getSession(sessionId)
    if (!browserSession) {
      throw new Error(`Session "${sessionId}" not found.`)
    }

    const browser = browserSession.project.browser!
    const provider = browser.provider
    if (!provider) {
      throw new Error(`Browser provider is not defined for the project "${browserSession.project.name}".`)
    }
    if (!provider.getCDPSession) {
      throw new Error(`CDP is not supported by the provider "${provider.name}".`)
    }

    const session = await this.cdpSessionsPromises.get(rpcId) ?? await (async () => {
      const promise = provider.getCDPSession!(sessionId).finally(() => {
        this.cdpSessionsPromises.delete(rpcId)
      })
      this.cdpSessionsPromises.set(rpcId, promise)
      return promise
    })()

    const rpc = (browser.state as BrowserServerState).testers.get(rpcId)
    if (!rpc) {
      throw new Error(`Tester RPC "${rpcId}" was not established.`)
    }

    const handler = new BrowserServerCDPHandler(session, rpc)
    this.cdps.set(
      rpcId,

View on GitHub (pinned to 1fa9837ec2)