{"record":{"id":"8f292e12b3c62839","repo":"stablyai/orca","slug":"browser-target-ambiguous","errorCode":"browser_target_ambiguous","errorMessage":"Multiple worktrees have browser tabs open; pass --worktree to target text insertion safely","messagePattern":"Multiple worktrees have browser tabs open; pass --worktree to target text insertion safely","errorType":"error_code","errorClass":"BrowserError","httpStatus":null,"severity":"warning","filePath":"src/main/browser/agent-browser-bridge.ts","lineNumber":2279,"sourceCode":"\n  // Why: don't fall back to the global tab for text mutation — it could inject into another worktree's foreground webview and steal focus.\n  private resolveScopedActiveTab(worktreeId?: string): ResolvedBrowserCommandTarget {\n    if (worktreeId) {\n      return this.resolveActiveTab(worktreeId)\n    }\n\n    const worktreesWithLiveTabs = new Set<string | undefined>()\n    for (const [tabId, wcId] of this.getRegisteredTabs(undefined)) {\n      if (this.getWebContents(wcId)) {\n        worktreesWithLiveTabs.add(this.browserManager.getWorktreeIdForTab(tabId))\n      }\n    }\n\n    if (worktreesWithLiveTabs.size === 0) {\n      throw new BrowserError('browser_no_tab', 'No browser tab open in this worktree')\n    }\n    if (worktreesWithLiveTabs.size > 1) {\n      throw new BrowserError(\n        'browser_target_ambiguous',\n        'Multiple worktrees have browser tabs open; pass --worktree to target text insertion safely'\n      )\n    }\n\n    const [onlyWorktreeId] = worktreesWithLiveTabs\n    return this.resolveActiveTab(onlyWorktreeId)\n  }\n\n  private async ensureSession(\n    sessionName: string,\n    browserPageId: string,\n    webContentsId: number\n  ): Promise<void> {\n    const pendingDestruction = this.pendingSessionDestruction.get(sessionName)\n    if (pendingDestruction) {\n      await pendingDestruction\n    }","sourceCodeStart":2261,"sourceCodeEnd":2297,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/src/main/browser/agent-browser-bridge.ts#L2261-L2297","documentation":"Thrown by resolveScopedActiveTab when more than one worktree has at least one live browser tab and no worktreeId was provided. Because text-mutation commands could inject into the wrong worktree's foreground webview and steal focus, the resolver refuses to guess — it demands an explicit --worktree flag. This is a safety guard, not a crash.","triggerScenarios":"A text-insertion command (type, fill, select-all, focus-element) is called without worktreeId while two or more worktrees each have live browser tabs. resolveScopedActiveTab collects worktreesWithLiveTabs, finds size > 1, and throws browser_target_ambiguous. The message tells the caller to pass --worktree.","commonSituations":"User/agent has multiple worktree sessions open, each with a browser tab, and issues a type command without specifying which worktree; agent loop didn't track which worktree it's operating in; multi-worktree development session with concurrent browser panels.","solutions":["Pass the correct worktreeId when calling the text-mutation command — the message explicitly recommends `--worktree`.","If operating in a single-worktree context, ensure other worktrees' tabs are closed so the resolver can auto-target the sole remaining one.","Track the active worktree in the agent's command context and propagate it to all browser text commands."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// before calling a text-mutation command, check if disambiguation is needed\nconst worktrees = bridge.getWorktreesWithLiveTabs()\nif (worktrees.size > 1 && !worktreeId) {\n  // must pass worktreeId to avoid ambiguity\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await bridge.type(text) // no worktreeId\n} catch (e) {\n  if (e instanceof BrowserError && e.code === 'browser_target_ambiguous') {\n    // caller must supply the correct worktreeId\n    throw new Error('Ambiguous target: specify worktreeId')\n  }\n  throw e\n}","preventionTips":["Always pass worktreeId to text-mutation commands in multi-worktree sessions","Track the active worktree in the agent context and propagate it to all type/fill/select commands","Close unused worktree tabs to reduce ambiguity","Treat browser_target_ambiguous as a caller-error requiring explicit worktree, not a transient retry"],"tags":["browser","tab-resolution","ambiguous","worktree","text-mutation"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}