{"record":{"id":"84b7b63220895844","repo":"jackwener/OpenCLI","slug":"target-tab-required-pass-it-as-an-argument-or-t","errorCode":null,"errorMessage":"Target tab required. Pass it as an argument or --tab <targetId>.","messagePattern":"Target tab required\\. Pass it as an argument or --tab <targetId>\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli.ts","lineNumber":1215,"sourceCode":"    .description('Create a new tab and print its target ID')\n    .action(browserAction(async (page, url?: string) => {\n      if (!page.newTab) {\n        throw new Error('This browser session does not support creating tabs');\n      }\n      const createdPage = await page.newTab(url);\n      console.log(JSON.stringify({\n        page: createdPage,\n        url: url ?? null,\n      }, null, 2));\n    }));\n\n  addBrowserTabOption(browserTab.command('select')\n    .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, {","sourceCodeStart":1197,"sourceCodeEnd":1233,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/src/cli.ts#L1197-L1233","documentation":"`browser tab select` needs to know which tab to select: either a targetId positional argument or the --tab option. When resolveBrowserTabTarget finds neither (and no previously remembered default applies), the CLI throws this instructive error.","triggerScenarios":"Running `opencli browser <session> tab select` with no positional targetId and no --tab <targetId> flag.","commonSituations":"Omitting the argument in scripts; assuming the CLI auto-picks a tab; forgetting that `browser open` output's target ID must be passed along; stale remembered-tab state cleared between runs.","solutions":["Pass the target ID: opencli browser <session> tab select <targetId>","Or use the flag: opencli browser <session> tab select --tab <targetId>","Get valid target IDs from `browser open` output, `browser tab new`, or `browser tab list`","Check resolveBrowserTabTarget's precedence (positional vs --tab vs remembered state) if scripting"],"exampleFix":"// before\nopencli browser my-session tab select\n// after\nopencli browser my-session tab select --tab 1A2B3C4D5E6F","handlingStrategy":"validation","validationCode":"const targetId = positional ?? opts.tab;\nif (!targetId) throw new Error('tab select requires a targetId positional or --tab flag');","typeGuard":"function hasTabTarget(t: string | undefined, o?: { tab?: string }): t is string {\n  return Boolean(t ?? o?.tab);\n}","tryCatchPattern":"try {\n  await run(['opencli', 'browser', session, 'tab', 'select', targetId]);\n} catch (e) {\n  if (String((e as Error).message).startsWith('Target tab required')) {\n    console.error('Get a targetId from `browser open`, `browser tab new`, or `browser tab list`.');\n  }\n  throw e;\n}","preventionTips":["Capture the targetId printed by `browser open` / `browser tab new` into a variable and reuse it","Run `browser tab list` to discover IDs when unsure","Always pass --tab explicitly in non-interactive scripts","Don't rely on remembered default targets across separate CLI invocations"],"tags":["cli","missing-argument","browser"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}