microsoft/playwright · critical · Error
Error: unable to connect to a browser that does not have any
Error message
Error: unable to connect to a browser that does not have any contexts
What it means
Thrown when `--isolated` is not set and the resolved browser has zero contexts (`browser.contexts()[0]` is undefined). In non-isolated mode the CLI expects to reuse an existing context (e.g. a persistent profile or an attached/CDP server); a context-less browser cannot be driven, so startup aborts.
Source
Thrown at packages/playwright-core/src/tools/cli-daemon/program.ts:70
await initWorkspace(options.initSkills, options.initSkillsGlobal);
return;
}
setupExitWatchdog();
const clientInfo = createClientInfo();
const mcpConfig = await configUtils.resolveCLIConfigForCLI(clientInfo.daemonProfilesDir, sessionName, options);
const mcpClientInfo = {
cwd: process.cwd(),
clientName: guessClientName(),
};
try {
const { browser, browserInfo, canBind, ownership } = await createBrowserWithInfo(mcpConfig, mcpClientInfo, options);
if (canBind)
await browser.bind(sessionName, { workspaceDir: clientInfo.workspaceDir });
const browserContext = mcpConfig.browser.isolated ? await browser.newContext(mcpConfig.browser.contextOptions) : browser.contexts()[0];
if (!browserContext)
throw new Error('Error: unable to connect to a browser that does not have any contexts');
const persistent = options.persistent || options.profile || mcpConfig.browser.userDataDir ? true : undefined;
const socketPath = await startCliDaemonServer(sessionName, browserContext, browserInfo, mcpConfig, clientInfo, mcpClientInfo, { persistent, exitOnClose: true, ownership });
console.log(`Daemon listening on ${socketPath}\n`);
} catch (error) {
console.log(error);
gracefullyProcessExitDoNotHang(1);
}
});
}
function defaultConfigFile(): string {
return path.resolve('.playwright', 'cli.config.json');
}
function globalConfigFile(): string {
return path.join(process.env['PWTEST_CLI_GLOBAL_CONFIG'] ?? os.homedir(), '.playwright', 'cli.config.json');
}
View on GitHub (pinned to c8fc3bf8d3)
Solutions
- Pass `--isolated` so the CLI creates its own context on the remote browser.
- Or ensure the target browser already has at least one context before connecting (create one on the server side).
- Verify the `--cdp`/`--endpoint` URL points to a live browser process, not a shut-down one.
Example fix
// before playwright-cli start --cd-endpoint ws://host:9222 --no-isolated // after playwright-cli start --cdp-endpoint ws://host:9222 --isolated
Defensive patterns
Strategy: validation
Validate before calling
// Decide isolated vs reuse based on whether the remote has contexts.
const browser = await connectToBrowser(url);
const hasContext = browser.contexts().length > 0;
if (!hasContext && !options.isolated)
throw new Error('Remote browser has no contexts; pass --isolated or create one server-side.'); Try / catch
try {
await startCli(session, opts);
} catch (e) {
if (/does not have any contexts/.test((e as Error).message)) {
opts.isolated = true; // retry with isolated
await startCli(session, opts);
} else throw e;
} Prevention
- Use --isolated when targeting a fresh launchServer/CDP endpoint.
- For shared profiles, confirm a context exists server-side before connecting.
- Treat a context-less remote as a hard error rather than assuming reuse.
When it happens
Trigger: Connecting via `--endpoint`/`--cdp` to a browser server that was started with `launchServer` (which exposes no contexts until one is created) while `isolated` resolves to false; or a persistent/attached path where context creation failed silently.
Common situations: Pointing `--cdp-endpoint` at a fresh `browserType.launchServer()` instance without `--isolated`; the MCP/CLI default `isolated=true` was overridden to false via config while using a remote endpoint that has no contexts; a stale CDP endpoint whose context was already closed.
Related errors
- page: expected Page or Frame
- Device emulation is not supported with cdpEndpoint.
- Invalid viewport size format: use "width,height", for exampl
- Invalid geolocation format, should be "lat,long". For exampl
- PDF creation is only working with Chromium
AI-assisted analysis of microsoft/playwright@c8fc3bf8d3 (2026-08-12).
Data as JSON: /api/errors/bb9fb943648020c7.
Report an issue: GitHub.