slipwing 0.0.0-stage → 0.1.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.
Files changed (99) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +143 -3
  3. package/bin/agent-desktop-win32-x64.exe +0 -0
  4. package/bin/workflow.js +512 -0
  5. package/browser/LICENSE +201 -0
  6. package/browser/LICENSE-axe-core-THIRD-PARTY.txt +66 -0
  7. package/browser/LICENSE-axe-core.txt +362 -0
  8. package/browser/bin/agent-browser-win32-x64.exe +0 -0
  9. package/browser/skill-data/agentcore/SKILL.md +115 -0
  10. package/browser/skill-data/core/SKILL.md +279 -0
  11. package/browser/skill-data/core/references/authentication.md +413 -0
  12. package/browser/skill-data/core/references/commands.md +727 -0
  13. package/browser/skill-data/core/references/profiling.md +120 -0
  14. package/browser/skill-data/core/references/proxy-support.md +221 -0
  15. package/browser/skill-data/core/references/session-management.md +215 -0
  16. package/browser/skill-data/core/references/snapshot-refs.md +244 -0
  17. package/browser/skill-data/core/references/streaming.md +107 -0
  18. package/browser/skill-data/core/references/trust-boundaries.md +69 -0
  19. package/browser/skill-data/core/references/video-recording.md +254 -0
  20. package/browser/skill-data/core/references/webgpu.md +118 -0
  21. package/browser/skill-data/core/templates/authenticated-session.sh +109 -0
  22. package/browser/skill-data/core/templates/capture-workflow.sh +69 -0
  23. package/browser/skill-data/core/templates/form-automation.sh +63 -0
  24. package/browser/skill-data/derive-client/SKILL.md +88 -0
  25. package/browser/skill-data/dogfood/SKILL.md +224 -0
  26. package/browser/skill-data/dogfood/references/issue-taxonomy.md +109 -0
  27. package/browser/skill-data/dogfood/templates/dogfood-report-template.md +53 -0
  28. package/browser/skill-data/electron/SKILL.md +236 -0
  29. package/browser/skill-data/modern-web-guidance/SKILL.md +165 -0
  30. package/browser/skill-data/slack/SKILL.md +288 -0
  31. package/browser/skill-data/slack/references/slack-tasks.md +349 -0
  32. package/browser/skill-data/slack/templates/slack-report-template.md +163 -0
  33. package/browser/skill-data/vercel/SKILL.md +160 -0
  34. package/browser/skill-data/vercel-sandbox/SKILL.md +237 -0
  35. package/browser/skill-data/webmcp-gen/SKILL.md +52 -0
  36. package/browser/skills/agent-browser/SKILL.md +51 -0
  37. package/bundle.json +19 -0
  38. package/lib/browser-move.js +185 -0
  39. package/lib/bundle-version.js +32 -0
  40. package/lib/choose.js +382 -0
  41. package/lib/cli-options.js +47 -0
  42. package/lib/control-changes.js +47 -0
  43. package/lib/current-page.js +165 -0
  44. package/lib/error-code.js +19 -0
  45. package/lib/final-picture.js +31 -0
  46. package/lib/final-words.json +7 -0
  47. package/lib/flow-record.js +32 -0
  48. package/lib/host-client.js +65 -0
  49. package/lib/host-command.js +175 -0
  50. package/lib/host-paths.js +22 -0
  51. package/lib/host-server.js +383 -0
  52. package/lib/host-waits.js +12 -0
  53. package/lib/host-watch.js +340 -0
  54. package/lib/mcp-guide.js +45 -0
  55. package/lib/mcp-server.js +264 -0
  56. package/lib/notify.js +31 -0
  57. package/lib/page-choice.js +273 -0
  58. package/lib/page-input.js +141 -0
  59. package/lib/page-lease.js +87 -0
  60. package/lib/page-line.js +83 -0
  61. package/lib/page-pointer.js +191 -0
  62. package/lib/page-read.js +44 -0
  63. package/lib/platform.js +89 -0
  64. package/lib/png-mark.js +83 -0
  65. package/lib/prefs.js +228 -0
  66. package/lib/routine-approvals.js +67 -0
  67. package/lib/routine-command.js +150 -0
  68. package/lib/routine-effects.js +119 -0
  69. package/lib/routine-store.js +143 -0
  70. package/lib/script-args.js +48 -0
  71. package/lib/script-call.js +63 -0
  72. package/lib/script-desktop.js +731 -0
  73. package/lib/script-final.js +93 -0
  74. package/lib/script-fix.js +121 -0
  75. package/lib/script-input.js +25 -0
  76. package/lib/script-match.js +90 -0
  77. package/lib/script-picture.js +104 -0
  78. package/lib/script-repeat.js +43 -0
  79. package/lib/script-run.js +367 -0
  80. package/lib/script-screen.js +53 -0
  81. package/lib/script-visible.js +228 -0
  82. package/lib/script-wait.js +15 -0
  83. package/lib/script-web.js +338 -0
  84. package/lib/skill-command.js +81 -0
  85. package/lib/space.js +56 -0
  86. package/lib/text-match.js +18 -0
  87. package/lib/watch-helper.ps1 +200 -0
  88. package/lib/web-page.js +214 -0
  89. package/lib/window-move.js +213 -0
  90. package/lib/windows-bin.js +44 -0
  91. package/package.json +32 -5
  92. package/scripts/initialize-state.ps1 +13 -0
  93. package/skills/slipwing/SKILL.md +189 -0
  94. package/skills/slipwing/chrome.md +62 -0
  95. package/skills/slipwing/desktop.md +82 -0
  96. package/skills/slipwing/human.md +63 -0
  97. package/skills/slipwing/jobs.md +82 -0
  98. package/skills/slipwing/routines.md +73 -0
  99. package/skills/slipwing/watches.md +37 -0
