{"record":{"id":"5ede63d73337d160","repo":"musistudio/claude-code-router","slug":"browser-automation-session-tab-was-not-found-re","errorCode":null,"errorMessage":"Browser automation session tab was not found: ${ref.tabId}","messagePattern":"Browser automation session tab was not found: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/electron/src/main/browser-automation-mcp.ts","lineNumber":1232,"sourceCode":"    }\n    return session;\n  }\n\n  private resolveOptionalSession(args: Record<string, unknown>): AttachedSession | undefined {\n    const ref = readSessionRef(args.session);\n    if (!ref) {\n      return undefined;\n    }\n    const existing = this.sessions.get(ref.sessionId);\n    if (existing) {\n      if (existing.ref.tabId !== ref.tabId) {\n        throw new Error(\"Browser automation session tabId does not match the attached session.\");\n      }\n      return existing;\n    }\n    const state = builtInBrowserService.getAutomationState();\n    if (!state.tabs.some((tab) => tab.id === ref.tabId)) {\n      throw new Error(`Browser automation session tab was not found: ${ref.tabId}`);\n    }\n    const restored: AttachedSession = {\n      attachedAt: Date.now(),\n      leaseId: randomUUID(),\n      observeOnly: false,\n      ref\n    };\n    this.sessions.set(ref.sessionId, restored);\n    return restored;\n  }\n\n  private assertCanMutate(session?: AttachedSession): void {\n    if (session?.observeOnly) {\n      throw new Error(\"This browser automation session is observeOnly and cannot mutate browser state.\");\n    }\n  }\n\n  private removeSessionsForTab(tabId: string): void {","sourceCodeStart":1214,"sourceCodeEnd":1250,"githubUrl":"https://github.com/musistudio/claude-code-router/blob/99f24806c6a2c660b16e53e95211c517448a6c90/packages/electron/src/main/browser-automation-mcp.ts#L1214-L1250","documentation":"Thrown when restoring an unknown session (not in the in-memory sessions map) whose referenced tabId no longer exists in the browser automation state. Session restore requires the target tab to still be live; a dead tab means the session cannot be rehydrated.","triggerScenarios":"Passing a session ref whose tab was closed (closing a tab removes its sessions, so the ref is treated as new), or after the automation browser reopened with fresh tabs while the caller kept an old ref.","commonSituations":"Long-running scripts that pause and resume; app/browser restart invalidating tab ids; closing a tab mid-workflow and reusing the prior session object in the next call.","solutions":["Re-attach to a live tab and use the newly returned session object.","Avoid closing a tab while you still intend to use its session.","Treat this as a signal to re-discover state (browser_tab_list) rather than retrying the same ref."],"exampleFix":"// before\nawait call(\"browser_tab_close\", { tabId });\nawait call(\"browser_tool\", { session: oldSession });\n\n// after\nawait call(\"browser_tab_close\", { tabId });\nconst { session } = await call(\"browser_attach\", { tabId: newTabId });\nawait call(\"browser_tool\", { session });","handlingStrategy":"fallback","validationCode":"const { tabs } = await call(\"browser_tab_list\", {});\nif (!tabs.some((t) => t.id === session.ref.tabId)) { const { session: s } = await call(\"browser_attach\", { tabId: tabs[0].id }); session = s; }\nawait call(tool, { session });","typeGuard":null,"tryCatchPattern":"try { await call(tool, { session }); } catch (e) { if (e instanceof Error && e.message.includes(\"session tab was not found\")) { const { session: s } = await call(\"browser_attach\", { tabId }); await call(tool, { session: s }); } else throw e; }","preventionTips":["Re-attach after restarts or tab closures","Don't close tabs you still need sessions on","Refresh refs before resuming paused scripts"],"tags":["mcp","browser-automation","session","tab-not-found"],"backgroundTag":"session-tab-not-found","analyzedSha":"99f24806c6a2c660b16e53e95211c517448a6c90","analyzedAt":"2026-08-27T04:11:01.184Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}