{"record":{"id":"9fd14a6e899dcbde","repo":"different-ai/openwork","slug":"unknown-browser-tab-tabid","errorCode":null,"errorMessage":"Unknown browser tab: ${tabId}","messagePattern":"Unknown browser tab: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/desktop/electron/browser-panel.mjs","lineNumber":621,"sourceCode":"\n  function attachActiveBrowserView() {\n    const mainWindow = window();\n    if (!mainWindow || !browserViewVisible) return;\n    const view = getActiveBrowserView();\n    if (!view) return;\n    for (const tab of browserTabs.values()) {\n      if (tab.view !== view) detachBrowserView(tab.view);\n    }\n    if (!mainWindow.contentView.children.includes(view)) {\n      mainWindow.contentView.addChildView(view);\n    }\n    if (lastBrowserBounds && lastBrowserBounds.width > 0 && lastBrowserBounds.height > 0) {\n      view.setBounds(scaleRendererBounds(lastBrowserBounds));\n    }\n  }\n\n  function selectBrowserTab(tabId) {\n    if (!browserTabs.has(tabId)) throw new Error(`Unknown browser tab: ${tabId}`);\n    hideMenuOverlay();\n    const previousView = getActiveBrowserView();\n    activeBrowserTabId = tabId;\n    if (previousView && previousView !== getActiveBrowserView()) {\n      detachBrowserView(previousView);\n    }\n    attachActiveBrowserView();\n    sendBrowserState();\n    return getBrowserTab(tabId);\n  }\n\n  function closeBrowserTab(tabId = activeBrowserTabId) {\n    const tab = getBrowserTab(tabId);\n    if (!tab) return null;\n    if (menuOverlayRequest?.tabId === tabId) hideMenuOverlay();\n    const closingIndex = browserTabOrder.indexOf(tabId);\n    const wasActive = activeBrowserTabId === tabId;\n    detachBrowserView(tab.view);","sourceCodeStart":603,"sourceCodeEnd":639,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/apps/desktop/electron/browser-panel.mjs#L603-L639","documentation":"selectBrowserTab looks up the requested id in the browserTabs map and throws when it is absent. The caller referenced a tab that does not exist in the built-in browser panel's current session.","triggerScenarios":"Calling the select-tab IPC/API with a stale or fabricated tabId: the tab was already closed, IDs from a previous app session are reused, an off-by-one/typo'd ID, or the panel was reloaded resetting tab state.","commonSituations":"UI keeping a reference to a closed tab and letting the user click it; scripts replaying old tab IDs; a tab closed asynchronously while automation still targets it; string vs number id mismatch if the caller doesn't match the map's key type.","solutions":["Refresh the tab list (listBrowserTabs/browser state) and use a current tabId","Check the tab still exists before selecting it","Update stale UI references when tabs close (listen for tab-closed state updates)","Reopen the tab or start a new tab if the old one is genuinely gone"],"exampleFix":"// before\nselectBrowserTab(oldTabId);\n// after\nconst tabs = listBrowserTabs();\nif (tabs.some(t => String(t.tabId) === String(oldTabId))) selectBrowserTab(oldTabId);","handlingStrategy":"type-guard","validationCode":"function tabExists(tabId) {\n  return listBrowserTabs().some(t => String(t.tabId) === String(tabId));\n}\nif (!tabExists(tabId)) return; // skip selection","typeGuard":"function isOpenTab(tabId, tabs) { return tabs.some(t => String(t.tabId) === String(tabId)); }","tryCatchPattern":"try {\n  selectBrowserTab(tabId);\n} catch (e) {\n  if (e.message.startsWith('Unknown browser tab:')) {\n    // refresh tab state, select the first open tab instead\n    const tabs = listBrowserTabs();\n    if (tabs.length) selectBrowserTab(tabs[0].tabId);\n  } else throw e;\n}","preventionTips":["Re-fetch tab state before selecting rather than caching ids","Remove references to a tab the moment its close event fires","Normalize ids to the same type (string) used by the panel","Guard UI elements for closed tabs (disable/hide on tab-close events)"],"tags":["lookup-failure","stale-reference","browser-tabs"],"backgroundTag":"unknown-tab-id","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}