{"record":{"id":"0bbbc9901201d5cd","repo":"vitest-dev/vitest","slug":"browser-is-not-initialized","errorCode":null,"errorMessage":"Browser is not initialized","messagePattern":"Browser is not initialized","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/browser-preview/src/preview.ts","lineNumber":50,"sourceCode":"      throw new Error(\n        'You\\'ve enabled headless mode for \"preview\" provider but it doesn\\'t support it. Use \"playwright\" or \"webdriverio\" instead: https://vitest.dev/guide/browser/#configuration',\n      )\n    }\n  }\n\n  isOpen(): boolean {\n    return this.open\n  }\n\n  getCommandsContext() {\n    return {}\n  }\n\n  async openPage(_sessionId: string, url: string): Promise<void> {\n    this.open = true\n    this.project.vitest.logger.log(`Browser runner started at ${url}\\n`)\n    if (!this.project.browser) {\n      throw new Error('Browser is not initialized')\n    }\n    const options = this.project.browser.vite.config.server\n    const _open = options.open\n    options.open = url\n    this.project.browser.vite.openBrowser()\n    options.open = _open\n  }\n\n  async close(): Promise<void> {}\n}\n\ndeclare module 'vitest/browser' {\n  export interface UserEventClickOptions extends SelectorOptions {}\n  export interface UserEventHoverOptions extends SelectorOptions {}\n  export interface UserEventFillOptions extends SelectorOptions {}\n  export interface UserEventSelectOptions extends SelectorOptions {}\n  export interface UserEventClearOptions extends SelectorOptions {}\n  export interface UserEventDoubleClickOptions extends SelectorOptions {}","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/browser-preview/src/preview.ts#L32-L68","documentation":"PreviewBrowserProvider.openPage delegates to `this.project.browser.vite.openBrowser()` to launch the headed window. It first asserts `this.project.browser` is set — if the BrowserPlugin has not initialized the browser object yet, openPage throws. This indicates a lifecycle ordering problem: openPage was called before browser initialization completed.","triggerScenarios":"openPage invoked before the browser plugin's configureServer/initialization has run; custom orchestration that calls openPage directly; a race during vitest startup where the preview provider is asked to open before `project.browser` is assigned.","commonSituations":"Plugin load order issues; custom test runner integrating vitest incorrectly; partial initialization after a config error; preview provider used outside the standard vitest lifecycle.","solutions":["Do not call openPage manually; let vitest's browser plugin drive it after initialization.","Ensure the browser plugin is properly registered in the vite config for the project.","If extending vitest, await project initialization before invoking provider methods.","Check vitest version compatibility — this should be wired internally; if seen, file an issue."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// not user-callable in normal flows — if integrating vitest programmatically:\nif (!project.browser) {\n  throw new Error('Browser plugin must initialize before openPage is called')\n}","typeGuard":"function isBrowserReady(project: { browser?: unknown }): boolean {\n  return !!project.browser\n}","tryCatchPattern":null,"preventionTips":["Let vitest drive openPage after plugin initialization.","Do not call provider.openPage from test code.","Ensure the browser plugin is registered in vite config."],"tags":["browser","preview","lifecycle","initialization","internal"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}