{"record":{"id":"bb9fb943648020c7","repo":"microsoft/playwright","slug":"error-unable-to-connect-to-a-browser-that-does-no","errorCode":null,"errorMessage":"Error: unable to connect to a browser that does not have any contexts","messagePattern":"Error: unable to connect to a browser that does not have any contexts","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/playwright-core/src/tools/cli-daemon/program.ts","lineNumber":70,"sourceCode":"          await initWorkspace(options.initSkills, options.initSkillsGlobal);\n          return;\n        }\n\n        setupExitWatchdog();\n        const clientInfo = createClientInfo();\n        const mcpConfig = await configUtils.resolveCLIConfigForCLI(clientInfo.daemonProfilesDir, sessionName, options);\n        const mcpClientInfo = {\n          cwd: process.cwd(),\n          clientName: guessClientName(),\n        };\n\n        try {\n          const { browser, browserInfo, canBind, ownership } = await createBrowserWithInfo(mcpConfig, mcpClientInfo, options);\n          if (canBind)\n            await browser.bind(sessionName, { workspaceDir: clientInfo.workspaceDir });\n          const browserContext = mcpConfig.browser.isolated ? await browser.newContext(mcpConfig.browser.contextOptions) : browser.contexts()[0];\n          if (!browserContext)\n            throw new Error('Error: unable to connect to a browser that does not have any contexts');\n          const persistent = options.persistent || options.profile || mcpConfig.browser.userDataDir ? true : undefined;\n          const socketPath = await startCliDaemonServer(sessionName, browserContext, browserInfo, mcpConfig, clientInfo, mcpClientInfo, { persistent, exitOnClose: true, ownership });\n          console.log(`Daemon listening on ${socketPath}\\n`);\n        } catch (error) {\n          console.log(error);\n          gracefullyProcessExitDoNotHang(1);\n        }\n      });\n}\n\nfunction defaultConfigFile(): string {\n  return path.resolve('.playwright', 'cli.config.json');\n}\n\nfunction globalConfigFile(): string {\n  return path.join(process.env['PWTEST_CLI_GLOBAL_CONFIG'] ?? os.homedir(), '.playwright', 'cli.config.json');\n}\n","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-core/src/tools/cli-daemon/program.ts#L52-L88","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nplaywright-cli start --cd-endpoint ws://host:9222 --no-isolated\n// after\nplaywright-cli start --cdp-endpoint ws://host:9222 --isolated","handlingStrategy":"validation","validationCode":"// Decide isolated vs reuse based on whether the remote has contexts.\nconst browser = await connectToBrowser(url);\nconst hasContext = browser.contexts().length > 0;\nif (!hasContext && !options.isolated)\n  throw new Error('Remote browser has no contexts; pass --isolated or create one server-side.');","typeGuard":null,"tryCatchPattern":"try {\n  await startCli(session, opts);\n} catch (e) {\n  if (/does not have any contexts/.test((e as Error).message)) {\n    opts.isolated = true; // retry with isolated\n    await startCli(session, opts);\n  } else throw e;\n}","preventionTips":["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."],"tags":["cli","browser-context","remote","cdp","isolated-mode"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}