{"record":{"id":"4f21b363f7cbe840","repo":"jackwener/OpenCLI","slug":"failed-to-create-tab-in-automation-container","errorCode":null,"errorMessage":"Failed to create tab in automation container","messagePattern":"Failed to create tab in automation container","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"extension/src/background.ts","lineNumber":1590,"sourceCode":"  // without a group signal must create a fresh tab rather than overwrite user\n  // content in a window where an OpenCLI group may have disappeared.\n  const tabs = await chrome.tabs.query({ windowId: scopedWindowId });\n  const reuseTab = existingSession?.owned ? undefined : tabs.find(t => t.id);\n  if (reuseTab?.id) {\n    await chrome.tabs.update(reuseTab.id, { url: BLANK_PAGE });\n    await new Promise(resolve => setTimeout(resolve, 300));\n    try {\n      const updated = await chrome.tabs.get(reuseTab.id);\n      if (isDebuggableUrl(updated.url)) return { tabId: reuseTab.id, tab: updated };\n      console.warn(`[opencli] data: URI was intercepted (${updated.url}), creating fresh tab`);\n    } catch {\n      // Tab was closed during navigation\n    }\n  }\n\n  // Fallback: create a new tab\n  const newTab = await chrome.tabs.create({ windowId: scopedWindowId, url: BLANK_PAGE, active: true });\n  if (!newTab.id) throw new Error('Failed to create tab in automation container');\n  await ensureOwnedContainerGroup(role, scopedWindowId, [newTab.id]);\n  return { tabId: newTab.id, tab: await chrome.tabs.get(newTab.id) };\n}\n\n/** Build a page-scoped success result with targetId resolved from tabId */\nasync function pageScopedResult(id: string, tabId: number, data?: unknown): Promise<Result> {\n  const page = await identity.resolveTargetId(tabId);\n  return { id, ok: true, data, page };\n}\n\n/** Convenience wrapper returning just the tabId (used by most handlers) */\nasync function resolveTabId(tabId: number | undefined, leaseKey: string, initialUrl?: string): Promise<number> {\n  const resolved = await resolveTab(tabId, leaseKey, initialUrl);\n  return resolved.tabId;\n}\n\nasync function listAutomationTabs(leaseKey: string): Promise<chrome.tabs.Tab[]> {\n  const session = automationSessions.get(leaseKey);","sourceCodeStart":1572,"sourceCodeEnd":1608,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/extension/src/background.ts#L1572-L1608","documentation":"As a last resort resolveTab creates a blank tab in the automation container window; if chrome.tabs.create returns a tab without an id (creation failed), the library throws a generic Error because it cannot group or track a tab without an id. This indicates the Chrome tabs API failed to create the tab.","triggerScenarios":"chrome.tabs.create({ windowId: scopedWindowId, url: BLANK_PAGE, active: true }) returns a Tab whose id is undefined/null — no valid tabId exists for ensureOwnedContainerGroup.","commonSituations":"Invalid or closed scopedWindowId, Chrome window destroyed mid-creation, extension lacking 'tabs' permission context changes, Chrome profile shutting down during automation.","solutions":["Retry the command; transient window teardown often resolves on a second attempt","Verify the automation container window still exists (opencli browser open to recreate it)","Re-create the automation container/window before running tab commands","Check Chrome extension error console for tabs API permission or lifecycle errors"],"exampleFix":"// before\nconst newTab = await chrome.tabs.create({ windowId: staleWindowId, ... });\nif (!newTab.id) throw new Error('Failed to create tab in automation container');\n// after\nconst win = await chrome.windows.get(scopedWindowId);   // validate window first\nconst newTab = await chrome.tabs.create({ windowId: win.id, ... });","handlingStrategy":"retry","validationCode":"try { await chrome.windows.get(scopedWindowId); } catch {\n  throw new Error('automation window gone; recreate container first');\n}","typeGuard":"async function windowIsValid(windowId: number): Promise<boolean> {\n  try { await chrome.windows.get(windowId); return true; } catch { return false; }\n}","tryCatchPattern":"try {\n  await cmd();\n} catch (e) {\n  if ((e as Error).message.includes('Failed to create tab')) {\n    await recreateContainerWindow();\n    return retry(cmd, { attempts: 2 });\n  }\n  throw e;\n}","preventionTips":["Verify the automation window exists before tab-heavy commands","Recreate the container window after Chrome updates/restarts","Retry once on transient tabs.create failures","Check the extension service-worker console for tabs API errors"],"tags":["chrome-extension","tab-creation","tabs-api"],"backgroundTag":"tab-creation-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}