vitest-dev/vitest · warning · Error
Failed to extract browser runner state from the response
Error message
Failed to extract browser runner state from the response
What it means
After successfully fetching the browser runner HTML, the devUiScriptPlugin tries to extract the inline bootstrap script via the BROWSER_SCRIPT_RE regex (which looks for `window.__vitest_browser_runner__` and `window.VITEST_API_TOKEN`). If the regex does not match, this error fires. Like error 162, this is internal to Vitest contributor workflows, not user-facing.
Source
Thrown at packages/ui/vite.config.ts:89
const BROWSER_SCRIPT_RE = /<script type="module">([\s\S]*?window\.__vitest_browser_runner__\s*=\s*\{[\s\S]*?window\.VITEST_API_TOKEN\s*=[\s\S]*?)<\/script>/
const browserUrl = `http://localhost:${process.env.BROWSER_DEV_PORT || '63315'}/__vitest_test__/`
return {
name: 'dev-ui-script',
apply(_config, env) {
return env.command === 'serve' && env.mode !== 'test'
},
async transformIndexHtml() {
if (process.env.BROWSER_DEV) {
const response = await fetch(browserUrl)
if (!response.ok) {
throw new Error(`Failed to fetch browser runner HTML from ${browserUrl}`)
}
const browserHtml = await response.text()
const browserScript = browserHtml.match(BROWSER_SCRIPT_RE)?.[1]
if (!browserScript) {
throw new Error('Failed to extract browser runner state from the response')
}
return [
{
tag: 'script',
attrs: { type: 'module' },
children: browserScript,
injectTo: 'head-prepend',
},
]
}
const token = resolveApiToken(process.cwd()).token
return [
{
tag: 'script',
children: `window.VITEST_API_TOKEN = ${JSON.stringify(token)}`,
injectTo: 'head-prepend',
},View on GitHub (pinned to 1fa9837ec2)
Solutions
- Update BROWSER_SCRIPT_RE in packages/ui/vite.config.ts to match the current browser runner HTML output.
- Ensure the UI package and browser runner are on the same git checkout / version.
- Manually inspect the fetched HTML at the browser URL to see the actual script tag format.
Defensive patterns
Strategy: validation
Prevention
- Keep BROWSER_SCRIPT_RE in sync with the browser runner HTML format when refactoring either side.
- Run UI and browser runner from the same checkout to avoid version skew.
When it happens
Trigger: The browser runner server responded but its HTML structure changed (e.g. the script tag or the global variable names were refactored), so BROWSER_SCRIPT_RE no longer matches. Version skew between the UI package and the browser runner can cause this.
Common situations: Contributor updated the browser runner HTML format but not BROWSER_SCRIPT_RE; running an older UI dev server against a newer browser runner or vice versa.
Related errors
- Failed to fetch browser runner HTML from ${browserUrl}
- stopChunkTrace cannot be called outside of the test file.
- This command can only be called inside a test file.
- provider ${context.provider.name} is not supported
- Browser is not initialized
AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11).
Data as JSON: /api/errors/939d8c53ac5b8c45.
Report an issue: GitHub.