{"record":{"id":"2042837083225912","repo":"musistudio/claude-code-router","slug":"failed-to-handle-browser-dialog-formaterror-err","errorCode":null,"errorMessage":"Failed to handle browser dialog: ${formatError(error)}","messagePattern":"Failed to handle browser dialog: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/electron/src/main/browser-automation-mcp.ts","lineNumber":2310,"sourceCode":"    await withTimeout(webContents.debugger.sendCommand(\"Page.enable\"), defaultJavascriptTimeoutMs, \"Timed out enabling browser dialog handling.\");\n    await withTimeout(\n      webContents.debugger.sendCommand(\"Page.handleJavaScriptDialog\", {\n        accept,\n        ...(promptText !== undefined ? { promptText } : {})\n      }),\n      defaultJavascriptTimeoutMs,\n      \"Timed out handling browser dialog.\"\n    );\n    return {\n      accepted: accept,\n      ok: true,\n      promptText,\n      session,\n      title: await webContents.getTitle(),\n      url: webContents.getURL()\n    };\n  } catch (error) {\n    throw new Error(`Failed to handle browser dialog: ${formatError(error)}`);\n  } finally {\n    if (attachedHere && webContents.debugger.isAttached()) {\n      try {\n        webContents.debugger.detach();\n      } catch {\n        // Ignore detach errors after the dialog is resolved.\n      }\n    }\n  }\n}\n\nasync function executeJavaScriptWithTimeout<T = unknown>(\n  webContents: WebContents,\n  script: string,\n  timeoutMs: number,\n  label: string\n): Promise<T> {\n  if (webContents.isDestroyed()) {","sourceCodeStart":2292,"sourceCodeEnd":2328,"githubUrl":"https://github.com/musistudio/claude-code-router/blob/99f24806c6a2c660b16e53e95211c517448a6c90/packages/electron/src/main/browser-automation-mcp.ts#L2292-L2328","documentation":"A wrapper error thrown when handling a browser dialog (alert/confirm/prompt) via the Electron debugger protocol fails for any underlying reason — the inner error is captured and re-formatted into the message. Root causes include the debugger failing to attach, the dialog already being dismissed, or an unexpected CDP response.","triggerScenarios":"Calling a browser dialog tool while the debugger cannot attach to the webContents (already attached elsewhere), when the dialog no longer exists by the time the handler acts, or when the CDP command errors/times out.","commonSituations":"Race between dialog appearance and the handle call; another debugger client (DevTools) is attached; page dismissed the dialog programmatically; concurrent dialog-handling calls on the same tab.","solutions":["Read the embedded inner error text — it identifies the actual CDP/debugger failure to fix.","Retry once: dialogs are inherently racy and a retry after re-detecting the dialog often succeeds.","Ensure no other debugger session (open DevTools, another tool call) holds the webContents.","Avoid firing multiple dialog-handling calls concurrently on the same tab."],"exampleFix":"// before\nawait call(\"browser_handle_dialog\", { accept: true, tabId }); // throws if dialog already gone\n\n// after\ntry {\n  await call(\"browser_handle_dialog\", { accept: true, tabId });\n} catch (e) {\n  if (String(e.message).includes(\"Failed to handle browser dialog\")) {\n    const state = await call(\"browser_snapshot\", { tabId }); // dialog already resolved; continue\n  } else throw e;\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await call(\"browser_handle_dialog\", { accept: true, tabId }); } catch (e) { if (e instanceof Error && e.message.startsWith(\"Failed to handle browser dialog\")) { const snapshot = await call(\"browser_snapshot\", { tabId }); /* dialog likely already resolved; inspect and continue */ } else throw e; }","preventionTips":["Handle dialogs promptly when detected","Avoid concurrent dialog calls on one tab","Close DevTools/other debugger sessions before dialog automation","Read the inner formatted error to find the CDP root cause"],"tags":["mcp","browser-automation","dialog","debugger","cdp"],"backgroundTag":"browser-dialog-handling-failed","analyzedSha":"99f24806c6a2c660b16e53e95211c517448a6c90","analyzedAt":"2026-08-27T04:11:01.184Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}