{"record":{"id":"d7320868dc9d13c1","repo":"jackwener/OpenCLI","slug":"this-browser-session-does-not-support-closing-tabs","errorCode":null,"errorMessage":"This browser session does not support closing tabs","messagePattern":"This browser session does not support closing tabs","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli.ts","lineNumber":1228,"sourceCode":"    .argument('[targetId]', 'Target tab/page identity returned by \"browser open\", \"browser tab new\", or \"browser tab list\"')\n    .description('Select a tab by target ID and make it the default browser tab'))\n    .action(browserAction(async (page, targetId?: string, opts?: { tab?: string } | Command) => {\n      const resolvedTarget = resolveBrowserTabTarget(targetId, opts);\n      if (!resolvedTarget) {\n        throw new Error('Target tab required. Pass it as an argument or --tab <targetId>.');\n      }\n      await page.selectTab(resolvedTarget);\n      saveBrowserTargetState(resolvedTarget, getPageScope(page));\n      console.log(JSON.stringify({ selected: resolvedTarget }, null, 2));\n    }));\n\n  addBrowserTabOption(browserTab.command('close')\n    .argument('[targetId]', 'Target tab/page identity returned by \"browser open\", \"browser tab new\", or \"browser tab list\"')\n    .description('Close a tab by target ID'))\n    .action(browserAction(async (page, targetId?: string, opts?: { tab?: string } | Command) => {\n      const resolvedTarget = resolveBrowserTabTarget(targetId, opts);\n      if (!page.closeTab) {\n        throw new Error('This browser session does not support closing tabs');\n      }\n      if (!resolvedTarget) {\n        throw new Error('Target tab required. Pass it as an argument or --tab <targetId>.');\n      }\n      const validatedTarget = await resolveBrowserTargetInSession(page, resolvedTarget, {\n        scope: getPageScope(page),\n        source: 'explicit',\n      });\n      if (!validatedTarget) {\n        throw new Error(`Target tab ${resolvedTarget} is not part of the current browser session.`);\n      }\n      await page.closeTab(validatedTarget);\n      const scope = getPageScope(page);\n      if (loadBrowserTargetState(scope)?.defaultPage === validatedTarget) {\n        saveBrowserTargetState(undefined, scope);\n      }\n      console.log(JSON.stringify({ closed: validatedTarget }, null, 2));\n    }));","sourceCodeStart":1210,"sourceCodeEnd":1246,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/src/cli.ts#L1210-L1246","documentation":"The `browser tab close` subcommand requires the page's optional closeTab capability; when the current session's page does not implement it, the CLI throws before attempting the close. Like 5266, this is a capability guard for sessions that cannot close tabs.","triggerScenarios":"Running `opencli browser <session> tab close [targetId]` against a session whose page lacks closeTab (page.closeTab is undefined).","commonSituations":"Attached/externally managed browser contexts where the CLI may not close pages; restricted remote sessions; older adapter versions without closeTab.","solutions":["Use a session type that owns the browser and supports closing tabs","Verify the browser context permits closing targets (some managed contexts forbid it)","Update the adapter/driver to implement closeTab","Close the tab manually in the browser if the session cannot"],"exampleFix":"// before\nopencli browser attached-session tab close 1A2B3C4D5E6F  // throws\n// after\nopencli browser launched-session tab close 1A2B3C4D5E6F","handlingStrategy":"try-catch","validationCode":"if (typeof (page as { closeTab?: unknown }).closeTab !== 'function') {\n  throw new Error('This session does not support closing tabs; use a launched browser session.');\n}","typeGuard":"function supportsCloseTab(page: IPage): page is IPage & { closeTab: (targetId: string) => Promise<void> } {\n  return typeof (page as { closeTab?: unknown }).closeTab === 'function';\n}","tryCatchPattern":"try {\n  await run(['opencli', 'browser', session, 'tab', 'close', targetId]);\n} catch (e) {\n  if (String((e as Error).message).includes('does not support closing tabs')) {\n    console.error(`Session '${session}' cannot close tabs; close them in the browser or use a launched session.`);\n    return;\n  }\n  throw e;\n}","preventionTips":["Verify closeTab support on the session kind before scripting cleanup steps","Use CLI-owned/launched sessions for full tab lifecycle control","Fall back to manual browser cleanup for attached/managed contexts","Keep adapters current so capability methods exist"],"tags":["browser","capability","unsupported-operation"],"backgroundTag":"unsupported-capability","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}