agent-browser 0.30.1 → 0.31.0

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
@@ -557,7 +557,7 @@ agent-browser provides multiple ways to persist login sessions so you don't re-a
557
557
  |----------|----------|------------|
558
558
  | **Chrome profile reuse** | Reuse your existing Chrome login state (cookies, sessions) with zero setup | `--profile <name>` / `AGENT_BROWSER_PROFILE` |
559
559
  | **Persistent profile** | Full browser state (cookies, IndexedDB, service workers, cache) across restarts | `--profile <path>` / `AGENT_BROWSER_PROFILE` |
560
- | **Session persistence** | Auto-save/restore cookies + localStorage by name | `--session-name <name>` / `AGENT_BROWSER_SESSION_NAME` |
560
+ | **Session persistence** | Auto-save/restore cookies + localStorage from a stable session key | `--session <id> --restore` / `AGENT_BROWSER_RESTORE` |
561
561
  | **Import from your browser** | Grab auth from a Chrome session you already logged into | `--auto-connect` + `state save` |
562
562
  | **State file** | Load a previously saved state JSON on launch | `--state <path>` / `AGENT_BROWSER_STATE` |
563
563
  | **Auth vault** | Store credentials locally (encrypted), login by name | `auth save` / `auth login` |
@@ -578,9 +578,10 @@ agent-browser --auto-connect state save ./my-auth.json
578
578
  # 3. Use the saved auth in future sessions
579
579
  agent-browser --state ./my-auth.json open https://app.example.com/dashboard
580
580
 
581
- # 4. Or use --session-name for automatic persistence
582
- agent-browser --session-name myapp state load ./my-auth.json
583
- # From now on, --session-name myapp auto-saves/restores this state
581
+ # 4. Or use --restore for automatic persistence
582
+ SESSION="$(agent-browser session id --scope worktree --prefix myapp)"
583
+ agent-browser --session "$SESSION" --restore --state ./my-auth.json open https://app.example.com/dashboard
584
+ # From now on, --session "$SESSION" --restore auto-saves/restores this state
584
585
  ```
585
586
 
586
587
  > **Security notes:**
@@ -610,6 +611,12 @@ agent-browser session list
610
611
 
611
612
  # Show current session
612
613
  agent-browser session
614
+
615
+ # Generate a stable worktree-scoped session id
616
+ agent-browser session id --scope worktree --prefix next-dev-loop
617
+
618
+ # Inspect daemon, launch, and restore status
619
+ agent-browser session info --json
613
620
  ```
614
621
 
615
622
  Each session has its own:
@@ -668,18 +675,18 @@ The profile directory stores:
668
675
 
669
676
  ## Session Persistence
670
677
 
671
- Alternatively, use `--session-name` to automatically save and restore cookies and localStorage across browser restarts:
678
+ Use `--restore` with a stable `--session` to automatically save and restore cookies and localStorage across browser restarts:
672
679
 
673
680
  ```bash
674
- # Auto-save/load state for "twitter" session
675
- agent-browser --session-name twitter open twitter.com
681
+ # Generate a stable id for this worktree and auto-save/load state
682
+ SESSION="$(agent-browser session id --scope worktree --prefix twitter)"
683
+ agent-browser --session "$SESSION" --restore open twitter.com
676
684
 
677
685
  # Login once, then state persists automatically
678
686
  # State files stored in ~/.agent-browser/sessions/
679
687
 
680
- # Or via environment variable
681
- export AGENT_BROWSER_SESSION_NAME=twitter
682
- agent-browser open twitter.com
688
+ # Optional: validate restored state before auto-saving again
689
+ agent-browser --session "$SESSION" --restore --restore-check-text Dashboard open twitter.com
683
690
  ```
684
691
 
685
692
  ### State Encryption
@@ -691,12 +698,15 @@ Encrypt saved session data at rest with AES-256-GCM:
691
698
  export AGENT_BROWSER_ENCRYPTION_KEY=<64-char-hex-key>
692
699
 
693
700
  # State files are now encrypted automatically
