{"record":{"id":"6be536a7c2e0669c","repo":"musistudio/claude-code-router","slug":"unable-to-resolve-browser-tab-for-automation-sessi","errorCode":null,"errorMessage":"Unable to resolve browser tab for automation session.","messagePattern":"Unable to resolve browser tab for automation session\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/electron/src/main/browser-automation-mcp.ts","lineNumber":1132,"sourceCode":"    let createdTab = false;\n\n    if (tabId && !state.tabs.some((tab) => tab.id === tabId)) {\n      throw new Error(`Browser tab was not found: ${tabId}`);\n    }\n\n    if (!tabId && url) {\n      const tab = builtInBrowserService.createAutomationTab();\n      tabId = tab.id;\n      createdTab = true;\n    } else if (!tabId) {\n      tabId = state.activeTabId || builtInBrowserService.createAutomationTab().id;\n      createdTab = !state.activeTabId;\n    } else if (state.activeTabId !== tabId) {\n      builtInBrowserService.selectAutomationTab(tabId);\n    }\n\n    if (!tabId) {\n      throw new Error(\"Unable to resolve browser tab for automation session.\");\n    }\n\n    const waitUntil = normalizeWaitUntil(readString(args.waitUntil), url ? \"interactive\" : \"none\");\n    const timeoutMs = clampInteger(readNumber(args.timeoutMs) ?? defaultWaitTimeoutMs, 100, 120000);\n    const webContents = builtInBrowserService.getAutomationWebContents(tabId);\n    const readiness = await waitForReadiness(\n      webContents,\n      waitUntil,\n      timeoutMs,\n      url ? () => builtInBrowserService.navigateAutomationTab(url, tabId) : undefined,\n      url\n    );\n    state = builtInBrowserService.getAutomationState();\n    const tab = requiredTabState(state, tabId);\n    const ref: BrowserSessionRef = {\n      sessionId: randomUUID(),\n      tabId,\n      ...(readString(args.userId) ? { userId: readString(args.userId) } : {})","sourceCodeStart":1114,"sourceCodeEnd":1150,"githubUrl":"https://github.com/musistudio/claude-code-router/blob/99f24806c6a2c660b16e53e95211c517448a6c90/packages/electron/src/main/browser-automation-mcp.ts#L1114-L1150","documentation":"Thrown after tab-resolution logic in the main automation tool run when tabId is still falsy — no explicit tabId was given, no url was supplied that would trigger tab creation, and there is no active tab to reuse. It guards the invariant that a run must be bound to a tab before touching webContents.","triggerScenarios":"Calling an automation tool with neither tabId nor url on a browser whose activeTabId is null (e.g. after closing all tabs), so no creation or fallback path applies.","commonSituations":"Calling a snapshot/screenshot-style tool with no arguments when the hidden automation browser has zero tabs; a script step that only passes a session ref whose tab vanished.","solutions":["Pass a url so a tab is created, or pass an explicit tabId.","Call browser_open first to establish an initial tab.","Keep at least one tab open in automation scripts, or re-attach after closing tabs."],"exampleFix":"// before\nawait call(\"browser_snapshot\", {}); // no tabId, no active tab\n\n// after\nawait call(\"browser_open\", { url: \"https://example.com\" });\nawait call(\"browser_snapshot\", {});","handlingStrategy":"fallback","validationCode":"const state = await call(\"browser_tab_list\", {});\nif (!state.tabs.length) await call(\"browser_open\", { url: \"https://example.com\" });\nawait call(\"browser_snapshot\", {});","typeGuard":null,"tryCatchPattern":"try { await call(toolName, args); } catch (e) { if (e instanceof Error && e.message.includes(\"Unable to resolve browser tab\")) { await call(\"browser_open\", { url }); await call(toolName, args); } else throw e; }","preventionTips":["Keep one live tab during a workflow","Pass url or tabId explicitly","Re-open the browser after mass tab closure"],"tags":["mcp","browser-automation","no-active-tab","session"],"backgroundTag":"no-active-browser-tab","analyzedSha":"99f24806c6a2c660b16e53e95211c517448a6c90","analyzedAt":"2026-08-27T04:11:01.184Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}