{"id":"3c3bf02a3a19edc9","repo":"vitest-dev/vitest","slug":"page-sessionid-not-found-in-this-browsernam","errorCode":null,"errorMessage":"Page \"${sessionId}\" not found in ${this.browserName} browser.","messagePattern":"Page \"(.+?)\" not found in (.+?) browser\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/browser-playwright/src/playwright.ts","lineNumber":570,"sourceCode":"    const contextOptions = this.options.contextOptions ?? {}\n    const options = {\n      ...contextOptions,\n      ignoreHTTPSErrors: true,\n    } satisfies BrowserContextOptions\n    // A `null` viewport lets the page adopt the real window size, which is only\n    // meaningful for a headed UI. In headless mode there is no real window, so it\n    // would inherit the host's device scale factor and produce screenshots that\n    // differ from non-UI runs on the same machine.\n    if (this.project.config.browser.ui && !this.project.config.browser.headless) {\n      options.viewport = null\n    }\n    return options\n  }\n\n  public getPage(sessionId: string): Page {\n    const page = this.pages.get(sessionId)\n    if (!page) {\n      throw new Error(`Page \"${sessionId}\" not found in ${this.browserName} browser.`)\n    }\n    return page\n  }\n\n  public getCommandsContext(sessionId: string): {\n    page: Page\n    context: BrowserContext\n    frame: () => Promise<Frame>\n    readonly iframe: FrameLocator\n  } {\n    const page = this.getPage(sessionId)\n    return {\n      page,\n      context: this.contexts.get(sessionId)!,\n      frame(): Promise<Frame> {\n        return new Promise<Frame>((resolve, reject) => {\n          const frame = page.frame('vitest-iframe')\n          if (frame) {","sourceCodeStart":552,"sourceCodeEnd":588,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/browser-playwright/src/playwright.ts#L552-L588","documentation":"Thrown by PlaywrightBrowserProvider.getPage(sessionId) when the given sessionId is not present in the provider's pages map. getPage is the single lookup used by getCommandsContext, getCDPSession, and tracing commands to resolve the active Playwright Page for a session.","triggerScenarios":"Calling getPage/getCommandsContext/getCDPSession with a sessionId that was never opened, was already closed (openBrowserPage deleted it), or belongs to a different provider instance. Also after the provider is closed and pages.clear() ran.","commonSituations":"Reusing a stale sessionId after a page close, cross-provider session id collisions, calling commands after teardown, or a race where the page is closed between open and command dispatch.","solutions":["Use the sessionId returned by openPage/closePage lifecycle; do not invent ids.","Ensure the page is still open before issuing commands (avoid teardown races).","Re-open the page via openPage if it was closed, rather than reusing the old id.","Confirm the provider instance is the same one that created the page."],"exampleFix":"// before\nconst page = provider.getPage('stale-or-guessed-id') // throws\n\n// after\nconst sessionId = await provider.openPage(/* id */, url, { parallel: false })\nconst page = provider.getPage(sessionId)","handlingStrategy":"validation","validationCode":"if (!provider.pages.has(sessionId)) {\n  throw new Error(`no page for session ${sessionId}; open it first via openPage`)\n}\nconst page = provider.getPage(sessionId)","typeGuard":"function hasPage(provider: PlaywrightBrowserProvider, id: string): boolean {\n  return provider.pages.has(id)\n}","tryCatchPattern":"try {\n  const page = provider.getPage(sessionId)\n} catch (err) {\n  if (err instanceof Error && /Page .* not found/.test(err.message)) {\n    // re-open or skip; do not reuse stale id\n  } else throw err\n}","preventionTips":["Use only sessionIds returned by the provider lifecycle.","Avoid reusing a sessionId after its page was closed.","Do not call getPage after provider close()/teardown."],"tags":["browser","playwright","session","lifecycle","vitest"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}