{"record":{"id":"939d8c53ac5b8c45","repo":"vitest-dev/vitest","slug":"failed-to-extract-browser-runner-state-from-the-re","errorCode":null,"errorMessage":"Failed to extract browser runner state from the response","messagePattern":"Failed to extract browser runner state from the response","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/ui/vite.config.ts","lineNumber":89,"sourceCode":"  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>/\n\n  const browserUrl = `http://localhost:${process.env.BROWSER_DEV_PORT || '63315'}/__vitest_test__/`\n\n  return {\n    name: 'dev-ui-script',\n    apply(_config, env) {\n      return env.command === 'serve' && env.mode !== 'test'\n    },\n    async transformIndexHtml() {\n      if (process.env.BROWSER_DEV) {\n        const response = await fetch(browserUrl)\n        if (!response.ok) {\n          throw new Error(`Failed to fetch browser runner HTML from ${browserUrl}`)\n        }\n        const browserHtml = await response.text()\n        const browserScript = browserHtml.match(BROWSER_SCRIPT_RE)?.[1]\n        if (!browserScript) {\n          throw new Error('Failed to extract browser runner state from the response')\n        }\n        return [\n          {\n            tag: 'script',\n            attrs: { type: 'module' },\n            children: browserScript,\n            injectTo: 'head-prepend',\n          },\n        ]\n      }\n\n      const token = resolveApiToken(process.cwd()).token\n      return [\n        {\n          tag: 'script',\n          children: `window.VITEST_API_TOKEN = ${JSON.stringify(token)}`,\n          injectTo: 'head-prepend',\n        },","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/ui/vite.config.ts#L71-L107","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["internal","dev-server","browser","regex"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}