vitest-dev/vitest · error · Error
Browser provider is not defined for the project
Error message
Browser provider is not defined for the project "${browserSession.project.name}". What it means
Inside ensureCDPHandler, after the session is found, the code reads browserSession.project.browser!.provider. If the project's browser instance exists but its provider has not been initialized (provider is undefined), CDP cannot be obtained. Unlike error 62 (which is about config), this is about the runtime provider instance being absent.
Solutions
- Ensure the target project is configured as a browser project (browser. instance set) and the provider initialized before issuing CDP requests.
- Await the browser provider initialization lifecycle (e.g. wait for the first page open) before calling CDP.
- Confirm the provider name is valid and the provider package is installed so initBrowserProvider succeeds.
Example fix
// before await parent.ensureCDPHandler(sessionId, rpcId) // provider not yet initialised // after await project.browser!.initBrowserProvider(project) await parent.ensureCDPHandler(sessionId, rpcId)
Defensive patterns
Strategy: validation
Validate before calling
function providerInitialized(browser?: { provider?: unknown }): boolean {
return !!browser?.provider
} Type guard
function hasProvider(browser: unknown): browser is { provider: { name: string; getCDPSession?: Function } } {
return !!browser && typeof browser === 'object' && !!(browser as any).provider
} Prevention
- Wait for the browser provider initialization lifecycle to complete before CDP calls.
- Confirm the target project is a browser project.
- Handle provider init failures loudly so silent undefined state is impossible.
When it happens
Trigger: Requesting a CDP session before initBrowserProvider has run for the project; a project whose browser failed to initialize its provider silently; referencing a project that is not actually a browser project.
Common situations: Calling CDP APIs very early in the lifecycle; a provider initialization failure that left provider undefined without throwing; mixing browser and non-browser projects and requesting CDP on the wrong one.
Related errors
- CDP is not supported by the provider
- Session " " not found.
- Browser is not initialized
- Browser provider is not defined for the project
- Cannot spawn child server without a parent dev server.
AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11).
Data as JSON: /api/errors/969e7c48b76b55aa.
Report an issue: GitHub.
Appendix: source
Thrown at packages/browser/src/node/projectParent.ts:205
}
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
})()
const rpc = (browser.state as BrowserServerState).testers.get(rpcId)
if (!rpc) {
throw new Error(`Tester RPC "${rpcId}" was not established.`)
}
View on GitHub (pinned to 1fa9837ec2)