microsoft/playwright · critical · Error
Error: unable to connect to a browser that does not have…
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.
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
- Device emulation is not supported with cdpEndpoint.
- page: expected Page or Frame
- boolean option '-- ' should not be passed with '=value'…
- Browser context was closed before the daemon could start
- Browser is already in use for
AI-assisted analysis of microsoft/playwright@500c9c822c (2026-09-15).
Data as JSON: /api/errors/bb9fb943648020c7.
Report an issue: GitHub.
Appendix: source
Thrown at packages/playwright-core/src/tools/cli-daemon/program.ts:69
.action(async (sessionName: string, options: any) => {
if (options.initWorkspace) {
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, ownership, idleTimer } = await createBrowserWithInfo(mcpConfig, mcpClientInfo, options, { title: 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, idleTimer });
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 500c9c822c)