@divebell/agent-browser 0.33.2-divebell.8 → 0.34.0-divebell.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -345,6 +345,8 @@ agent-browser click @e3 # click uses docs's refs
345
345
  agent-browser tab close docs # close by label
346
346
  ```
347
347
 
348
+ `tab list --json` also reports each tab's CDP `targetId`, and target ids are accepted anywhere a tab ref is accepted (`tab <targetId>`, `tab close <targetId>`). Unlike `t<N>` ids, which are per-daemon counters, target ids stay stable across daemon restarts, so they're the right handle for scripts coordinating multiple sessions on one browser.
349
+
348
350
  Switching to a tab discarded by Chrome's Memory Saver reactivates it, since a discarded tab has no renderer to drive. Reactivation reloads the discarded page and resets its unsaved state, and the switch result reports `"revived": true`. A tab whose page is paused by a JavaScript dialog or debugger is alive rather than discarded, so the switch leaves it untouched and reports `"dialogBlocked": true` or `"debuggerPaused": true`. Resolve the dialog or resume the debugger before interacting. Closing the active tab onto a discarded successor revives it the same way and reports `"activeTabRevived": true`.
349
351
 
350
352
  ### Frames
@@ -776,6 +778,31 @@ Each session has its own:
776
778
  - Navigation history
777
779
  - Authentication state
778
780
 
781
+ ### Tab pinning
782
+
783
+ When several sessions share one Chrome over `--cdp`, each session remembers which tab it is bound to (by CDP target id, persisted across daemon restarts). A restarted daemon reattaches to the session's own tab instead of adopting whatever tab happens to be active, which is usually another session's.
784
+
785
+ By default, if the bound tab is closed the session falls back to a neighboring tab (legacy behavior). Pass `--pin-tab` (or set `AGENT_BROWSER_PIN_TAB=1`) to make the binding strict:
786
+
787
+ ```bash
788
+ # Two agents sharing one Chrome, each pinned to its own tab
789
+ agent-browser --session agent1 --cdp 9222 --pin-tab open site-a.com
790
+ agent-browser --session agent2 --cdp 9222 --pin-tab open site-b.com
791
+ ```
792
+
793
+ With `--pin-tab`:
794
+
795
+ - Attaching with no binding opens a fresh tab instead of adopting an existing one
796
+ - If the bound tab is closed, commands fail with a `tab_gone` error (exit code 1) instead of silently acting on another tab. JSON responses carry `"code": "tab_gone"` and recovery metadata in `data.targetId` plus optional `data.lastUrl`
797
+ - `tab list`, `tab new`, and `tab <ref>` still work in that state, so an agent can recover by binding a new tab
798
+ - Tabs opened by other sessions or the user never steal the pinned session's active tab
799
+
800
+ The flag is sticky per session: pass it once and later commands and daemon restarts keep the strict semantics. Pass `--no-pin-tab` to explicitly turn the pin off again.
801
+
802
+ `data.lastUrl` is emitted only for sanitized HTTP(S) URLs and `about:blank`. HTTP(S) credentials, query strings, and fragments are removed, and opaque URLs such as `data:` are omitted. Batch output exposes the same object as `result`.
803
+
804
+ When re-running a shared-tab script such as the repro from #1530, add `--pin-tab` to the first command for every session. Without it, `open` intentionally preserves the legacy behavior and navigates the shared active tab, so the original script still collides. The same rule applies when sessions attach with `--auto-connect` instead of `--cdp`.
805
+
779
806
  ## Chrome Profile Reuse
780
807
 
781
808
  The fastest way to use your existing login state: pass a Chrome profile name to `--profile`:
@@ -1067,6 +1094,8 @@ This is useful for multimodal AI models that can reason about visual layout, unl
1067
1094
  | `--webgpu` | Enable WebGPU; SwiftShader software Vulkan on Linux, no GPU required (or `AGENT_BROWSER_WEBGPU` env) |
1068
1095
  | `--cdp <port\|url>` | Connect via Chrome DevTools Protocol (port or WebSocket URL) |
1069
1096
  | `--auto-connect` | Auto-discover and connect to running Chrome (or `AGENT_BROWSER_AUTO_CONNECT` env) |
1097
+ | `--pin-tab` | Pin the session to its bound tab; fail with `tab_gone` instead of falling back to another tab (or `AGENT_BROWSER_PIN_TAB` env) |
1098
+ | `--no-pin-tab` | Disable a sticky pin previously enabled with `--pin-tab` |
1070
1099
  | `--color-scheme <scheme>` | Color scheme: `dark`, `light`, `no-preference` (or `AGENT_BROWSER_COLOR_SCHEME` env) |
1071
1100
  | `--download-path <path>` | Default download directory (or `AGENT_BROWSER_DOWNLOAD_PATH` env) |
1072
1101
  | `--content-boundaries` | Wrap page output in boundary markers for LLM safety (or `AGENT_BROWSER_CONTENT_BOUNDARIES` env) |
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@divebell/agent-browser",
3
- "version": "0.33.2-divebell.8",
3
+ "version": "0.34.0-divebell.2",
4
4
  "description": "Browser automation CLI for AI agents with Divebell memory diagnostics",
5
5
  "type": "module",
6
6
  "engines": {
@@ -21,6 +21,16 @@ agent-browser snapshot -i # 4. Re-snapshot after any page change
21
21
 
22
22
  Refs (`@e1`, `@e2`, ...) are assigned fresh on every snapshot. They become **stale the moment the page changes** — after clicks that navigate, form submits, dynamic re-renders, dialog opens. Always re-snapshot before your next ref interaction.
23
23
 
24
+ ## Always use your own session
25
+
26
+ Before your first command, set a named session for the whole task:
27
+
28
+ ```bash
29
+ export AGENT_BROWSER_SESSION="$(agent-browser session id --scope worktree --prefix task)"
30
+ ```
31
+
32
+ The default (unnamed) session is a single shared browser: it is shared with every other agent on the machine and it persists across conversations, so working in it can hijack another agent's page mid-task or navigate away from something the human left open. Every example below assumes a named session is active. See [Run multiple browsers in parallel](#run-multiple-browsers-in-parallel) and `references/session-management.md`.
33
+
24
34
  ## Quickstart
25
35
 
26
36
  ```bash
