vitest-dev/vitest · error · Error

Switch context is only available for WebDriverIO provider.

Error message

Switch context is only available for WebDriverIO provider.

What it means

After confirming a provider exists, wdioSwitchContext checks provider.name === 'webdriverio'. The switchToTestFrame/switchToMainFrame APIs only exist on the WebDriverIO provider, so calling wdioSwitchContext under playwright or preview is unsupported.

Solutions

  1. Use provider: 'webdriverio' if you need iframe/main-frame context switching.
  2. Remove or disable the wdioSwitchContext call when running playwright/preview.
  3. At the call site, branch on provider.name before invoking the switch.

Example fix

// before
browser: { provider: 'playwright' } // then call wdioSwitchContext
// after
browser: { provider: 'webdriverio' }
Defensive patterns

Strategy: type-guard

Validate before calling

function isWebdriverio(provider?: { name?: string }): boolean {
  return provider?.name === 'webdriverio'
}

Type guard

function isWebdriverioProvider(provider: unknown): provider is { name: 'webdriverio'; switchToTestFrame(): Promise<void>; switchToMainFrame(): Promise<void> } {
  return !!provider && (provider as any).name === 'webdriverio'
}

Prevention

When it happens

Trigger: Invoking the wdioSwitchContext RPC (the browser UI's frame toggle, or a manual call) while running tests with provider: 'playwright' or 'preview'. The iframe/main-frame switching is a WebDriverIO-specific feature.

Common situations: Switching providers from webdriverio to playwright and forgetting to update the UI/client that calls context switch; copy-pasting wdio helpers into a playwright run.

Related errors


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

Appendix: source

Thrown at packages/browser/src/node/rpc.ts:332

        cancelCurrentRun(reason) {
          vitest.cancelCurrentRun(reason)
        },
        async resolveId(id, importer) {
          return mockResolver.resolveId(id, importer)
        },
        debug(...args) {
          vitest.logger.console.debug(...args)
        },
        getCountOfFailedTests() {
          return vitest.state.getCountOfFailedTests()
        },
        async wdioSwitchContext(direction) {
          const provider = project.browser!.provider
          if (!provider) {
            throw new Error('Commands are only available for browser tests.')
          }
          if (provider.name !== 'webdriverio') {
            throw new Error('Switch context is only available for WebDriverIO provider.')
          }
          if (direction === 'iframe') {
            await (provider as any).switchToTestFrame()
          }
          else {
            await (provider as any).switchToMainFrame()
          }
        },
        async triggerCommand(sessionId, command, testPath, payload) {
          debug?.('[%s] Triggering command "%s"', sessionId, command)
          const provider = project.browser!.provider
          if (!provider) {
            throw new Error('Commands are only available for browser tests.')
          }
          const context = Object.assign(
            {
              testPath,
              project,

View on GitHub (pinned to 1fa9837ec2)