#18888: Fix: Merge targetId into request body for browser act operations
agents
size: XS
Cluster:
Error Handling Improvements
## Problem
When the browser tool receives act operations (click, type, etc.), the targetId parameter was being dropped during request construction.
The tool receives:
```json
{action: 'act', request: {kind: 'click', ref: 'e52'}, targetId: 'ABC...'}
```
But only `params.request` was passed to `browserAct()`, losing `params.targetId`.
## Impact
This caused `ensureTabAvailable()` to be called with `undefined`, falling back to `pickDefault()` which uses `profileState.lastTargetId` from whatever agent used the browser last, resulting in operations executing on the wrong tab.
**Symptoms:** When multiple agents use the browser concurrently, clicks would redirect to unexpected pages (e.g., agent clicks LinkedIn profile link, ends up on a different agent's search results page).
## Fix
Merge `params.targetId` into the request object before passing to `browserAct()`:
```typescript
const request = {
...requestBody,
targetId: params.targetId,
};
```
## Testing
Verified with debug logging showing targetId is now correctly passed through to `ensureTabAvailable()` during concurrent browser operations (0 mismatches across 247+ operations).
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Fixed tab targeting bug in browser tool where `targetId` was dropped during `act` operation requests. The tool receives `targetId` at the top level but only passed the nested `request` object to `browserAct()`, causing operations to execute on the wrong tab when multiple agents used the browser concurrently. The fix merges `params.targetId` into the request body before passing to `browserAct()` and proxy requests.
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The fix is simple, well-scoped, and directly addresses a clear bug. The change adds the missing `targetId` field by spreading it into the request object, which aligns with how all other browser operations (upload, dialog, etc.) handle this field. The PR description provides clear testing evidence (0 mismatches across 247+ operations), and the fix follows the established pattern in the codebase.
- No files require special attention
<sub>Last reviewed commit: 30b12f0</sub>
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#23075: fix(browser): merge top-level ref/targetId into act request body
by Remixer33 · 2026-02-22
80.7%
#3794: fix(browser-tool): disallow close without targetId to avoid unsafe ...
by JaydenLiang · 2026-01-29
76.9%
#14784: fix(browser): clarify stale targetId errors (tab not found)
by sovushik · 2026-02-12
74.6%
#14728: fix(browser): add targetUrl description and improve error messages ...
by lailoo · 2026-02-12
73.0%
#18907: Fix: Improve browser error messages to avoid misleading agents
by jriff · 2026-02-17
72.9%
#19143: fix: support target param in message tool send extraction
by botverse · 2026-02-17
71.2%
#16030: fix(browser): extend single-tab fallback to remote CDP profiles
by lailoo · 2026-02-14
71.2%
#20207: fix(browser): use profile driver instead of hardcoded name
by mahsumaktas · 2026-02-18
69.9%
#23668: fix: distinguish browser validation errors from connectivity failures
by davidemanuelDEV · 2026-02-22
69.5%
#9693: fix: add configurable browser.actTimeoutMs to prevent action timeouts
by JitendraZaa · 2026-02-05
68.7%