@@ -289,7 +299,7 @@ agent-browser tab t2 # switch to tab t2
289
299
  agent-browser tab close t2 # close tab t2
290
300
  ```
291
301
 
292
- Stable `tabId`s mean `t2` points at the same tab across commands even when other tabs open or close. After switching, refs from a prior snapshot on a different tab no longer apply — re-snapshot.
302
+ Stable `tabId`s mean `t2` points at the same tab across commands even when other tabs open or close. After switching, refs from a prior snapshot on a different tab no longer apply — re-snapshot. `tab list --json` also reports each tab's CDP `targetId`, accepted anywhere a tab ref is accepted; target ids stay stable across daemon restarts, unlike `t<N>` ids.
293
303
 
294
304
  Switching has two special cases worth knowing:
295
305
 
@@ -309,6 +319,8 @@ agent-browser --session b fill @e1 "bob@test.com"
309
319
 
310
320
  `AGENT_BROWSER_SESSION=myapp` sets the default session for the current shell.
311
321
 
322
+ When several sessions share one Chrome over `--cdp <port>`, add `--pin-tab` so each session sticks to its own tab. Every session remembers its bound tab across daemon restarts; with `--pin-tab` a command whose bound tab was closed fails with a `tab_gone` error instead of acting on another session's tab. JSON output includes `"code": "tab_gone"`, `data.targetId`, and an optional sanitized `data.lastUrl` for recovery. Recover with `tab new <url>` or pick a tab from `tab list`. The flag is sticky per session, so pass it once (`--no-pin-tab` turns it off again). See `references/session-management.md` for details.
323
+
312
324
  ### Mock network requests
313
325
 
314
326
  ```bash
@@ -232,6 +232,8 @@ agent-browser tab close docs # close by label
232
232
 
233
233
  Labels are never auto-generated, never rewritten on navigation, and must be unique within a session. To interact with another tab, switch to it first: the daemon maintains a single active tab, so refs (`@eN`) belong to the tab that was active when the snapshot ran.
234
234
 
235
+ `tab list --json` also reports each tab's CDP `targetId`, accepted anywhere a tab ref is accepted (`tab <targetId>`, `tab close <targetId>`). Target ids stay stable across daemon restarts, unlike `t<N>` ids, which are per-daemon counters. With `--pin-tab` the session is pinned to its bound tab: if that tab is closed, commands fail with a `tab_gone` error instead of falling back to another tab, and `tab new` or `tab list` recover. JSON errors include `code: "tab_gone"` and a recovery object with `data.targetId` plus optional sanitized `data.lastUrl`; batch uses `result` for the same object.
236
+
235
237
  Switching to a tab that the browser discarded to save memory reactivates it, since a discarded tab has no renderer to drive. Reactivation reloads the page and resets its unsaved state, and the switch result adds `"revived": true` so the reload is not silent. A tab whose page is paused by a JavaScript dialog or debugger is alive rather than discarded: the switch leaves it untouched and adds `"dialogBlocked": true` or `"debuggerPaused": true`. Resolve the dialog or resume the debugger and its state is preserved. Closing the active tab onto a discarded successor revives it the same way and reports `"activeTabRevived": true`.
