{"record":{"id":"9f8c1c017b454016","repo":"vitest-dev/vitest","slug":"switch-context-is-only-available-for-webdriverio-p","errorCode":null,"errorMessage":"Switch context is only available for WebDriverIO provider.","messagePattern":"Switch context is only available for WebDriverIO provider\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/browser/src/node/rpc.ts","lineNumber":332,"sourceCode":"        cancelCurrentRun(reason) {\n          vitest.cancelCurrentRun(reason)\n        },\n        async resolveId(id, importer) {\n          return mockResolver.resolveId(id, importer)\n        },\n        debug(...args) {\n          vitest.logger.console.debug(...args)\n        },\n        getCountOfFailedTests() {\n          return vitest.state.getCountOfFailedTests()\n        },\n        async wdioSwitchContext(direction) {\n          const provider = project.browser!.provider\n          if (!provider) {\n            throw new Error('Commands are only available for browser tests.')\n          }\n          if (provider.name !== 'webdriverio') {\n            throw new Error('Switch context is only available for WebDriverIO provider.')\n          }\n          if (direction === 'iframe') {\n            await (provider as any).switchToTestFrame()\n          }\n          else {\n            await (provider as any).switchToMainFrame()\n          }\n        },\n        async triggerCommand(sessionId, command, testPath, payload) {\n          debug?.('[%s] Triggering command \"%s\"', sessionId, command)\n          const provider = project.browser!.provider\n          if (!provider) {\n            throw new Error('Commands are only available for browser tests.')\n          }\n          const context = Object.assign(\n            {\n              testPath,\n              project,","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/browser/src/node/rpc.ts#L314-L350","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use provider: 'webdriverio' if you need iframe/main-frame context switching.","Remove or disable the wdioSwitchContext call when running playwright/preview.","At the call site, branch on provider.name before invoking the switch."],"exampleFix":"// before\nbrowser: { provider: 'playwright' } // then call wdioSwitchContext\n// after\nbrowser: { provider: 'webdriverio' }","handlingStrategy":"type-guard","validationCode":"function isWebdriverio(provider?: { name?: string }): boolean {\n  return provider?.name === 'webdriverio'\n}","typeGuard":"function isWebdriverioProvider(provider: unknown): provider is { name: 'webdriverio'; switchToTestFrame(): Promise<void>; switchToMainFrame(): Promise<void> } {\n  return !!provider && (provider as any).name === 'webdriverio'\n}","tryCatchPattern":null,"preventionTips":["Branch context-switch logic on provider.name.","Only configure wdioSwitchContext tooling when provider is webdriverio.","Keep UI affordances for frame switching gated on the active provider."],"tags":["webdriverio","browser-provider","capability","context-switch","browser"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}