{"record":{"id":"d188166eeb58b392","repo":"stablyai/orca","slug":"browser-cdp-error","errorCode":"browser_cdp_error","errorMessage":"Could not attach debugger. DevTools may already be open for this tab.","messagePattern":"Could not attach debugger\\. DevTools may already be open for this tab\\.","errorType":"exception","errorClass":"BrowserError","httpStatus":null,"severity":"error","filePath":"src/main/browser/cdp-bridge.ts","lineNumber":1142,"sourceCode":"        // guest may already be destroyed\n      }\n    }\n  }\n\n  private async ensureDebuggerAttached(guest: Electron.WebContents): Promise<void> {\n    const tabId = this.resolveTabId(guest.id)\n    const state = this.getOrCreateTabState(tabId)\n    if (state.debuggerAttached && guest.debugger.isAttached()) {\n      return\n    }\n\n    try {\n      // Why: BrowserManager already attached the debugger; reuse it to avoid \"another debugger is already attached.\"\n      if (!guest.debugger.isAttached()) {\n        guest.debugger.attach('1.3')\n      }\n    } catch {\n      throw new BrowserError(\n        'browser_cdp_error',\n        'Could not attach debugger. DevTools may already be open for this tab.'\n      )\n    }\n\n    const sender = this.makeCdpSender(guest)\n    await sender('Page.enable')\n    await sender('DOM.enable')\n    await sender('Network.enable')\n\n    // Why: OOPIF iframes are invisible to the parent CDP session; flatten:true gives each a targetable sessionId.\n    await sender('Target.setAutoAttach', {\n      autoAttach: true,\n      waitForDebuggerOnStart: false,\n      flatten: true\n    })\n\n    // Why: CDP attach exposes automation signals (navigator.webdriver) that Cloudflare checks; override per new document.","sourceCodeStart":1124,"sourceCodeEnd":1160,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/src/main/browser/cdp-bridge.ts#L1124-L1160","documentation":"Same root cause as error 801 but in CdpBridge's ensureDebuggerAttached(). Electron permits only one debugger per WebContents. If BrowserManager hasn't pre-attached the debugger and the attach('1.3') call fails (DevTools open, or another consumer attached externally), this error is thrown with code browser_cdp_error. The bridge then sets up Page.enable, DOM.enable, Network.enable, Target.setAutoAttach, and anti-detection scripts, so a failed attach means none of that initialization happened.","triggerScenarios":"DevTools is open for the target tab; a prior CDP session didn't detach cleanly; the debugger was detached (e.g., by a detach event) and re-attach fails on the next command.","commonSituations":"Developer has DevTools open while running automation; concurrent screencast and automation sessions on the same tab; Electron version quirk causing attach flakiness.","solutions":["Close DevTools for that browser tab, then retry.","Stop other CDP consumers (screencast, WS proxy) on the same WebContents.","Retry the automation command — ensureDebuggerAttached is idempotent and will attempt re-attach."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (guest.debugger.isAttached()) {\n  // already attached by another consumer; command should proceed\n} else if (webContents.isDestroyed()) {\n  throw new Error('Cannot attach debugger: WebContents destroyed')\n}\nawait bridge.click(ref)","typeGuard":null,"tryCatchPattern":"try {\n  await bridge.click(ref)\n} catch (e) {\n  if (e instanceof BrowserError && e.code === 'browser_cdp_error' && /DevTools/.test(e.message)) {\n    // prompt user to close DevTools, then retry\n  }\n  throw e\n}","preventionTips":["Close DevTools for the target tab before running CDP automation.","Stop other CDP consumers (screencast, WS proxy) on the same WebContents before automating.","ensureDebuggerAttached is idempotent — retry the command after resolving the DevTools conflict."],"tags":["debugger","cdp","electron","devtools","attach"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}