236
238
 
237
239
  ## Frames
@@ -390,6 +392,8 @@ agent-browser --json ... # JSON output for parsing
390
392
  agent-browser --headed ... # Show browser window (not headless; on displayless Linux an Xvfb display starts automatically)
391
393
  agent-browser --webgpu ... # Enable WebGPU (SwiftShader software Vulkan on Linux, no GPU needed)
392
394
  agent-browser --cdp <port> ... # Connect via Chrome DevTools Protocol
395
+ agent-browser --pin-tab ... # Pin the session to its bound tab (strict tab binding)
396
+ agent-browser --no-pin-tab ... # Disable a sticky pin previously enabled with --pin-tab
393
397
  agent-browser -p <provider> ... # Browser provider or configured provider plugin
394
398
  agent-browser --proxy <url> ... # Use proxy server
395
399
  agent-browser --proxy-bypass <hosts> # Hosts to bypass proxy
@@ -8,6 +8,7 @@ Multiple isolated browser sessions with state persistence and concurrent browsin
8
8
 
9
9
  - [Named Sessions](#named-sessions)
10
10
  - [Session Isolation Properties](#session-isolation-properties)
11
+ - [Tab Pinning in a Shared Browser](#tab-pinning-in-a-shared-browser)
11
12
  - [Session State Persistence](#session-state-persistence)
12
13
  - [Common Patterns](#common-patterns)
13
14
  - [Default Session](#default-session)
@@ -47,6 +48,28 @@ Each session has independent:
47
48
  - Browsing history
48
49
  - Open tabs
49
50
 
51
+ ## Tab Pinning in a Shared Browser
52
+
53
+ Full isolation applies when each session launches its own browser. When sessions instead share one Chrome over `--cdp <port>`, cookies and storage are shared, and only the tab selection separates the sessions. Add `--pin-tab` so each session sticks to its own tab:
54
+
55
+ ```bash
56
+ agent-browser --session agent1 --cdp 9222 --pin-tab open https://site-a.com
57
+ agent-browser --session agent2 --cdp 9222 --pin-tab open https://site-b.com
58
+ ```
59
+
60
+ Every session remembers which tab it is bound to (by CDP target id, persisted in the session's state directory), so a restarted daemon reattaches to the session's own tab instead of adopting the most recently active one. `--pin-tab` (env `AGENT_BROWSER_PIN_TAB=1`) additionally makes the binding strict:
61
+
62
+ - Attaching with no binding opens a fresh tab instead of adopting an existing one
63
+ - If the bound tab is closed, commands fail with a `tab_gone` error instead of silently acting on another tab. JSON output includes `"code": "tab_gone"`, `data.targetId`, and optional `data.lastUrl`
64
+ - Recovery commands still work in that state: run `tab new <url>` to bind a fresh tab, or `tab list` and switch to an existing one
65
+ - Tabs opened by other sessions or the user never steal the pinned session's active tab
66
+
67
+ The flag is sticky per session: pass it once at session creation and later commands and daemon restarts keep the strict semantics. Pass `--no-pin-tab` to explicitly turn the pin off again. Use each tab's `targetId` from `tab list --json` when one session needs to reference another session's tab; target ids stay stable across daemon restarts.
68
+
69
+ The structured `lastUrl` is limited to sanitized HTTP(S) URLs and `about:blank`. Credentials, query strings, and fragments are removed from HTTP(S) URLs. Opaque URLs such as `data:` are omitted. In batch JSON, the recovery object appears under `result` instead of `data`.
70
+
71
+ When re-running a shared-tab script such as the repro from #1530, add `--pin-tab` to the first command for every session. Without it, `open` intentionally preserves the legacy behavior and navigates the shared active tab, so the original script still collides. The same rule applies when sessions attach with `--auto-connect` instead of `--cdp`.
72
+
50
73
  ## Session State Persistence
51
74
 
52
75
  ### Automatic Restore