694
- agent-browser --session-name secure open example.com
701
+ agent-browser --session secure --restore open example.com
695
702
  ```
696
703
 
697
704
  | Variable | Description |
698
705
  | --------------------------------- | -------------------------------------------------- |
699
- | `AGENT_BROWSER_SESSION_NAME` | Auto-save/load state persistence name |
706
+ | `AGENT_BROWSER_RESTORE` | Auto-save/load state persistence name |
707
+ | `AGENT_BROWSER_RESTORE_SAVE` | Restore save policy: `auto`, `always`, or `never` |
708
+ | `AGENT_BROWSER_NAMESPACE` | Namespace for daemon sockets and restore state |
709
+ | `AGENT_BROWSER_SESSION_NAME` | Legacy auto-save/load state persistence name |
700
710
  | `AGENT_BROWSER_ENCRYPTION_KEY` | 64-char hex key for AES-256-GCM encryption |
701
711
  | `AGENT_BROWSER_STATE_EXPIRE_DAYS` | Auto-delete states older than N days (default: 30) |
702
712
 
@@ -861,7 +871,13 @@ This is useful for multimodal AI models that can reason about visual layout, unl
861
871
  | Option | Description |
862
872
  |--------|-------------|
863
873
  | `--session <name>` | Use isolated session (or `AGENT_BROWSER_SESSION` env) |
864
- | `--session-name <name>` | Auto-save/restore session state (or `AGENT_BROWSER_SESSION_NAME` env) |
874
+ | `--restore [name]` | Auto-save/restore session state. Bare `--restore` uses `--session` as the key |
875
+ | `--restore-save <policy>` | Restore save policy: `auto`, `always`, or `never` |
876
+ | `--restore-check-url <glob>` | Validate restored state against a URL pattern |
877
+ | `--restore-check-text <text>` | Validate restored state against page text |
878
+ | `--restore-check-fn <js>` | Validate restored state against a truthy JavaScript expression |
879
+ | `--namespace <name>` | Isolate daemon sockets and restore-state directories |
880
+ | `--session-name <name>` | Legacy alias for restore persistence key |
865
881
  | `--profile <name\|path>` | Chrome profile name or persistent directory path (or `AGENT_BROWSER_PROFILE` env) |
866
882
  | `--state <path>` | Load storage state from JSON file (or `AGENT_BROWSER_STATE` env) |
867
883
  | `--headers <json>` | Set HTTP headers scoped to the URL's origin |
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": "agent-browser",
3
- "version": "0.30.1",
3
+ "version": "0.31.0",
4
4
  "description": "Browser automation CLI for AI agents",
5
5
  "type": "module",
6
6
  "engines": {
@@ -221,18 +221,18 @@ agent-browser plugin run captcha captcha.solve --payload '{"siteKey":"...","url"
221
221
  ### Persist session across runs
222
222
 
223
223
  ```bash
224
- # Log in once, save cookies + localStorage
225
- agent-browser state save ./auth.json
224
+ # Derive one stable id for this agent/worktree
225
+ SESSION="$(agent-browser session id --scope worktree --prefix my-app)"
226
226
 
227
- # Later runs start already-logged-in
228
- agent-browser --state ./auth.json open https://app.example.com
227
+ # Pass the same id and restore request on every command
228
+ agent-browser --session "$SESSION" --restore open https://app.example.com
229
229
  ```
230
230
 
231
- Or use `--session-name` for auto-save/restore:
231
+ `--restore` with no value uses the current `--session` as the persistence key. Agent skills should prefer this over hand-built state file paths. Use `--restore-save auto` by default so a failed restore does not overwrite the previous known-good state.
232
232
 
233
233
  ```bash
234
- AGENT_BROWSER_SESSION_NAME=my-app agent-browser open https://app.example.com
235
- # State is auto-saved and restored on subsequent runs with the same name.
234
+ agent-browser --session "$SESSION" --restore --restore-check-text Dashboard open https://app.example.com
235
+ agent-browser --session "$SESSION" session info --json
236
236
  ```
237
237
 
238
238
  ### Extract data
@@ -284,7 +284,7 @@ Stable `tabId`s mean `t2` points at the same tab across commands even when other
284
284
 
285
285
  ### Run multiple browsers in parallel
286
286
 
287
- Each `--session <name>` is an isolated browser with its own cookies, tabs, and refs. Useful for testing multi-user flows or parallel scraping:
287
+ Each `--session <name>` is an isolated browser with its own cookies, tabs, and refs. For agent skills, derive stable names with `agent-browser session id --scope worktree --prefix <skill>`. Useful for testing multi-user flows or parallel scraping:
288
288
 
289
289
  ```bash
290
290
  agent-browser --session a open https://app.example.com
@@ -400,7 +400,7 @@ EOF
400
400
 
