vitest-dev/vitest · error · Error
Session " " not found.
Error message
Session "${sessionId}" not found. What it means
ensureCDPHandler looks up a browser session by sessionId in vitest._browserSessions. Sessions are created when a browser test run starts and removed when it ends; a missing session means the ID is unknown, already cleaned up, or never created.
Solutions
- Refresh or re-establish the CDP connection so it uses the current run's sessionId.
- Ensure the CDP client does not cache session IDs across test runs.
- If you are driving CDP programmatically, fetch the live sessionId from the runner state before each call.
- Check for premature session teardown (e.g. browser closing before CDP work finishes) and serialize teardown after CDP cleanup.
Example fix
// before const handler = await parent.ensureCDPHandler(staleSessionId, rpcId) // after - re-read the live session id const live = vitest._browserSessions.getSession(currentSessionId)! const handler = await parent.ensureCDPHandler(live.id, rpcId)
Defensive patterns
Strategy: validation
Validate before calling
function sessionExists(getSession: (id: string) => unknown, id: string): boolean {
return !!getSession(id)
} Prevention
- Always read the live sessionId from runner state before issuing CDP requests.
- Do not cache sessionIds across test runs.
- Serialize teardown so it does not race with in-flight CDP traffic.
When it happens
Trigger: A CDP debugging client (or browser UI) sends a request referencing a sessionId that has no matching BrowserSession: stale ID after a run finished, typo/malformed ID, a session from a different Vitest process, or a race where the session was torn down before the CDP request arrived.
Common situations: Leaving the browser devtools UI open across a test re-run; reconnecting a CDP client with an old session ID after the server restarted; a flaky teardown that removes the session before in-flight CDP traffic lands.
Related errors
- Browser provider is not defined for the project
- Page " " not found in browser.
- Browser is not initialized
- Cannot spawn child server without a parent dev server.
- Cannot take a screenshot without a test path
AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11).
Data as JSON: /api/errors/36619e40dd8f91fd.
Report an issue: GitHub.
Appendix: source
Thrown at packages/browser/src/node/projectParent.ts:199
options: StackTraceParserOptions = {},
): ParsedStack[] {
return parseStacktrace(trace, {
...this.stackTraceOptions,
...options,
})
}
public readonly cdps: Map<string, BrowserServerCDPHandler> = new Map()
private cdpSessionsPromises = new Map<string, Promise<CDPSession>>()
async ensureCDPHandler(sessionId: string, rpcId: string): Promise<BrowserServerCDPHandler> {
const cachedHandler = this.cdps.get(rpcId)
if (cachedHandler) {
return cachedHandler
}
const browserSession = this.vitest._browserSessions.getSession(sessionId)
if (!browserSession) {
throw new Error(`Session "${sessionId}" not found.`)
}
const browser = browserSession.project.browser!
const provider = browser.provider
if (!provider) {
throw new Error(`Browser provider is not defined for the project "${browserSession.project.name}".`)
}
if (!provider.getCDPSession) {
throw new Error(`CDP is not supported by the provider "${provider.name}".`)
}
const session = await this.cdpSessionsPromises.get(rpcId) ?? await (async () => {
const promise = provider.getCDPSession!(sessionId).finally(() => {
this.cdpSessionsPromises.delete(rpcId)
})
this.cdpSessionsPromises.set(rpcId, promise)
return promise
})()View on GitHub (pinned to 1fa9837ec2)