@@ -0,0 +1,120 @@
1
+ # Profiling
2
+
3
+ Capture Chrome DevTools performance profiles during browser automation for performance analysis.
4
+
5
+ **Related**: [commands.md](commands.md) for full command reference, [SKILL.md](../SKILL.md) for quick start.
6
+
7
+ ## Contents
8
+
9
+ - [Basic Profiling](#basic-profiling)
10
+ - [Profiler Commands](#profiler-commands)
11
+ - [Categories](#categories)
12
+ - [Use Cases](#use-cases)
13
+ - [Output Format](#output-format)
14
+ - [Viewing Profiles](#viewing-profiles)
15
+ - [Limitations](#limitations)
16
+
17
+ ## Basic Profiling
18
+
19
+ ```bash
20
+ # Start profiling
21
+ agent-browser profiler start
22
+
23
+ # Perform actions
24
+ agent-browser navigate https://example.com
25
+ agent-browser click "#button"
26
+ agent-browser wait 1000
27
+
28
+ # Stop and save
29
+ agent-browser profiler stop ./trace.json
30
+ ```
31
+
32
+ ## Profiler Commands
33
+
34
+ ```bash
35
+ # Start profiling with default categories
36
+ agent-browser profiler start
37
+
38
+ # Start with custom trace categories
39
+ agent-browser profiler start --categories "devtools.timeline,v8.execute,blink.user_timing"
40
+
41
+ # Stop profiling and save to file
42
+ agent-browser profiler stop ./trace.json
43
+ ```
44
+
45
+ ## Categories
46
+
47
+ The `--categories` flag accepts a comma-separated list of Chrome trace categories. Default categories include:
48
+
49
+ - `devtools.timeline` -- standard DevTools performance traces
50
+ - `v8.execute` -- time spent running JavaScript
51
+ - `blink` -- renderer events
52
+ - `blink.user_timing` -- `performance.mark()` / `performance.measure()` calls
53
+ - `latencyInfo` -- input-to-latency tracking
54
+ - `renderer.scheduler` -- task scheduling and execution
55
+ - `toplevel` -- broad-spectrum basic events
56
+
57
+ Several `disabled-by-default-*` categories are also included for detailed timeline, call stack, and V8 CPU profiling data.
58
+
59
+ ## Use Cases
60
+
61
+ ### Diagnosing Slow Page Loads
62
+
63
+ ```bash
64
+ agent-browser profiler start
65
+ agent-browser navigate https://app.example.com
66
+ agent-browser wait --load load
67
+ agent-browser profiler stop ./page-load-profile.json
68
+ ```
69
+
70
+ ### Profiling User Interactions
71
+
72
+ ```bash
73
+ agent-browser navigate https://app.example.com
74
+ agent-browser profiler start
75
+ agent-browser click "#submit"
76
+ agent-browser wait 2000
77
+ agent-browser profiler stop ./interaction-profile.json
78
+ ```
79
+
80
+ ### CI Performance Regression Checks
81
+
82
+ ```bash
83
+ #!/bin/bash
84
+ agent-browser profiler start
85
+ agent-browser navigate https://app.example.com
86
+ agent-browser wait --load load
87
+ agent-browser profiler stop "./profiles/build-${BUILD_ID}.json"
88
+ ```
89
+
90
+ ## Output Format
91
+
92
+ The output is a JSON file in Chrome Trace Event format:
93
+
94
+ ```json
95
+ {
96
+ "traceEvents": [
97
+ { "cat": "devtools.timeline", "name": "RunTask", "ph": "X", "ts": 12345, "dur": 100, ... },
98
+ ...
99
+ ],
100
+ "metadata": {
101
+ "clock-domain": "LINUX_CLOCK_MONOTONIC"
102
+ }
103
+ }
104
+ ```
105
+
106
+ The `metadata.clock-domain` field is set based on the host platform (Linux or macOS). On Windows it is omitted.
107
+
108
+ ## Viewing Profiles
109
+
110
+ Load the output JSON file in any of these tools:
111
+
112
+ - **Chrome DevTools**: Performance panel > Load profile (Ctrl+Shift+I > Performance)
113
+ - **Perfetto UI**: https://ui.perfetto.dev/ -- drag and drop the JSON file
114
+ - **Trace Viewer**: `chrome://tracing` in any Chromium browser
115
+
116
+ ## Limitations
117
+
118
+ - Only works with Chromium-based browsers (Chrome, Edge). Not supported on Firefox or WebKit.
119
+ - Trace data accumulates in memory while profiling is active (capped at 5 million events). Stop profiling promptly after the area of interest.
120
+ - Data collection on stop has a 30-second timeout. If the browser is unresponsive, the stop command may fail.
@@ -0,0 +1,221 @@
1
+ # Proxy Support
2
+
3
+ Proxy configuration for geo-testing, rate limiting avoidance, and corporate environments.
4
+
5
+ **Related**: [commands.md](commands.md) for global options, [SKILL.md](../SKILL.md) for quick start.
6
+
7
+ ## Contents
8
+
9
+ - [Basic Proxy Configuration](#basic-proxy-configuration)
10
+ - [Authenticated Proxy](#authenticated-proxy)
11
+ - [SOCKS Proxy](#socks-proxy)
12
+ - [Proxy Bypass](#proxy-bypass)
13
+ - [Common Use Cases](#common-use-cases)
14
+ - [Verifying Proxy Connection](#verifying-proxy-connection)
15
+ - [Troubleshooting](#troubleshooting)
16
+ - [Best Practices](#best-practices)
17
+
18
+ ## Basic Proxy Configuration
19
+
20
+ Use the `--proxy` flag or set proxy via environment variable:
21
+
22
+ ```bash
23
+ # Via CLI flag
24
+ agent-browser --proxy "http://proxy.example.com:8080" open https://example.com
25
+
26
+ # Via environment variable
27
+ export HTTP_PROXY="http://proxy.example.com:8080"
28
+ agent-browser open https://example.com
29
+
30
+ # HTTPS proxy
31
+ export HTTPS_PROXY="https://proxy.example.com:8080"
32
+ agent-browser open https://example.com
33
+
34
+ # Both
35
+ export HTTP_PROXY="http://proxy.example.com:8080"
36
+ export HTTPS_PROXY="http://proxy.example.com:8080"
37
+ agent-browser open https://example.com
38
+ ```
39
+
40
+ When launching Chrome, agent-browser accepts a proxy URL with a trailing slash. The MCP server uses the same environment and config settings; set the proxy there because MCP tools do not accept a proxy argument.
41
+
42
+ ## Authenticated Proxy
43
+
44
+ For proxies requiring authentication:
45
+
46
+ ```bash
47
+ # Include credentials in URL
48
+ export HTTP_PROXY="http://username:password@proxy.example.com:8080"
49
+ agent-browser open https://example.com
50
+ ```
51
+
52
+ Credentials embedded in the URL are percent-decoded once before Chrome answers the proxy's authentication challenge. Encode reserved characters in the username or password, so `p@ss` is written `p%40ss` and a literal percent is written `%25`. A `+` stays a literal `+`. If the decoded bytes are not valid UTF-8, the entire credential is kept as written.
53
+
54
+ ## SOCKS Proxy
55
+
56
+ ```bash
57
+ # SOCKS5 proxy
58
+ export ALL_PROXY="socks5://proxy.example.com:1080"
59
+ agent-browser open https://example.com
60
+
61
+ # SOCKS5 with auth
62
+ export ALL_PROXY="socks5://user:pass@proxy.example.com:1080"
63
+ agent-browser open https://example.com
64
+ ```
65
+
66
+ ## Proxy Bypass
67
+
68
+ Skip proxy for specific domains using `--proxy-bypass` or `NO_PROXY`. The experimental Obscura engine rejects proxy bypass settings, including `proxyBypass` config, `AGENT_BROWSER_PROXY_BYPASS`, `NO_PROXY`, and `no_proxy`, even without a proxy. Use Chrome when bypass rules are required. Explicit `--engine obscura` launches use the current invocation's resolved bypass settings, even with an existing daemon. Removing bypass settings takes effect on the next explicit Obscura launch without restarting the daemon.
69
+
70
+ Chrome example:
71
+
72
+ ```bash
73
+ # Via CLI flag
74
+ agent-browser --proxy "http://proxy.example.com:8080" --proxy-bypass "localhost,*.internal.com" open https://example.com
75
+
76
+ # Via environment variable
77
+ export NO_PROXY="localhost,127.0.0.1,.internal.company.com"
78
+ agent-browser open https://internal.company.com # Direct connection
79
+ agent-browser open https://external.com # Via proxy
80
+ ```
81
+
82
+ ## Common Use Cases
83
+
84
+ ### Geo-Location Testing
85
+
86
+ ```bash
87
+ #!/bin/bash
88
+ # Test site from different regions using geo-located proxies
89
+
90
+ PROXIES=(
91
+ "http://us-proxy.example.com:8080"
92
+ "http://eu-proxy.example.com:8080"
93
+ "http://asia-proxy.example.com:8080"
94
+ )
95
+
96
+ for proxy in "${PROXIES[@]}"; do
97
+ export HTTP_PROXY="$proxy"
98
+ export HTTPS_PROXY="$proxy"
99
+
100
+ region=$(echo "$proxy" | grep -oP '^\w+-\w+')
101
+ echo "Testing from: $region"
102
+
103
+ agent-browser --session "$region" open https://example.com
104
+ agent-browser --session "$region" screenshot "./screenshots/$region.png"
105
+ agent-browser --session "$region" close
106
+ done
107
+ ```
108
+
109
+ ### Rotating Proxies for Scraping
110
+
111
+ ```bash
112
+ #!/bin/bash
113
+ # Rotate through proxy list to avoid rate limiting
114
+
115
+ PROXY_LIST=(
116
+ "http://proxy1.example.com:8080"
117
+ "http://proxy2.example.com:8080"
118
+ "http://proxy3.example.com:8080"
119
+ )
120
+
121
+ URLS=(
122
+ "https://site.com/page1"
123
+ "https://site.com/page2"
124
+ "https://site.com/page3"
125
+ )
126
+
127
+ for i in "${!URLS[@]}"; do
128
+ proxy_index=$((i % ${#PROXY_LIST[@]}))
129
+ export HTTP_PROXY="${PROXY_LIST[$proxy_index]}"
130
+ export HTTPS_PROXY="${PROXY_LIST[$proxy_index]}"
131
+
132
+ agent-browser open "${URLS[$i]}"
133
+ agent-browser get text body > "output-$i.txt"
134
+ agent-browser close
135
+
136
+ sleep 1 # Polite delay
137
+ done
138
+ ```
139
+
140
+ ### Corporate Network Access
141
+
142
+ ```bash
143
+ #!/bin/bash
144
+ # Access internal sites via corporate proxy
145
+
146
+ export HTTP_PROXY="http://corpproxy.company.com:8080"
147
+ export HTTPS_PROXY="http://corpproxy.company.com:8080"
148
+ export NO_PROXY="localhost,127.0.0.1,.company.com"
149
+
150
+ # External sites go through proxy
151
+ agent-browser open https://external-vendor.com
152
+
153
+ # Internal sites bypass proxy
154
+ agent-browser open https://intranet.company.com
155
+ ```
156
+
157
+ ## Verifying Proxy Connection
158
+
159
+ ```bash
160
+ # Check your apparent IP
161
+ agent-browser open https://httpbin.org/ip
162
+ agent-browser get text body
163
+ # Should show proxy's IP, not your real IP
164
+ ```
165
+
166
+ ## Troubleshooting
167
+
168
+ ### Proxy Connection Failed
169
+
170
+ ```bash
171
+ # Test proxy connectivity first
172
+ curl -x http://proxy.example.com:8080 https://httpbin.org/ip
173
+
174
+ # Check if proxy requires auth
175
+ export HTTP_PROXY="http://user:pass@proxy.example.com:8080"
176
+ ```
177
+
178
+ ### SSL/TLS Errors Through Proxy
179
+
180
+ Some proxies perform SSL inspection with a custom CA certificate. Trust only that CA:
181
+
182
+ ```bash
183
+ # Recommended: trust the proxy's CA certificate
184
+ agent-browser --ca-cert /etc/ssl/certs/proxy-ca.crt open https://example.com
185
+
186
+ # Via environment variable
187
+ export AGENT_BROWSER_CA_CERT=/etc/ssl/certs/proxy-ca.crt
188
+ agent-browser open https://example.com
189
+
190
+ # CLI requests (read, install, upgrade, doctor) on any platform
191
+ agent-browser --ca-cert /etc/ssl/certs/proxy-ca.crt read https://example.com
192
+ agent-browser --use-system-ca install
193
+ ```
194
+
195
+ `read`, `install`, `upgrade`, and `doctor` make their own HTTPS requests and trust the built-in Mozilla roots by default. On every platform, `--ca-cert` adds the CA to those requests, and `--use-system-ca` switches them to the operating system trust store, which already holds a CA deployed by MDM or an enterprise image. `SSL_CERT_FILE` is used as a fallback CA file and is ignored with a warning when unusable. Neither option disables certificate or hostname verification. For `read`, a selection given on the command line stays in effect for the session until `close`, including across daemon restarts; `--no-ca-cert` or `--use-system-ca false` turns it off. `read` never launches or relaunches a browser because of these options. They do not yet change how agent-browser connects to a remote browser over `--cdp`, `--auto-connect`, or a provider.
196
+
197
+ On Linux, `--ca-cert` imports the certificate or PEM bundle into an isolated NSS database used only by that locally launched Chromium process. Certificate hostname, validity period, and unrelated authority verification stay enabled. Later commands retain the CA when they omit the flag. Use `--no-ca-cert` to clear it. Different certificate content or an explicit clear relaunches Chromium without restarting the daemon, while the same content from any path reuses the browser. `agent-browser install --with-deps` installs the required `certutil`; otherwise install `libnss3-tools` on Debian/Ubuntu or `nss-tools` on RPM Linux.
198
+
199
+ Browser trust does not support `--profile`, `--cdp`, `--auto-connect`, providers, Lightpanda, macOS, or Windows. Use `--ignore-https-errors` only when a broad bypass is the intended contract.
200
+
201
+ Without the CA certificate on hand, fall back to ignoring every certificate error:
202
+
203
+ ```bash
204
+ # For testing only - not recommended for production
205
+ agent-browser open https://example.com --ignore-https-errors
206
+ ```
207
+
208
+ ### Slow Performance
209
+
210
+ ```bash
211
+ # Use proxy only when necessary
212
+ export NO_PROXY="*.cdn.com,*.static.com" # Direct CDN access
213
+ ```
214
+
215
+ ## Best Practices
216
+
217
+ 1. **Use environment variables** - Don't hardcode proxy credentials
218
+ 2. **Set NO_PROXY appropriately** - Avoid routing local traffic through proxy
219
+ 3. **Test proxy before automation** - Verify connectivity with simple requests
220
+ 4. **Handle proxy failures gracefully** - Implement retry logic for unstable proxies
221
+ 5. **Rotate proxies for large scraping jobs** - Distribute load and avoid bans
@@ -0,0 +1,215 @@
1
+ # Session Management
2
+
3
+ Multiple isolated browser sessions with state persistence and concurrent browsing.
4
+
5
+ **Related**: [authentication.md](authentication.md) for login patterns, [SKILL.md](../SKILL.md) for quick start.
6
+
7
+ ## Contents
8
+
9
+ - [Named Sessions](#named-sessions)
10
+ - [Session Isolation Properties](#session-isolation-properties)
11
+ - [Tab Pinning in a Shared Browser](#tab-pinning-in-a-shared-browser)
12
+ - [Changing settings on a running session](#changing-settings-on-a-running-session)
13
+ - [Session State Persistence](#session-state-persistence)
14
+ - [Common Patterns](#common-patterns)
15
+ - [Default Session](#default-session)
16
+ - [Session Cleanup](#session-cleanup)
17
+ - [Best Practices](#best-practices)
18
+
19
+ ## Named Sessions
20
+
21
+ Use `--session` to isolate browser contexts. Agent skills should derive one stable id and reuse it on every command:
22
+
23
+ ```bash
24
+ SESSION="$(agent-browser session id --scope worktree --prefix my-skill)"
25
+ agent-browser --session "$SESSION" --restore open https://app.example.com/login
26
+ ```
27
+
28
+ `--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.
29
+
30
+ Session names accept Unicode letters and numbers, hyphens, and underscores only. For example, `café-東京_7` is valid, while `my session` is rejected because it contains a space.
31
+
32
+ ```bash
33
+ # Session 1: Authentication flow
34
+ agent-browser --session auth open https://app.example.com/login
35
+
36
+ # Session 2: Public browsing (separate cookies, storage)
37
+ agent-browser --session public open https://example.com
38
+
39
+ # Commands are isolated by session
40
+ agent-browser --session auth fill @e1 "user@example.com"
41
+ agent-browser --session public get text body
42
+ ```
43
+
44
+ ## Session Isolation Properties
45
+
46
+ Each session has independent:
47
+ - Cookies
48
+ - LocalStorage / SessionStorage
49
+ - IndexedDB
50
+ - Cache
51
+ - Browsing history
52
+ - Open tabs
53
+
54
+ ## Tab Pinning in a Shared Browser
55
+
56
+ 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:
57
+
58
+ ```bash
59
+ agent-browser --session agent1 --cdp 9222 --pin-tab open https://site-a.com
60
+ agent-browser --session agent2 --cdp 9222 --pin-tab open https://site-b.com
61
+ ```
62
+
63
+ 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:
64
+
65
+ - Attaching with no binding opens a fresh tab instead of adopting an existing one
66
+ - 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`
67
+ - 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
68
+ - Tabs opened by other sessions or the user never steal the pinned session's active tab
69
+ - Another session cannot take a pinned tab with `tab <ref>` while the pinning session is running; the switch fails with `tab_locked` naming the owner
70
+
71
+ The flag is sticky per session: pass it once at session creation and later commands keep the strict semantics. Daemon restarts keep the pin; an explicit `close` releases it so other sessions can take the tab, and the next `--pin-tab` command pins again. 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.
72
+
73
+ 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`.
74
+
75
+ 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`.
76
+
77
+ ## Changing settings on a running session
78
+
79
+ Each command carries the settings you set for it (flag, environment variable, or config). The daemon compares them with the running session. A setting you omit keeps its running value, and a setting equal to the running one does nothing, so repeating `--profile ./work` on every command never relaunches the browser. Timeouts, `--action-policy`, `--confirm-actions`, `--no-auto-dialog`, and restore and pin settings apply in place. A relaunched browser that agent-browser launches itself gets runtime settings (`set viewport`, `set device` with touch, user agent, media, timezone, locale, geolocation, headers, offline, init scripts) applied again; a launch setting changed in the same relaunch replaces only its own runtime value, `--window-size`, `--start-maximized` or `--start-fullscreen` added or changed by the relaunch drop the remembered viewport, and `close`, `--cdp`, `--auto-connect` and provider sessions start without them. Launch settings (`--profile`, `--args`, `--headed`, `--proxy`, `--state`, `--allowed-domains`, and similar) relaunch the browser without restarting the daemon. Each change that takes effect prints one line on stderr, for example `⚠ profile: ./a → ./b (--profile), relaunched browser`. Every change appears in `lifecycle.settings.changes` with `--json`, as `applied: true` or `applied: false` (a launch setting changed while no browser is running waits for the next launch). Commands that never launch (`get cdp-url`, `session info`) apply live settings only, and `get cdp-url` sends no launch settings. Settings that only describe a browser agent-browser launches itself (`--profile`, `--args`, `--executable-path`, `--extension`, `--proxy`, `--user-agent`, `--state`) are ignored for `--cdp`, `--auto-connect` and provider sessions and show as `effect: "ignored"`. Inherited `--state`, `--profile`, `--extension`, `--proxy` (and credentials), `--executable-path` and `--args` values are dropped when the session switches to an external browser, an empty `--provider` resets a provider session to a local launch, and `--no-auto-connect` resets an `--auto-connect` session. Secrets are redacted: passwords and CDP headers are hidden, and CDP URLs lose their credentials and query string. A launch setting is kept only after the launch succeeds, except `--allowed-domains`, which stays installed. A command denied by policy or waiting for confirmation changes no launch setting. Setting `--state` replaces an inherited `--profile` or `--extension`, and the reverse. The first command of a session still seeds from the environment the daemon was spawned with, except the connection target, which is kept only after an attach succeeds. `--state <path>` loads the file at launch only; pass `--relaunch` to relaunch the browser and load it again.
80
+
81
+ A connection target from the environment or config (`AGENT_BROWSER_CDP`, `AGENT_BROWSER_PROVIDER`, `AGENT_BROWSER_AUTO_CONNECT`, or config `cdp`, `provider`, `autoConnect`) is a session default. It applies only to a session that has no target yet, so it never replaces a browser the session is attached to, for example one attached with `connect <port|url>`. The same target on the command line (`--cdp`, `--provider`, `--auto-connect`) is explicit and replaces the session target. `--no-auto-connect` and an empty `--provider` reset the session to a local launch; a default target from the environment or config then applies to it. When the environment or config names more than one target, the first of cdp, auto-connect, provider applies. `--cdp-headers` values are credentials of an endpoint, not a target, and go only to the endpoint they were given for. Headers from `AGENT_BROWSER_CDP_HEADERS` or config belong to the endpoint the environment or config names (`AGENT_BROWSER_CDP`, `cdp`): they go with that endpoint when it applies or is the session's, and never to a different one named by `--cdp` or `connect <port|url>`; with no endpoint named there, they go with whichever the command names. Headers on the command line go with the endpoint the same command names, and alone they update the headers of the endpoint the session is attached to. If the endpoint a command names is skipped because the session stays attached to another, its headers are dropped, never sent to the attached endpoint. A changed value reconnects the same endpoint.
82
+
83
+ Security settings (`--allowed-domains`, `--action-policy`, `--confirm-actions`) are stored in an owner-only `<session>.settings` file in the socket directory before they take effect, so they survive a daemon restart (idle expiry, crash, kill, upgrade). The file wins over the environment when the daemon starts, a new value replaces it, an empty `--allowed-domains` is an error (`--relaunch` keeps the filter; only `close` removes it), and a successful `close` (or `close --all`, which also closes sessions whose daemon is gone, under their stored policy) removes the file. A relative `--action-policy` path is stored absolute. A denied or confirmation-pending `close`, and CLI-triggered daemon restarts, keep the file. A file that cannot be read or parsed, or is readable by other users on Unix, stops the daemon from starting and names the file; `agent-browser --session <name> close` clears it.
84
+
85
+ ## Session State Persistence
86
+
87
+ ### Automatic Restore
88
+
89
+ ```bash
90
+ # Bare --restore uses the current --session as the persistence key
91
+ SESSION="$(agent-browser session id --scope worktree --prefix next-dev-loop)"
92
+ agent-browser --session "$SESSION" --restore open https://app.example.com/dashboard
93
+ ```
94
+
95
+ When `--restore` or another restore key is configured, state is loaded before navigation and saved on close, daemon shutdown, idle timeout, and compatible relaunch. It is also saved periodically while the browser is open (after commands settle, at most once per `AGENT_BROWSER_AUTOSAVE_INTERVAL_MS`, default 30000; set to `0` to save only on close), so a browser window the user closes by hand still leaves a recent save behind. A session ID by itself only isolates the daemon and does not enable persistence; without a restore key, shutdown discards transient browser state and open tabs. Idle sessions with configured persistence keep saving on the same interval, capturing changes the page makes on its own such as token refreshes. The daemon exits after one hour without commands or dashboard input by default; `--idle-timeout <time>` or `AGENT_BROWSER_IDLE_TIMEOUT_MS` tunes this, and `0` disables it. Values too large to convert to milliseconds produce a warning and are ignored. Headed, Safari/iOS WebDriver, and user-attached browsers are exempt from the default timeout; provider-owned cloud browsers are not. The default save policy is `--restore-save auto`, which skips auto-save if restore failed or validation failed; `never` disables periodic autosave too.
96
+
97
+ ```bash
98
+ agent-browser --session "$SESSION" --restore --restore-check-url "**/dashboard" open https://app.example.com/dashboard
99
+ agent-browser --session "$SESSION" --restore --restore-check-text Dashboard open https://app.example.com/dashboard
100
+ agent-browser --session "$SESSION" --restore --restore-check-fn "!!localStorage.getItem('session')" open https://app.example.com/dashboard
101
+ ```
102
+
103
+ Use `agent-browser session info --json` for diagnostics:
104
+
105
+ ```bash
106
+ agent-browser --session "$SESSION" session info --json
107
+ ```
108
+
109
+ ### Manual State Files
110
+
111
+ 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.
112
+
113
+ ## Common Patterns
114
+
115
+ ### Authenticated Session Reuse
116
+
117
+ ```bash
118
+ #!/bin/bash
119
+ SESSION="$(agent-browser session id --scope worktree --prefix app)"
120
+ agent-browser --session "$SESSION" --restore open https://app.example.com/dashboard
121
+ ```
122
+
123
+ ### Concurrent Scraping
124
+
125
+ ```bash
126
+ #!/bin/bash
127
+ # Scrape multiple sites concurrently
128
+
129
+ # Start all sessions
130
+ agent-browser --session site1 open https://site1.com &
131
+ agent-browser --session site2 open https://site2.com &
132
+ agent-browser --session site3 open https://site3.com &
133
+ wait
134
+
135
+ # Extract from each
136
+ agent-browser --session site1 get text body > site1.txt
137
+ agent-browser --session site2 get text body > site2.txt
138
+ agent-browser --session site3 get text body > site3.txt
139
+
140
+ # Cleanup
141
+ agent-browser --session site1 close
142
+ agent-browser --session site2 close
143
+ agent-browser --session site3 close
144
+ ```
145
+
146
+ ### A/B Testing Sessions
147
+
148
+ ```bash
149
+ # Test different user experiences
150
+ agent-browser --session variant-a open "https://app.com?variant=a"
151
+ agent-browser --session variant-b open "https://app.com?variant=b"
152
+
153
+ # Compare
154
+ agent-browser --session variant-a screenshot /tmp/variant-a.png
155
+ agent-browser --session variant-b screenshot /tmp/variant-b.png
156
+ ```
157
+
158
+ ## Default Session
159
+
160
+ When `--session` is omitted, commands use the default session:
161
+
162
+ ```bash
163
+ # These use the same default session
164
+ agent-browser open https://example.com
165
+ agent-browser snapshot -i
166
+ agent-browser close # Closes default session
167
+ ```
168
+
169
+ ## Session Cleanup
170
+
171
+ ```bash
172
+ # Close specific session
173
+ agent-browser --session auth close
174
+
175
+ # List active sessions
176
+ agent-browser session list
177
+ ```
178
+
179
+ ## Best Practices
180
+
181
+ ### 1. Name Sessions Semantically
182
+
183
+ ```bash
184
+ # GOOD: Clear purpose
185
+ agent-browser --session github-auth open https://github.com
186
+ agent-browser --session docs-scrape open https://docs.example.com
187
+
188
+ # AVOID: Generic names
189
+ agent-browser --session s1 open https://github.com
190
+ ```
191
+
192
+ ### 2. Always Clean Up
193
+
194
+ ```bash
195
+ # Close sessions when done
196
+ agent-browser --session auth close
197
+ agent-browser --session scrape close
198
+ ```
199
+
200
+ ### 3. Handle State Files Securely
201
+
202
+ ```bash
203
+ # Don't commit state files (contain auth tokens!)
204
+ echo "*.auth-state.json" >> .gitignore
205
+
206
+ # Delete after use
207
+ rm /tmp/auth-state.json
208
+ ```
209
+
210
+ ### 4. Timeout Long Sessions
211
+
212
+ ```bash
213
+ # Set timeout for automated scripts
214
+ timeout 60 agent-browser --session long-task get text body
215
+ ```