@kritchoff/agent-browser 0.9.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.
Files changed (88) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +903 -0
  3. package/README.sdk.md +77 -0
  4. package/bin/agent-browser-linux-x64 +0 -0
  5. package/bin/agent-browser.js +109 -0
  6. package/dist/actions.d.ts +17 -0
  7. package/dist/actions.d.ts.map +1 -0
  8. package/dist/actions.js +1427 -0
  9. package/dist/actions.js.map +1 -0
  10. package/dist/browser.d.ts +474 -0
  11. package/dist/browser.d.ts.map +1 -0
  12. package/dist/browser.js +1566 -0
  13. package/dist/browser.js.map +1 -0
  14. package/dist/cdp-client.d.ts +103 -0
  15. package/dist/cdp-client.d.ts.map +1 -0
  16. package/dist/cdp-client.js +223 -0
  17. package/dist/cdp-client.js.map +1 -0
  18. package/dist/daemon.d.ts +60 -0
  19. package/dist/daemon.d.ts.map +1 -0
  20. package/dist/daemon.js +401 -0
  21. package/dist/daemon.js.map +1 -0
  22. package/dist/dualmode-config.d.ts +37 -0
  23. package/dist/dualmode-config.d.ts.map +1 -0
  24. package/dist/dualmode-config.js +44 -0
  25. package/dist/dualmode-config.js.map +1 -0
  26. package/dist/dualmode-fetcher.d.ts +60 -0
  27. package/dist/dualmode-fetcher.d.ts.map +1 -0
  28. package/dist/dualmode-fetcher.js +449 -0
  29. package/dist/dualmode-fetcher.js.map +1 -0
  30. package/dist/dualmode-types.d.ts +183 -0
  31. package/dist/dualmode-types.d.ts.map +1 -0
  32. package/dist/dualmode-types.js +8 -0
  33. package/dist/dualmode-types.js.map +1 -0
  34. package/dist/ios-actions.d.ts +11 -0
  35. package/dist/ios-actions.d.ts.map +1 -0
  36. package/dist/ios-actions.js +228 -0
  37. package/dist/ios-actions.js.map +1 -0
  38. package/dist/ios-manager.d.ts +266 -0
  39. package/dist/ios-manager.d.ts.map +1 -0
  40. package/dist/ios-manager.js +1073 -0
  41. package/dist/ios-manager.js.map +1 -0
  42. package/dist/protocol.d.ts +26 -0
  43. package/dist/protocol.d.ts.map +1 -0
  44. package/dist/protocol.js +832 -0
  45. package/dist/protocol.js.map +1 -0
  46. package/dist/snapshot.d.ts +83 -0
  47. package/dist/snapshot.d.ts.map +1 -0
  48. package/dist/snapshot.js +653 -0
  49. package/dist/snapshot.js.map +1 -0
  50. package/dist/stream-server.d.ts +117 -0
  51. package/dist/stream-server.d.ts.map +1 -0
  52. package/dist/stream-server.js +305 -0
  53. package/dist/stream-server.js.map +1 -0
  54. package/dist/types.d.ts +742 -0
  55. package/dist/types.d.ts.map +1 -0
  56. package/dist/types.js +2 -0
  57. package/dist/types.js.map +1 -0
  58. package/docker-compose.sdk.yml +45 -0
  59. package/package.json +85 -0
  60. package/scripts/benchmark.sh +80 -0
  61. package/scripts/build-all-platforms.sh +68 -0
  62. package/scripts/check-version-sync.js +39 -0
  63. package/scripts/copy-native.js +36 -0
  64. package/scripts/fast_reset.sh +108 -0
  65. package/scripts/postinstall.js +235 -0
  66. package/scripts/publish_images.sh +55 -0
  67. package/scripts/snapshot_manager.sh +293 -0
  68. package/scripts/start-android-agent.sh +49 -0
  69. package/scripts/sync-version.js +69 -0
  70. package/scripts/vaccine-run +26 -0
  71. package/sdk.sh +153 -0
  72. package/skills/agent-browser/SKILL.md +217 -0
  73. package/skills/agent-browser/references/authentication.md +202 -0
  74. package/skills/agent-browser/references/commands.md +259 -0
  75. package/skills/agent-browser/references/proxy-support.md +188 -0
  76. package/skills/agent-browser/references/session-management.md +193 -0
  77. package/skills/agent-browser/references/snapshot-refs.md +194 -0
  78. package/skills/agent-browser/references/video-recording.md +173 -0
  79. package/skills/agent-browser/templates/authenticated-session.sh +97 -0
  80. package/skills/agent-browser/templates/capture-workflow.sh +69 -0
  81. package/skills/agent-browser/templates/form-automation.sh +62 -0
  82. package/skills/skill-creator/LICENSE.txt +202 -0
  83. package/skills/skill-creator/SKILL.md +356 -0
  84. package/skills/skill-creator/references/output-patterns.md +82 -0
  85. package/skills/skill-creator/references/workflows.md +28 -0
  86. package/skills/skill-creator/scripts/init_skill.py +303 -0
  87. package/skills/skill-creator/scripts/package_skill.py +113 -0
  88. package/skills/skill-creator/scripts/quick_validate.py +95 -0
