{"record":{"id":"c0ec6d1febb34126","repo":"jackwener/OpenCLI","slug":"profile-required","errorCode":"profile-required","errorMessage":"Multiple Browser Bridge profiles are connected","messagePattern":"Multiple Browser Bridge profiles are connected","errorType":"exception","errorClass":"BrowserConnectError","httpStatus":null,"severity":"error","filePath":"src/browser/daemon-lifecycle.ts","lineNumber":143,"sourceCode":"    }\n\n    if (!portReleased) {\n      throw new BrowserConnectError(\n        'Stale daemon could not be replaced',\n        `A stale daemon (${reason}) is running but did not shut down (graceful + SIGKILL both failed).\\n` +\n        '  Run manually: opencli daemon stop',\n        'daemon-not-running',\n      );\n    }\n    staleDaemonReplaced = true;\n  }\n\n  if (!staleDaemonReplaced && health.state === 'ready') {\n    return health;\n  }\n\n  if (!staleDaemonReplaced && health.state === 'profile-required') {\n    throw browserConnectErrorFromHealth(health, contextId);\n  }\n\n  if (staleDaemonReplaced || health.state === 'stopped') {\n    if (verbose && (process.env.OPENCLI_VERBOSE || process.stderr.isTTY)) {\n      process.stderr.write('⏳ Starting daemon...\\n');\n    }\n    daemonLifecycleHooks.spawnDaemonProcess();\n  } else if (verbose && (process.env.OPENCLI_VERBOSE || process.stderr.isTTY)) {\n    process.stderr.write('⏳ Waiting for Chrome/Chromium extension to connect...\\n');\n    process.stderr.write('   Make sure Chrome or Chromium is open and the OpenCLI extension is enabled.\\n');\n  }\n\n  const finalHealth = await waitForBridgeReady(getDaemonHealth, { timeoutMs, contextId, preferredContextId });\n  if (finalHealth.state === 'ready') return finalHealth;\n  throw browserConnectErrorFromHealth(finalHealth, contextId);\n}\n\nfunction browserConnectErrorFromHealth(health: DaemonHealth, contextId?: string): BrowserConnectError {","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/src/browser/daemon-lifecycle.ts#L125-L161","documentation":"ensureBrowserBridgeReady found the daemon health in state 'profile-required', meaning multiple Browser Bridge profiles/contexts are connected and the caller must specify which one to use. The library throws BrowserConnectError with code profile-required because it cannot disambiguate the target context.","triggerScenarios":"Calling any Browser Bridge-backed command (via _ensureDaemon or health) when the daemon reports more than one connected profile and no contextId/preferredContextId was supplied; the code path browserConnectErrorFromHealth(health, contextId) converts the health state into this error.","commonSituations":"Multiple Chrome profiles (personal + work) running the OpenCLI extension, several browser windows across profiles connected simultaneously, or leftover daemon connections from a previous session.","solutions":["Pass an explicit context/profile ID to the command so the bridge knows which connected profile to target.","Close or disconnect the extra Chrome profiles/windows running the OpenCLI extension.","Restart the daemon so only one profile reconnects, then rerun the command.","Check daemon health output to list connected profiles and pick the correct contextId."],"exampleFix":"// before\nawait runCommand('browser', 'click', { selector: '#go' });\n// after: disambiguate the profile\nawait runCommand('browser', 'click', { selector: '#go', contextId: 'work-profile' });","handlingStrategy":"validation","validationCode":"const health = await bridge.health();\nif (health.state === 'profile-required') {\n  // supply a contextId before running commands\n}","typeGuard":"function isProfileRequired(health) {\n  return health.state === 'profile-required';\n}","tryCatchPattern":"try {\n  await runCommand('browser', action, args);\n} catch (e) {\n  if (e.code === 'profile-required') {\n    return runCommand('browser', action, { ...args, contextId: pickProfileId() });\n  }\n  throw e;\n}","preventionTips":["Always pass an explicit contextId when multiple Chrome profiles run the extension.","Run only one browser profile with the OpenCLI extension enabled.","Check daemon health before batch runs to detect multi-profile states early.","Disconnect stale daemon sessions from previous runs."],"tags":["browser-bridge","daemon","configuration"],"backgroundTag":"multiple-profiles-connected","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}