401
401
  **Cross-origin iframe not accessible** Cross-origin iframes that block accessibility tree access are silently skipped. Use `frame "#iframe"` to switch into them explicitly if the parent opts in, otherwise the iframe's contents aren't available via snapshot — fall back to `eval` in the iframe's origin or use the `--headers` flag to satisfy CORS.
402
402
 
403
- **Authentication expires mid-workflow** Use `--session-name <name>` or `state save`/`state load` so your session survives browser restarts. See [references/session-management.md](references/session-management.md) and [references/authentication.md](references/authentication.md).
403
+ **Authentication expires mid-workflow** Use `--session <id> --restore` so your session survives browser restarts. Check `agent-browser session info --json` if restore fails. See [references/session-management.md](references/session-management.md) and [references/authentication.md](references/authentication.md).
404
404
 
405
405
  ## Global flags worth knowing
406
406
 
@@ -414,7 +414,9 @@ EOF
414
414
  --headers <json> # HTTP headers scoped to the URL's origin
415
415
  --proxy <url> # proxy server
416
416
  --state <path> # load saved auth state from JSON
417
- --session-name <name> # auto-save/restore session state by name
417
+ --restore [name] # auto-save/restore session state, defaults to --session
418
+ --restore-save <policy> # auto, always, or never
419
+ --namespace <name> # isolate daemon sockets and restore-state directories
418
420
  ```
419
421
 
420
422
  ## When to load another skill
@@ -54,20 +54,22 @@ agent-browser --auto-connect state save ./my-auth.json
54
54
  # Load auth at launch
55
55
  agent-browser --state ./my-auth.json open https://app.example.com/dashboard
56
56
 
57
- # Or load into an existing session
57
+ # Or load into an already-launched session
58
+ agent-browser open about:blank
58
59
  agent-browser state load ./my-auth.json
59
60
  agent-browser open https://app.example.com/dashboard
60
61
  ```
61
62
 
62
- This works for any site, including those with complex OAuth flows, SSO, or 2FA -- as long as Chrome already has valid session cookies.
63
+ This works for any site, including those with complex OAuth flows, SSO, or 2FA, as long as Chrome already has valid session cookies.
63
64
 