@@ -0,0 +1,259 @@
1
+ # Command Reference
2
+
3
+ Complete reference for all agent-browser commands. For quick start and common patterns, see SKILL.md.
4
+
5
+ ## Navigation
6
+
7
+ ```bash
8
+ agent-browser open <url> # Navigate to URL (aliases: goto, navigate)
9
+ # Supports: https://, http://, file://, about:, data://
10
+ # Auto-prepends https:// if no protocol given
11
+ agent-browser back # Go back
12
+ agent-browser forward # Go forward
13
+ agent-browser reload # Reload page
14
+ agent-browser close # Close browser (aliases: quit, exit)
15
+ agent-browser connect 9222 # Connect to browser via CDP port
16
+ ```
17
+
18
+ ## Snapshot (page analysis)
19
+
20
+ ```bash
21
+ agent-browser snapshot # Full accessibility tree
22
+ agent-browser snapshot -i # Interactive elements only (recommended)
23
+ agent-browser snapshot -c # Compact output
24
+ agent-browser snapshot -d 3 # Limit depth to 3
25
+ agent-browser snapshot -s "#main" # Scope to CSS selector
26
+ ```
27
+
28
+ ## Interactions (use @refs from snapshot)
29
+
30
+ ```bash
31
+ agent-browser click @e1 # Click
32
+ agent-browser dblclick @e1 # Double-click
33
+ agent-browser focus @e1 # Focus element
34
+ agent-browser fill @e2 "text" # Clear and type
35
+ agent-browser type @e2 "text" # Type without clearing
36
+ agent-browser press Enter # Press key (alias: key)
37
+ agent-browser press Control+a # Key combination
38
+ agent-browser keydown Shift # Hold key down
39
+ agent-browser keyup Shift # Release key
40
+ agent-browser hover @e1 # Hover
41
+ agent-browser check @e1 # Check checkbox
42
+ agent-browser uncheck @e1 # Uncheck checkbox
43
+ agent-browser select @e1 "value" # Select dropdown option
44
+ agent-browser select @e1 "a" "b" # Select multiple options
45
+ agent-browser scroll down 500 # Scroll page (default: down 300px)
46
+ agent-browser scrollintoview @e1 # Scroll element into view (alias: scrollinto)
47
+ agent-browser drag @e1 @e2 # Drag and drop
48
+ agent-browser upload @e1 file.pdf # Upload files
49
+ ```
50
+
51
+ ## Get Information
52
+
53
+ ```bash
54
+ agent-browser get text @e1 # Get element text
55
+ agent-browser get html @e1 # Get innerHTML
56
+ agent-browser get value @e1 # Get input value
57
+ agent-browser get attr @e1 href # Get attribute
58
+ agent-browser get title # Get page title
59
+ agent-browser get url # Get current URL
60
+ agent-browser get count ".item" # Count matching elements
61
+ agent-browser get box @e1 # Get bounding box
62
+ agent-browser get styles @e1 # Get computed styles (font, color, bg, etc.)
63
+ ```
64
+
65
+ ## Check State
66
+
67
+ ```bash
68
+ agent-browser is visible @e1 # Check if visible
69
+ agent-browser is enabled @e1 # Check if enabled
70
+ agent-browser is checked @e1 # Check if checked
71
+ ```
72
+
73
+ ## Screenshots and PDF
74
+
75
+ ```bash
76
+ agent-browser screenshot # Save to temporary directory
77
+ agent-browser screenshot path.png # Save to specific path
78
+ agent-browser screenshot --full # Full page
79
+ agent-browser pdf output.pdf # Save as PDF
80
+ ```
81
+
82
+ ## Video Recording
83
+
84
+ ```bash
85
+ agent-browser record start ./demo.webm # Start recording
86
+ agent-browser click @e1 # Perform actions
87
+ agent-browser record stop # Stop and save video
88
+ agent-browser record restart ./take2.webm # Stop current + start new
89
+ ```
90
+
91
+ ## Wait
92
+
93
+ ```bash
94
+ agent-browser wait @e1 # Wait for element
95
+ agent-browser wait 2000 # Wait milliseconds
96
+ agent-browser wait --text "Success" # Wait for text (or -t)
97
+ agent-browser wait --url "**/dashboard" # Wait for URL pattern (or -u)
98
+ agent-browser wait --load networkidle # Wait for network idle (or -l)
99
+ agent-browser wait --fn "window.ready" # Wait for JS condition (or -f)
100
+ ```
101
+
102
+ ## Mouse Control
103
+
104
+ ```bash
105
+ agent-browser mouse move 100 200 # Move mouse
106
+ agent-browser mouse down left # Press button
107
+ agent-browser mouse up left # Release button
108
+ agent-browser mouse wheel 100 # Scroll wheel
109
+ ```
110
+
111
+ ## Semantic Locators (alternative to refs)
112
+
113
+ ```bash
114
+ agent-browser find role button click --name "Submit"
115
+ agent-browser find text "Sign In" click
116
+ agent-browser find text "Sign In" click --exact # Exact match only
117
+ agent-browser find label "Email" fill "user@test.com"
118
+ agent-browser find placeholder "Search" type "query"
119
+ agent-browser find alt "Logo" click
120
+ agent-browser find title "Close" click
121
+ agent-browser find testid "submit-btn" click
122
+ agent-browser find first ".item" click
123
+ agent-browser find last ".item" click
124
+ agent-browser find nth 2 "a" hover
125
+ ```
126
+
127
+ ## Browser Settings
128
+
129
+ ```bash
130
+ agent-browser set viewport 1920 1080 # Set viewport size
131
+ agent-browser set device "iPhone 14" # Emulate device
132
+ agent-browser set geo 37.7749 -122.4194 # Set geolocation (alias: geolocation)
133
+ agent-browser set offline on # Toggle offline mode
134
+ agent-browser set headers '{"X-Key":"v"}' # Extra HTTP headers
135
+ agent-browser set credentials user pass # HTTP basic auth (alias: auth)
136
+ agent-browser set media dark # Emulate color scheme
137
+ agent-browser set media light reduced-motion # Light mode + reduced motion
138
+ ```
139
+
140
+ ## Cookies and Storage
141
+
142
+ ```bash
143
+ agent-browser cookies # Get all cookies
144
+ agent-browser cookies set name value # Set cookie
145
+ agent-browser cookies clear # Clear cookies
146
+ agent-browser storage local # Get all localStorage
147
+ agent-browser storage local key # Get specific key
148
+ agent-browser storage local set k v # Set value
149
+ agent-browser storage local clear # Clear all
150
+ ```
151
+
152
+ ## Network
153
+
154
+ ```bash
155
+ agent-browser network route <url> # Intercept requests
156
+ agent-browser network route <url> --abort # Block requests
157
+ agent-browser network route <url> --body '{}' # Mock response
158
+ agent-browser network unroute [url] # Remove routes
159
+ agent-browser network requests # View tracked requests
160
+ agent-browser network requests --filter api # Filter requests
161
+ ```
162
+
163
+ ## Tabs and Windows
164
+
165
+ ```bash
166
+ agent-browser tab # List tabs
167
+ agent-browser tab new [url] # New tab
168
+ agent-browser tab 2 # Switch to tab by index
169
+ agent-browser tab close # Close current tab
170
+ agent-browser tab close 2 # Close tab by index
171
+ agent-browser window new # New window
172
+ ```
173
+
174
+ ## Frames
175
+
176
+ ```bash
177
+ agent-browser frame "#iframe" # Switch to iframe
178
+ agent-browser frame main # Back to main frame
179
+ ```
180
+
181
+ ## Dialogs
182
+
183
+ ```bash
184
+ agent-browser dialog accept [text] # Accept dialog
185
+ agent-browser dialog dismiss # Dismiss dialog
186
+ ```
187
+
188
+ ## JavaScript
189
+
190
+ ```bash
191
+ agent-browser eval "document.title" # Simple expressions only
192
+ agent-browser eval -b "<base64>" # Any JavaScript (base64 encoded)
193
+ agent-browser eval --stdin # Read script from stdin
194
+ ```
195
+
196
+ Use `-b`/`--base64` or `--stdin` for reliable execution. Shell escaping with nested quotes and special characters is error-prone.
197
+
198
+ ```bash
199
+ # Base64 encode your script, then:
200
+ agent-browser eval -b "ZG9jdW1lbnQucXVlcnlTZWxlY3RvcignW3NyYyo9Il9uZXh0Il0nKQ=="
201
+
202
+ # Or use stdin with heredoc for multiline scripts:
203
+ cat <<'EOF' | agent-browser eval --stdin
204
+ const links = document.querySelectorAll('a');
205
+ Array.from(links).map(a => a.href);
206
+ EOF
207
+ ```
208
+
209
+ ## State Management
210
+
211
+ ```bash
212
+ agent-browser state save auth.json # Save cookies, storage, auth state
213
+ agent-browser state load auth.json # Restore saved state
214
+ ```
215
+
216
+ ## Global Options
217
+
218
+ ```bash
219
+ agent-browser --session <name> ... # Isolated browser session
220
+ agent-browser --json ... # JSON output for parsing
221
+ agent-browser --headed ... # Show browser window (not headless)
222
+ agent-browser --full ... # Full page screenshot (-f)
223
+ agent-browser --cdp <port> ... # Connect via Chrome DevTools Protocol
224
+ agent-browser -p <provider> ... # Cloud browser provider (--provider)
225
+ agent-browser --proxy <url> ... # Use proxy server
226
+ agent-browser --headers <json> ... # HTTP headers scoped to URL's origin
227
+ agent-browser --executable-path <p> # Custom browser executable
228
+ agent-browser --extension <path> ... # Load browser extension (repeatable)
229
+ agent-browser --ignore-https-errors # Ignore SSL certificate errors
230
+ agent-browser --help # Show help (-h)
231
+ agent-browser --version # Show version (-V)
232
+ agent-browser <command> --help # Show detailed help for a command
233
+ ```
234
+
235
+ ## Debugging
236
+
237
+ ```bash
238
+ agent-browser --headed open example.com # Show browser window
239
+ agent-browser --cdp 9222 snapshot # Connect via CDP port
240
+ agent-browser connect 9222 # Alternative: connect command
241
+ agent-browser console # View console messages
242
+ agent-browser console --clear # Clear console
243
+ agent-browser errors # View page errors
244
+ agent-browser errors --clear # Clear errors
245
+ agent-browser highlight @e1 # Highlight element
246
+ agent-browser trace start # Start recording trace
247
+ agent-browser trace stop trace.zip # Stop and save trace
248
+ ```
249
+
250
+ ## Environment Variables
251
+
252
+ ```bash
253
+ AGENT_BROWSER_SESSION="mysession" # Default session name
254
+ AGENT_BROWSER_EXECUTABLE_PATH="/path/chrome" # Custom browser path
255
+ AGENT_BROWSER_EXTENSIONS="/ext1,/ext2" # Comma-separated extension paths
256
+ AGENT_BROWSER_PROVIDER="browserbase" # Cloud browser provider
257
+ AGENT_BROWSER_STREAM_PORT="9223" # WebSocket streaming port
258
+ AGENT_BROWSER_HOME="/path/to/agent-browser" # Custom install location
259
+ ```
@@ -0,0 +1,188 @@
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
+ Set proxy via environment variable before starting:
21
+
22
+ ```bash
23
+ # HTTP proxy
24
+ export HTTP_PROXY="http://proxy.example.com:8080"
25
+ agent-browser open https://example.com
26
+
27
+ # HTTPS proxy
28
+ export HTTPS_PROXY="https://proxy.example.com:8080"
29
+ agent-browser open https://example.com
30
+
31
+ # Both
32
+ export HTTP_PROXY="http://proxy.example.com:8080"
33
+ export HTTPS_PROXY="http://proxy.example.com:8080"
34
+ agent-browser open https://example.com
35
+ ```
36
+
37
+ ## Authenticated Proxy
38
+
39
+ For proxies requiring authentication:
40
+
41
+ ```bash
42
+ # Include credentials in URL
43
+ export HTTP_PROXY="http://username:password@proxy.example.com:8080"
44
+ agent-browser open https://example.com
45
+ ```
46
+
47
+ ## SOCKS Proxy
48
+
49
+ ```bash
50
+ # SOCKS5 proxy
51
+ export ALL_PROXY="socks5://proxy.example.com:1080"
52
+ agent-browser open https://example.com
53
+
54
+ # SOCKS5 with auth
55
+ export ALL_PROXY="socks5://user:pass@proxy.example.com:1080"
56
+ agent-browser open https://example.com
57
+ ```
58
+
59
+ ## Proxy Bypass
60
+
61
+ Skip proxy for specific domains:
62
+
63
+ ```bash
64
+ # Bypass proxy for local addresses
65
+ export NO_PROXY="localhost,127.0.0.1,.internal.company.com"
66
+ agent-browser open https://internal.company.com # Direct connection
67
+ agent-browser open https://external.com # Via proxy
68
+ ```
69
+
70
+ ## Common Use Cases
71
+
72
+ ### Geo-Location Testing
73
+
74
+ ```bash
75
+ #!/bin/bash
76
+ # Test site from different regions using geo-located proxies
77
+
78
+ PROXIES=(
79
+ "http://us-proxy.example.com:8080"
80
+ "http://eu-proxy.example.com:8080"
81
+ "http://asia-proxy.example.com:8080"
82
+ )
83
+
84
+ for proxy in "${PROXIES[@]}"; do
85
+ export HTTP_PROXY="$proxy"
86
+ export HTTPS_PROXY="$proxy"
87
+
88
+ region=$(echo "$proxy" | grep -oP '^\w+-\w+')
89
+ echo "Testing from: $region"
90
+
91
+ agent-browser --session "$region" open https://example.com
92
+ agent-browser --session "$region" screenshot "./screenshots/$region.png"
93
+ agent-browser --session "$region" close
94
+ done
95
+ ```
96
+
97
+ ### Rotating Proxies for Scraping
98
+
99
+ ```bash
100
+ #!/bin/bash
101
+ # Rotate through proxy list to avoid rate limiting
102
+
103
+ PROXY_LIST=(
104
+ "http://proxy1.example.com:8080"
105
+ "http://proxy2.example.com:8080"
106
+ "http://proxy3.example.com:8080"
107
+ )
108
+
109
+ URLS=(
110
+ "https://site.com/page1"
111
+ "https://site.com/page2"
112
+ "https://site.com/page3"
113
+ )
114
+
115
+ for i in "${!URLS[@]}"; do
116
+ proxy_index=$((i % ${#PROXY_LIST[@]}))
117
+ export HTTP_PROXY="${PROXY_LIST[$proxy_index]}"
118
+ export HTTPS_PROXY="${PROXY_LIST[$proxy_index]}"
119
+
120
+ agent-browser open "${URLS[$i]}"
121
+ agent-browser get text body > "output-$i.txt"
122
+ agent-browser close
123
+
124
+ sleep 1 # Polite delay
125
+ done
126
+ ```
127
+
128
+ ### Corporate Network Access
129
+
130
+ ```bash
131
+ #!/bin/bash
132
+ # Access internal sites via corporate proxy
133
+
134
+ export HTTP_PROXY="http://corpproxy.company.com:8080"
135
+ export HTTPS_PROXY="http://corpproxy.company.com:8080"
136
+ export NO_PROXY="localhost,127.0.0.1,.company.com"
137
+
138
+ # External sites go through proxy
139
+ agent-browser open https://external-vendor.com
140
+
141
+ # Internal sites bypass proxy
142
+ agent-browser open https://intranet.company.com
143
+ ```
144
+
145
+ ## Verifying Proxy Connection
146
+
147
+ ```bash
148
+ # Check your apparent IP
149
+ agent-browser open https://httpbin.org/ip
150
+ agent-browser get text body
151
+ # Should show proxy's IP, not your real IP
152
+ ```
153
+
154
+ ## Troubleshooting
155
+
156
+ ### Proxy Connection Failed
157
+
158
+ ```bash
159
+ # Test proxy connectivity first
160
+ curl -x http://proxy.example.com:8080 https://httpbin.org/ip
161
+
162
+ # Check if proxy requires auth
163
+ export HTTP_PROXY="http://user:pass@proxy.example.com:8080"
164
+ ```
165
+
166
+ ### SSL/TLS Errors Through Proxy
167
+
168
+ Some proxies perform SSL inspection. If you encounter certificate errors:
169
+
170
+ ```bash
171
+ # For testing only - not recommended for production
172
+ agent-browser open https://example.com --ignore-https-errors
173
+ ```
174
+
175
+ ### Slow Performance
176
+
177
+ ```bash
178
+ # Use proxy only when necessary
179
+ export NO_PROXY="*.cdn.com,*.static.com" # Direct CDN access
180
+ ```
181
+
182
+ ## Best Practices
183
+
184
+ 1. **Use environment variables** - Don't hardcode proxy credentials
185
+ 2. **Set NO_PROXY appropriately** - Avoid routing local traffic through proxy
186
+ 3. **Test proxy before automation** - Verify connectivity with simple requests
187
+ 4. **Handle proxy failures gracefully** - Implement retry logic for unstable proxies
188
+ 5. **Rotate proxies for large scraping jobs** - Distribute load and avoid bans
@@ -0,0 +1,193 @@
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
+ - [Session State Persistence](#session-state-persistence)
12
+ - [Common Patterns](#common-patterns)
13
+ - [Default Session](#default-session)
14
+ - [Session Cleanup](#session-cleanup)
15
+ - [Best Practices](#best-practices)
16
+
17
+ ## Named Sessions
18
+
19
+ Use `--session` flag to isolate browser contexts:
20
+
21
+ ```bash
22
+ # Session 1: Authentication flow
23
+ agent-browser --session auth open https://app.example.com/login
24
+
25
+ # Session 2: Public browsing (separate cookies, storage)
26
+ agent-browser --session public open https://example.com
27
+
28
+ # Commands are isolated by session
29
+ agent-browser --session auth fill @e1 "user@example.com"
30
+ agent-browser --session public get text body
31
+ ```
32
+
33
+ ## Session Isolation Properties
34
+
35
+ Each session has independent:
36
+ - Cookies
37
+ - LocalStorage / SessionStorage
38
+ - IndexedDB
39
+ - Cache
40
+ - Browsing history
41
+ - Open tabs
42
+
43
+ ## Session State Persistence
44
+
45
+ ### Save Session State
46
+
47
+ ```bash
48
+ # Save cookies, storage, and auth state
49
+ agent-browser state save /path/to/auth-state.json
50
+ ```
51
+
52
+ ### Load Session State
53
+
54
+ ```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
60
+ ```
61
+
62
+ ### State File Contents
63
+
64
+ ```json
65
+ {
66
+ "cookies": [...],
67
+ "localStorage": {...},
68
+ "sessionStorage": {...},
69
+ "origins": [...]
70
+ }
71
+ ```
72
+
73
+ ## Common Patterns
74
+
75
+ ### Authenticated Session Reuse
76
+
77
+ ```bash
78
+ #!/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
99
+ ```
100
+
101
+ ### Concurrent Scraping
102
+
103
+ ```bash
104
+ #!/bin/bash
105
+ # Scrape multiple sites concurrently
106
+
107
+ # Start all sessions
108
+ agent-browser --session site1 open https://site1.com &
109
+ agent-browser --session site2 open https://site2.com &
110
+ agent-browser --session site3 open https://site3.com &
111
+ wait
112
+
113
+ # Extract from each
114
+ agent-browser --session site1 get text body > site1.txt
115
+ agent-browser --session site2 get text body > site2.txt
116
+ agent-browser --session site3 get text body > site3.txt
117
+
118
+ # Cleanup
119
+ agent-browser --session site1 close
120
+ agent-browser --session site2 close
121
+ agent-browser --session site3 close
122
+ ```
123
+
124
+ ### A/B Testing Sessions
125
+
126
+ ```bash
127
+ # Test different user experiences
128
+ agent-browser --session variant-a open "https://app.com?variant=a"
129
+ agent-browser --session variant-b open "https://app.com?variant=b"
130
+
131
+ # Compare
132
+ agent-browser --session variant-a screenshot /tmp/variant-a.png
133
+ agent-browser --session variant-b screenshot /tmp/variant-b.png
134
+ ```
135
+
136
+ ## Default Session
137
+
138
+ When `--session` is omitted, commands use the default session:
139
+
140
+ ```bash
141
+ # These use the same default session
142
+ agent-browser open https://example.com
143
+ agent-browser snapshot -i
144
+ agent-browser close # Closes default session
145
+ ```
146
+
147
+ ## Session Cleanup
148
+
149
+ ```bash
150
+ # Close specific session
151
+ agent-browser --session auth close
152
+
153
+ # List active sessions
154
+ agent-browser session list
155
+ ```
156
+
157
+ ## Best Practices
158
+
159
+ ### 1. Name Sessions Semantically
160
+
161
+ ```bash
162
+ # GOOD: Clear purpose
163
+ agent-browser --session github-auth open https://github.com
164
+ agent-browser --session docs-scrape open https://docs.example.com
165
+
166
+ # AVOID: Generic names
167
+ agent-browser --session s1 open https://github.com
168
+ ```
169
+
170
+ ### 2. Always Clean Up
171
+
172
+ ```bash
173
+ # Close sessions when done
174
+ agent-browser --session auth close
175
+ agent-browser --session scrape close
176
+ ```
177
+
178
+ ### 3. Handle State Files Securely
179
+
180
+ ```bash
181
+ # Don't commit state files (contain auth tokens!)
182
+ echo "*.auth-state.json" >> .gitignore
183
+
184
+ # Delete after use
185
+ rm /tmp/auth-state.json
186
+ ```
187
+
188
+ ### 4. Timeout Long Sessions
189
+
190
+ ```bash
191
+ # Set timeout for automated scripts
192
+ timeout 60 agent-browser --session long-task get text body
193
+ ```