From aa08e740cb2f12cb424a2d042619955c99230ed7 Mon Sep 17 00:00:00 2001 From: amankumarsingh77 Date: Fri, 8 May 2026 00:18:15 +0530 Subject: feat: add per-tab isolation for multi-agent safety Replace singleton dialog, pageInfoDirty, networkBuffer, and consoleBuffer with per-tab TabSession objects stored in a Map. - Add TabSession type (sessionId, targetId, dialog, pageInfoDirty, networkBuffer, consoleBuffer) and tabs/sessionIdToTargetId Maps - Add ev.sessionId filter guard in consumeEvents to prevent cross-tab event contamination - Rework switchTo to create/reuse TabSession without clearing buffers, updating sessionId on re-attach - Route all CDP events (dialog, network, console) through resolveTab to the correct TabSession - takeDialog/drainPageInfoInvalidations/drainNetworkBuffer/ drainConsoleBuffer read from current TabSession - Target.targetDestroyed prunes dead TabSession entries - attachFirstPage creates initial TabSession and prunes dead entries - Per-tab pageCaches Map in client.ts replaces pageCache singleton - listTabs reconciliation prunes dead pageCaches entries - console-buffer.ts clear() resets nextSeq to 1 (per-tab seq space) - Multi-agent warning in prompt.ts Parallel Execution section --- src/prompt.ts | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/prompt.ts') diff --git a/src/prompt.ts b/src/prompt.ts index 850d36f..ae94db3 100644 --- a/src/prompt.ts +++ b/src/prompt.ts @@ -74,6 +74,8 @@ browser_screenshot() + browser_page_info() + browser_execute_js("document.title" browser_http_get("https://api.example.com/data") + browser_click(x, y) \`\`\` +**Multi-agent note**: When multiple subagents use the browser, tab switching by one agent changes the active tab for all agents. Per-tab data (console buffers, network traces, dialogs, page info cache) is isolated — switching tabs does not destroy another agent's collected data. Call \`browser_current_tab\` before mutation tools to confirm you're on the expected tab. If \`browser_page_info\` returns a dialog, handle it with \`browser_handle_dialog\` promptly — dialogs block page interaction and are not queued across agents. + ### Common Patterns **Navigation:** -- cgit v1.2.3