64
65
  > **Security note:** State files contain session tokens in plaintext. Add them to `.gitignore`, delete when no longer needed, and set `AGENT_BROWSER_ENCRYPTION_KEY` for encryption at rest. See [Security Best Practices](#security-best-practices).
65
66
 
66
- **Tip:** Combine with `--session-name` so the imported auth auto-persists across restarts:
67
+ **Tip:** Combine with `--session <id> --restore` so the imported auth auto-persists across restarts:
67
68
 
68
69
  ```bash
69
- agent-browser --session-name myapp state load ./my-auth.json
70
- # From now on, state is auto-saved/restored for "myapp"
70
+ SESSION="$(agent-browser session id --scope worktree --prefix myapp)"
71
+ agent-browser --session "$SESSION" --restore --state ./my-auth.json open https://app.example.com/dashboard
72
+ # From now on, state is auto-saved/restored for this session
71
73
  ```
72
74
 
73
75
  ## Persistent Profiles
@@ -99,23 +101,24 @@ agent-browser open https://app.example.com/dashboard
99
101
 
100
102
  ## Session Persistence
101
103
 
102
- Use `--session-name` to auto-save and restore cookies + localStorage by name, without managing files:
104
+ Use `--restore` with a stable `--session` to auto-save and restore cookies + localStorage without managing files:
103
105
 
104
106
  ```bash
105
107
  # Auto-saves state on close, auto-restores on next launch
106
- agent-browser --session-name twitter open https://twitter.com
108
+ SESSION="$(agent-browser session id --scope worktree --prefix twitter)"
109
+ agent-browser --session "$SESSION" --restore open https://twitter.com
107
110
  # ... login flow ...
108
- agent-browser close # state saved to ~/.agent-browser/sessions/
111
+ agent-browser --session "$SESSION" --restore close # state saved to ~/.agent-browser/sessions/
109
112
 
110
113
  # Next time: state is automatically restored
111
- agent-browser --session-name twitter open https://twitter.com
114
+ agent-browser --session "$SESSION" --restore open https://twitter.com
112
115
  ```
113
116
 
114
117
  Encrypt state at rest:
115
118
 
116
119
  ```bash
117
120
  export AGENT_BROWSER_ENCRYPTION_KEY=$(openssl rand -hex 32)
118
- agent-browser --session-name secure open https://app.example.com
121
+ agent-browser --session secure --restore open https://app.example.com
119
122
  ```
120
123
 
121
124
  ## Basic Login Flow
@@ -16,7 +16,14 @@ Multiple isolated browser sessions with state persistence and concurrent browsin
16
16
 
17
17
  ## Named Sessions
18
18
 
19
- Use `--session` flag to isolate browser contexts:
19
+ Use `--session` to isolate browser contexts. Agent skills should derive one stable id and reuse it on every command:
20
+
21
+ ```bash
22
+ SESSION="$(agent-browser session id --scope worktree --prefix my-skill)"
23
+ agent-browser --session "$SESSION" --restore open https://app.example.com/login
24
+ ```
25
+
26
+ `--scope worktree` uses the Git worktree root when available, then the Git root, then the canonical current directory. This is the recommended default for agents because worktrees are commonly used for parallel agent runs.
20
27
 
21
28
  ```bash
22
29
  # Session 1: Authentication flow
@@ -42,60 +49,40 @@ Each session has independent:
42
49
 
43
50
  ## Session State Persistence
44
51
 
45
- ### Save Session State
52
+ ### Automatic Restore
46
53
 
47
54
  ```bash
48
- # Save cookies, storage, and auth state
49
- agent-browser state save /path/to/auth-state.json
55
+ # Bare --restore uses the current --session as the persistence key
56
+ SESSION="$(agent-browser session id --scope worktree --prefix next-dev-loop)"
57
+ agent-browser --session "$SESSION" --restore open https://app.example.com/dashboard
50
58
  ```
51
59
 
52
- ### Load Session State
60
+ State is loaded before navigation and saved on close, daemon shutdown, idle timeout, and compatible relaunch. The default save policy is `--restore-save auto`, which skips auto-save if restore failed or validation failed.
53
61
 
54
62
  ```bash
55
- # Restore saved state
56
- agent-browser state load /path/to/auth-state.json
57
-
58
- # Continue with authenticated session
59
- agent-browser open https://app.example.com/dashboard
63
+ agent-browser --session "$SESSION" --restore --restore-check-url "**/dashboard" open https://app.example.com/dashboard
64
+ agent-browser --session "$SESSION" --restore --restore-check-text Dashboard open https://app.example.com/dashboard
65
+ agent-browser --session "$SESSION" --restore --restore-check-fn "!!localStorage.getItem('session')" open https://app.example.com/dashboard
60
66
  ```
61
67
 
62
- ### State File Contents
68
+ Use `agent-browser session info --json` for diagnostics:
63
69
 
64
- ```json
65
- {
66
- "cookies": [...],
67
- "localStorage": {...},
68
- "sessionStorage": {...},
69
- "origins": [...]
70
- }
70
+ ```bash
71
+ agent-browser --session "$SESSION" session info --json
71
72
  ```
72
73
 
74
+ ### Manual State Files
75
+
76
+ Use `state save`, `state load`, and `--state <path>` when you need an explicit portable JSON file. Do not make agents construct paths under `~/.agent-browser/sessions/`; prefer `--restore` for reusable agent sessions.
77
+
73
78
  ## Common Patterns
74
79
 
75
80
  ### Authenticated Session Reuse
76
81
 
77
82
  ```bash
78
83
  #!/bin/bash
79
- # Save login state once, reuse many times
80
-
81
- STATE_FILE="/tmp/auth-state.json"
82
-
83
- # Check if we have saved state
84
- if [[ -f "$STATE_FILE" ]]; then
85
- agent-browser state load "$STATE_FILE"
86
- agent-browser open https://app.example.com/dashboard
87
- else
88
- # Perform login
89
- agent-browser open https://app.example.com/login
90
- agent-browser snapshot -i
91
- agent-browser fill @e1 "$USERNAME"
92
- agent-browser fill @e2 "$PASSWORD"
93
- agent-browser click @e3
94
- agent-browser wait --load networkidle
95
-
96
- # Save for future use
97
- agent-browser state save "$STATE_FILE"
98
- fi
84
+ SESSION="$(agent-browser session id --scope worktree --prefix app)"
85
+ agent-browser --session "$SESSION" --restore open https://app.example.com/dashboard
99
86
  ```
100
87
 
101
88
  ### Concurrent Scraping