{"record":{"id":"0c6d16ea643f7a81","repo":"vercel-labs/agent-browser","slug":"the-switch-action-requires-a-target-tab-id-or-la","errorCode":null,"errorMessage":"The \"switch\" action requires a target tab id or label.","messagePattern":"The \"switch\" action requires a target tab id or label\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/@agent-browser/eve/extension/tools/tabs.ts","lineNumber":33,"sourceCode":"    target: z\n      .string()\n      .optional()\n      .describe('Tab id (\"t2\") or label. Required for \"switch\"; \"close\" defaults to the active tab.'),\n    url: z.string().optional().describe('URL to open when action is \"new\".'),\n  }),\n  async execute({ action, label, target, url }, ctx) {\n    switch (action) {\n      case \"list\":\n        return await runBrowser(ctx, [\"tab\"]);\n      case \"new\": {\n        const args = [\"tab\", \"new\"];\n        if (label !== undefined) args.push(\"--label\", label);\n        if (url !== undefined) args.push(url);\n        return await runBrowser(ctx, args);\n      }\n      case \"switch\":\n        if (target === undefined) {\n          throw new Error('The \"switch\" action requires a target tab id or label.');\n        }\n        return await runBrowser(ctx, [\"tab\", target]);\n      case \"close\":\n        return await runBrowser(ctx, target === undefined ? [\"tab\", \"close\"] : [\"tab\", \"close\", target]);\n    }\n  },\n});\n","sourceCodeStart":15,"sourceCodeEnd":41,"githubUrl":"https://github.com/vercel-labs/agent-browser/blob/548b159b30eef119ccf6846c8bc807d0eaa3f6f8/packages/@agent-browser/eve/extension/tools/tabs.ts#L15-L41","documentation":"The eve 'tabs' tool switch action maps to 'agent-browser tab <target>' where target is a tab id or label. Unlike 'new' and 'close', which have sensible defaults, switching has nothing to default to, so execute() throws when action is 'switch' and target is undefined.","triggerScenarios":"Calling tabs with { action: 'switch' } and no target; label stored in an undefined variable; confusing 'switch' with 'new' (which needs neither).","commonSituations":"Agents assuming switch-to-latest semantics; flows where the tab list was fetched earlier and the id was dropped.","solutions":["List tabs first (action: 'list') and pass a concrete id or label","Pass the label you created the tab with: tools.tabs({ action: 'switch', target: 'checkout' })","For creating-and-switching use action 'new' with a label instead"],"exampleFix":"// before\nawait tools.tabs({ action: \"switch\" });\n\n// after\nconst list = await tools.tabs({ action: \"list\" });\nawait tools.tabs({ action: \"switch\", target: list[0].id });","handlingStrategy":"validation","validationCode":"if (input.action === \"switch\" && input.target === undefined) {\n  const tabs = await tools.tabs({ action: \"list\" });\n  if (tabs.length === 1) return tabs[0]; // nothing to switch to\n  throw new Error(\"switch requires a tab id or label from the list\");\n}","typeGuard":"function canSwitchTab(i: { action: string; target?: string }): boolean {\n  return i.action !== \"switch\" || i.target !== undefined;\n}","tryCatchPattern":null,"preventionTips":["List tabs first and carry a concrete id/label into the switch call","Label tabs at creation ('tab new --label x') so switches are stable","Remember 'close' and 'new' work without target; only 'switch' requires it"],"tags":["eve","input-validation","tabs"],"backgroundTag":null,"analyzedSha":"548b159b30eef119ccf6846c8bc807d0eaa3f6f8","analyzedAt":"2026-08-16T10:12:14.925Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}