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'`. Frame-switching is a WebDriver-specific operation; Playwright and the preview provider manage frames differently and don't expose this RPC.
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 d568f8ce37)
Solutions
- Switch the project's provider to `webdriverio` if you need WebDriver-style frame switching.
- Replace the call with the Playwright/preview equivalent (e.g. `page.frameLocator(...)` or `page.mainFrame()`).
- Gate the call behind a provider check (`server.provider === 'webdriverio'`).
Example fix
// before — under playwright provider
await switchToTestFrame()
// after — use provider-appropriate API
import { page } from 'vitest/browser'
await page.frameLocator('iframe').locator('#in').click() Defensive patterns
Strategy: validation
Validate before calling
function isWebdriverioProvider(provider: { name?: string }): boolean {
return provider?.name === 'webdriverio'
} Type guard
const isWebdriverioProvider = (p: { name?: string }): p is { name: 'webdriverio' } =>
p?.name === 'webdriverio' Prevention
- Use the WebDriverIO provider if you rely on WebDriver-style frame switching.
- Replace with Playwright frame APIs (frameLocator) when on Playwright.
- Guard helper code with `server.provider === 'webdriverio'`.
When it happens
Trigger: Calling `switchToTestFrame`/`switchToMainFrame` (via the `wdioSwitchContext` RPC) while running under Playwright or the preview provider.
Common situations: Migrating from WebDriverIO to Playwright without removing frame-switching calls; copy-pasted helpers from a WebDriverIO test suite into a Playwright project.
Related errors
- CDP is not supported by the provider "${provider.name}".
- Commands are only available for browser tests.
- bitLength is required
- Negative numbers are not supported
- The ${provider.name} provider does not support tracing.
AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03).
Data as JSON: /data/errors/9f8c1c017b454016.json.
Report an issue: GitHub.