@docyrus/docyrus 0.0.59 → 0.0.60

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 (44) hide show
  1. package/README.md +46 -0
  2. package/agent-loader.js +1 -1
  3. package/agent-loader.js.map +2 -2
  4. package/main.js +315 -22
  5. package/main.js.map +2 -2
  6. package/package.json +1 -1
  7. package/resources/browser-tools/browser-click.js +74 -0
  8. package/resources/browser-tools/browser-client.js +236 -0
  9. package/resources/browser-tools/browser-close.js +19 -0
  10. package/resources/browser-tools/browser-console.js +73 -0
  11. package/resources/browser-tools/browser-content.js +36 -75
  12. package/resources/browser-tools/browser-cookies.js +19 -14
  13. package/resources/browser-tools/browser-daemon.js +452 -0
  14. package/resources/browser-tools/browser-devtools.js +62 -0
  15. package/resources/browser-tools/browser-eval.js +16 -22
  16. package/resources/browser-tools/browser-fill.js +70 -0
  17. package/resources/browser-tools/browser-info.js +13 -0
  18. package/resources/browser-tools/browser-nav.js +21 -22
  19. package/resources/browser-tools/browser-network.js +91 -0
  20. package/resources/browser-tools/browser-run-script.js +12 -30
  21. package/resources/browser-tools/browser-screenshot.js +22 -22
  22. package/resources/browser-tools/browser-select.js +59 -0
  23. package/resources/browser-tools/browser-snapshot.js +100 -0
  24. package/resources/browser-tools/browser-start.js +101 -85
  25. package/resources/browser-tools/browser-tabs.js +38 -0
  26. package/resources/browser-tools/browser-wait.js +50 -0
  27. package/resources/pi-agent/skills/docyrus-chrome-devtools-cli/SKILL.md +157 -46
  28. package/server-loader.js +17 -229
  29. package/server-loader.js.map +4 -4
  30. package/resources/browser-tools/browser-connect.js +0 -172
  31. package/resources/browser-tools/browser-pick.js +0 -143
  32. package/resources/pi-agent/extensions/docyrus-web-browser.ts +0 -31
  33. package/resources/pi-agent/shared/docyrusWebBrowserProtocol.ts +0 -169
  34. package/resources/pi-agent/skills/agent-browser/SKILL.md +0 -779
  35. package/resources/pi-agent/skills/agent-browser/references/authentication.md +0 -303
  36. package/resources/pi-agent/skills/agent-browser/references/commands.md +0 -295
  37. package/resources/pi-agent/skills/agent-browser/references/profiling.md +0 -120
  38. package/resources/pi-agent/skills/agent-browser/references/proxy-support.md +0 -194
  39. package/resources/pi-agent/skills/agent-browser/references/session-management.md +0 -193
  40. package/resources/pi-agent/skills/agent-browser/references/snapshot-refs.md +0 -219
  41. package/resources/pi-agent/skills/agent-browser/references/video-recording.md +0 -173
  42. package/resources/pi-agent/skills/agent-browser/templates/authenticated-session.sh +0 -105
  43. package/resources/pi-agent/skills/agent-browser/templates/capture-workflow.sh +0 -69
  44. package/resources/pi-agent/skills/agent-browser/templates/form-automation.sh +0 -62
@@ -1,779 +0,0 @@
1
- ---
2
- name: agent-browser
3
- description: Browser automation CLI for AI agents. Use when the user needs to interact with websites, including navigating pages, filling forms, clicking buttons, taking screenshots, extracting data, testing web apps, or automating any browser task. Triggers include requests to "open a website", "fill out a form", "click a button", "take a screenshot", "scrape data from a page", "test this web app", "login to a site", "automate browser actions", or any task requiring programmatic web interaction.
4
- allowed-tools: Bash(npx agent-browser:*), Bash(agent-browser:*)
5
- ---
6
-
7
- # Browser Automation with agent-browser
8
-
9
- The CLI uses Chrome/Chromium via CDP directly. Install via `npm i -g agent-browser`, `brew install agent-browser`, or `cargo install agent-browser`. Run `agent-browser install` to download Chrome. Existing Chrome, Brave, Playwright, and Puppeteer installations are detected automatically. Run `agent-browser upgrade` to update to the latest version.
10
-
11
- ## Core Workflow
12
-
13
- Every browser automation follows this pattern:
14
-
15
- 1. **Navigate**: `agent-browser open <url>`
16
- 2. **Snapshot**: `agent-browser snapshot -i` (get element refs like `@e1`, `@e2`)
17
- 3. **Interact**: Use refs to click, fill, select
18
- 4. **Re-snapshot**: After navigation or DOM changes, get fresh refs
19
-
20
- ```bash
21
- agent-browser open https://example.com/form
22
- agent-browser snapshot -i
23
- # Output: @e1 [input type="email"], @e2 [input type="password"], @e3 [button] "Submit"
24
-
25
- agent-browser fill @e1 "user@example.com"
26
- agent-browser fill @e2 "password123"
27
- agent-browser click @e3
28
- agent-browser wait --load networkidle
29
- agent-browser snapshot -i # Check result
30
- ```
31
-
32
- ## Command Chaining
33
-
34
- Commands can be chained with `&&` in a single shell invocation. The browser persists between commands via a background daemon, so chaining is safe and more efficient than separate calls.
35
-
36
- ```bash
37
- # Chain open + wait + snapshot in one call
38
- agent-browser open https://example.com && agent-browser wait --load networkidle && agent-browser snapshot -i
39
-
40
- # Chain multiple interactions
41
- agent-browser fill @e1 "user@example.com" && agent-browser fill @e2 "password123" && agent-browser click @e3
42
-
43
- # Navigate and capture
44
- agent-browser open https://example.com && agent-browser wait --load networkidle && agent-browser screenshot page.png
45
- ```
46
-
47
- **When to chain:** Use `&&` when you don't need to read the output of an intermediate command before proceeding (e.g., open + wait + screenshot). Run commands separately when you need to parse the output first (e.g., snapshot to discover refs, then interact using those refs).
48
-
49
- ## Handling Authentication
50
-
51
- When automating a site that requires login, choose the approach that fits:
52
-
53
- **Option 1: Import auth from the user's browser (fastest for one-off tasks)**
54
-
55
- ```bash
56
- # Connect to the user's running Chrome (they're already logged in)
57
- agent-browser --auto-connect state save ./auth.json
58
- # Use that auth state
59
- agent-browser --state ./auth.json open https://app.example.com/dashboard
60
- ```
61
-
62
- State files contain session tokens in plaintext -- add to `.gitignore` and delete when no longer needed. Set `AGENT_BROWSER_ENCRYPTION_KEY` for encryption at rest.
63
-
64
- **Option 2: Chrome profile reuse (zero setup)**
65
-
66
- ```bash
67
- # List available Chrome profiles
68
- agent-browser profiles
69
-
70
- # Reuse the user's existing Chrome login state
71
- agent-browser --profile Default open https://gmail.com
72
- ```
73
-
74
- **Option 3: Persistent profile (for recurring tasks)**
75
-
76
- ```bash
77
- # First run: login manually or via automation
78
- agent-browser --profile ~/.myapp open https://app.example.com/login
79
- # ... fill credentials, submit ...
80
-
81
- # All future runs: already authenticated
82
- agent-browser --profile ~/.myapp open https://app.example.com/dashboard
83
- ```
84
-
85
- **Option 4: Session name (auto-save/restore cookies + localStorage)**
86
-
87
- ```bash
88
- agent-browser --session-name myapp open https://app.example.com/login
89
- # ... login flow ...
90
- agent-browser close # State auto-saved
91
-
92
- # Next time: state auto-restored
93
- agent-browser --session-name myapp open https://app.example.com/dashboard
94
- ```
95
-
96
- **Option 4: Auth vault (credentials stored encrypted, login by name)**
97
-
98
- ```bash
99
- echo "$PASSWORD" | agent-browser auth save myapp --url https://app.example.com/login --username user --password-stdin
100
- agent-browser auth login myapp
101
- ```
102
-
103
- `auth login` navigates with `load` and then waits for login form selectors to appear before filling/clicking, which is more reliable on delayed SPA login screens.
104
-
105
- **Option 5: State file (manual save/load)**
106
-
107
- ```bash
108
- # After logging in:
109
- agent-browser state save ./auth.json
110
- # In a future session:
111
- agent-browser state load ./auth.json
112
- agent-browser open https://app.example.com/dashboard
113
- ```
114
-
115
- See [references/authentication.md](references/authentication.md) for OAuth, 2FA, cookie-based auth, and token refresh patterns.
116
-
117
- ## Essential Commands
118
-
119
- ```bash
120
- # Navigation
121
- agent-browser open <url> # Navigate (aliases: goto, navigate)
122
- agent-browser close # Close browser
123
- agent-browser close --all # Close all active sessions
124
-
125
- # Snapshot
126
- agent-browser snapshot -i # Interactive elements with refs (recommended)
127
- agent-browser snapshot -s "#selector" # Scope to CSS selector
128
-
129
- # Interaction (use @refs from snapshot)
130
- agent-browser click @e1 # Click element
131
- agent-browser click @e1 --new-tab # Click and open in new tab
132
- agent-browser fill @e2 "text" # Clear and type text
133
- agent-browser type @e2 "text" # Type without clearing
134
- agent-browser select @e1 "option" # Select dropdown option
135
- agent-browser check @e1 # Check checkbox
136
- agent-browser press Enter # Press key
137
- agent-browser keyboard type "text" # Type at current focus (no selector)
138
- agent-browser keyboard inserttext "text" # Insert without key events
139
- agent-browser scroll down 500 # Scroll page
140
- agent-browser scroll down 500 --selector "div.content" # Scroll within a specific container
141
-
142
- # Get information
143
- agent-browser get text @e1 # Get element text
144
- agent-browser get url # Get current URL
145
- agent-browser get title # Get page title
146
- agent-browser get cdp-url # Get CDP WebSocket URL
147
-
148
- # Wait
149
- agent-browser wait @e1 # Wait for element
150
- agent-browser wait --load networkidle # Wait for network idle
151
- agent-browser wait --url "**/page" # Wait for URL pattern
152
- agent-browser wait 2000 # Wait milliseconds
153
- agent-browser wait --text "Welcome" # Wait for text to appear (substring match)
154
- agent-browser wait --fn "!document.body.innerText.includes('Loading...')" # Wait for text to disappear
155
- agent-browser wait "#spinner" --state hidden # Wait for element to disappear
156
-
157
- # Downloads
158
- agent-browser download @e1 ./file.pdf # Click element to trigger download
159
- agent-browser wait --download ./output.zip # Wait for any download to complete
160
- agent-browser --download-path ./downloads open <url> # Set default download directory
161
-
162
- # Network
163
- agent-browser network requests # Inspect tracked requests
164
- agent-browser network requests --type xhr,fetch # Filter by resource type
165
- agent-browser network requests --method POST # Filter by HTTP method
166
- agent-browser network requests --status 2xx # Filter by status (200, 2xx, 400-499)
167
- agent-browser network request <requestId> # View full request/response detail
168
- agent-browser network route "**/api/*" --abort # Block matching requests
169
- agent-browser network har start # Start HAR recording
170
- agent-browser network har stop ./capture.har # Stop and save HAR file
171
-
172
- # Viewport & Device Emulation
173
- agent-browser set viewport 1920 1080 # Set viewport size (default: 1280x720)
174
- agent-browser set viewport 1920 1080 2 # 2x retina (same CSS size, higher res screenshots)
175
- agent-browser set device "iPhone 14" # Emulate device (viewport + user agent)
176
-
177
- # Capture
178
- agent-browser screenshot # Screenshot to temp dir
179
- agent-browser screenshot --full # Full page screenshot
180
- agent-browser screenshot --annotate # Annotated screenshot with numbered element labels
181
- agent-browser screenshot --screenshot-dir ./shots # Save to custom directory
182
- agent-browser screenshot --screenshot-format jpeg --screenshot-quality 80
183
- agent-browser pdf output.pdf # Save as PDF
184
-
185
- # Live preview / streaming
186
- agent-browser stream enable # Start runtime WebSocket streaming on an auto-selected port
187
- agent-browser stream enable --port 9223 # Bind a specific localhost port
188
- agent-browser stream status # Inspect enabled state, port, connection, and screencasting
189
- agent-browser stream disable # Stop runtime streaming and remove the .stream metadata file
190
-
191
- # Clipboard
192
- agent-browser clipboard read # Read text from clipboard
193
- agent-browser clipboard write "Hello, World!" # Write text to clipboard
194
- agent-browser clipboard copy # Copy current selection
195
- agent-browser clipboard paste # Paste from clipboard
196
-
197
- # Dialogs (alert, confirm, prompt, beforeunload)
198
- # By default, alert and beforeunload dialogs are auto-accepted so they never block the agent.
199
- # confirm and prompt dialogs still require explicit handling.
200
- # Use --no-auto-dialog (or AGENT_BROWSER_NO_AUTO_DIALOG=1) to disable automatic handling.
201
- agent-browser dialog accept # Accept dialog
202
- agent-browser dialog accept "my input" # Accept prompt dialog with text
203
- agent-browser dialog dismiss # Dismiss/cancel dialog
204
- agent-browser dialog status # Check if a dialog is currently open
205
-
206
- # Diff (compare page states)
207
- agent-browser diff snapshot # Compare current vs last snapshot
208
- agent-browser diff snapshot --baseline before.txt # Compare current vs saved file
209
- agent-browser diff screenshot --baseline before.png # Visual pixel diff
210
- agent-browser diff url <url1> <url2> # Compare two pages
211
- agent-browser diff url <url1> <url2> --wait-until networkidle # Custom wait strategy
212
- agent-browser diff url <url1> <url2> --selector "#main" # Scope to element
213
- ```
214
-
215
- ## Streaming
216
-
217
- Every session automatically starts a WebSocket stream server on an OS-assigned port. Use `agent-browser stream status` to see the bound port and connection state. Use `stream disable` to tear it down, and `stream enable --port <port>` to re-enable on a specific port.
218
-
219
- ## Batch Execution
220
-
221
- Execute multiple commands in a single invocation by piping a JSON array of string arrays to `batch`. This avoids per-command process startup overhead when running multi-step workflows.
222
-
223
- ```bash
224
- echo '[
225
- ["open", "https://example.com"],
226
- ["snapshot", "-i"],
227
- ["click", "@e1"],
228
- ["screenshot", "result.png"]
229
- ]' | agent-browser batch --json
230
-
231
- # Stop on first error
232
- agent-browser batch --bail < commands.json
233
- ```
234
-
235
- Use `batch` when you have a known sequence of commands that don't depend on intermediate output. Use separate commands or `&&` chaining when you need to parse output between steps (e.g., snapshot to discover refs, then interact).
236
-
237
- ## Common Patterns
238
-
239
- ### Form Submission
240
-
241
- ```bash
242
- agent-browser open https://example.com/signup
243
- agent-browser snapshot -i
244
- agent-browser fill @e1 "Jane Doe"
245
- agent-browser fill @e2 "jane@example.com"
246
- agent-browser select @e3 "California"
247
- agent-browser check @e4
248
- agent-browser click @e5
249
- agent-browser wait --load networkidle
250
- ```
251
-
252
- ### Authentication with Auth Vault (Recommended)
253
-
254
- ```bash
255
- # Save credentials once (encrypted with AGENT_BROWSER_ENCRYPTION_KEY)
256
- # Recommended: pipe password via stdin to avoid shell history exposure
257
- echo "pass" | agent-browser auth save github --url https://github.com/login --username user --password-stdin
258
-
259
- # Login using saved profile (LLM never sees password)
260
- agent-browser auth login github
261
-
262
- # List/show/delete profiles
263
- agent-browser auth list
264
- agent-browser auth show github
265
- agent-browser auth delete github
266
- ```
267
-
268
- `auth login` waits for username/password/submit selectors before interacting, with a timeout tied to the default action timeout.
269
-
270
- ### Authentication with State Persistence
271
-
272
- ```bash
273
- # Login once and save state
274
- agent-browser open https://app.example.com/login
275
- agent-browser snapshot -i
276
- agent-browser fill @e1 "$USERNAME"
277
- agent-browser fill @e2 "$PASSWORD"
278
- agent-browser click @e3
279
- agent-browser wait --url "**/dashboard"
280
- agent-browser state save auth.json
281
-
282
- # Reuse in future sessions
283
- agent-browser state load auth.json
284
- agent-browser open https://app.example.com/dashboard
285
- ```
286
-
287
- ### Session Persistence
288
-
289
- ```bash
290
- # Auto-save/restore cookies and localStorage across browser restarts
291
- agent-browser --session-name myapp open https://app.example.com/login
292
- # ... login flow ...
293
- agent-browser close # State auto-saved to ~/.agent-browser/sessions/
294
-
295
- # Next time, state is auto-loaded
296
- agent-browser --session-name myapp open https://app.example.com/dashboard
297
-
298
- # Encrypt state at rest
299
- export AGENT_BROWSER_ENCRYPTION_KEY=$(openssl rand -hex 32)
300
- agent-browser --session-name secure open https://app.example.com
301
-
302
- # Manage saved states
303
- agent-browser state list
304
- agent-browser state show myapp-default.json
305
- agent-browser state clear myapp
306
- agent-browser state clean --older-than 7
307
- ```
308
-
309
- ### Working with Iframes
310
-
311
- Iframe content is automatically inlined in snapshots. Refs inside iframes carry frame context, so you can interact with them directly.
312
-
313
- ```bash
314
- agent-browser open https://example.com/checkout
315
- agent-browser snapshot -i
316
- # @e1 [heading] "Checkout"
317
- # @e2 [Iframe] "payment-frame"
318
- # @e3 [input] "Card number"
319
- # @e4 [input] "Expiry"
320
- # @e5 [button] "Pay"
321
-
322
- # Interact directly — no frame switch needed
323
- agent-browser fill @e3 "4111111111111111"
324
- agent-browser fill @e4 "12/28"
325
- agent-browser click @e5
326
-
327
- # To scope a snapshot to one iframe:
328
- agent-browser frame @e2
329
- agent-browser snapshot -i # Only iframe content
330
- agent-browser frame main # Return to main frame
331
- ```
332
-
333
- ### Data Extraction
334
-
335
- ```bash
336
- agent-browser open https://example.com/products
337
- agent-browser snapshot -i
338
- agent-browser get text @e5 # Get specific element text
339
- agent-browser get text body > page.txt # Get all page text
340
-
341
- # JSON output for parsing
342
- agent-browser snapshot -i --json
343
- agent-browser get text @e1 --json
344
- ```
345
-
346
- ### Parallel Sessions
347
-
348
- ```bash
349
- agent-browser --session site1 open https://site-a.com
350
- agent-browser --session site2 open https://site-b.com
351
-
352
- agent-browser --session site1 snapshot -i
353
- agent-browser --session site2 snapshot -i
354
-
355
- agent-browser session list
356
- ```
357
-
358
- ### Connect to Existing Chrome
359
-
360
- ```bash
361
- # Auto-discover running Chrome with remote debugging enabled
362
- agent-browser --auto-connect open https://example.com
363
- agent-browser --auto-connect snapshot
364
-
365
- # Or with explicit CDP port
366
- agent-browser --cdp 9222 snapshot
367
- ```
368
-
369
- Auto-connect discovers Chrome via `DevToolsActivePort`, common debugging ports (9222, 9229), and falls back to a direct WebSocket connection if HTTP-based CDP discovery fails.
370
-
371
- ### Color Scheme (Dark Mode)
372
-
373
- ```bash
374
- # Persistent dark mode via flag (applies to all pages and new tabs)
375
- agent-browser --color-scheme dark open https://example.com
376
-
377
- # Or via environment variable
378
- AGENT_BROWSER_COLOR_SCHEME=dark agent-browser open https://example.com
379
-
380
- # Or set during session (persists for subsequent commands)
381
- agent-browser set media dark
382
- ```
383
-
384
- ### Viewport & Responsive Testing
385
-
386
- ```bash
387
- # Set a custom viewport size (default is 1280x720)
388
- agent-browser set viewport 1920 1080
389
- agent-browser screenshot desktop.png
390
-
391
- # Test mobile-width layout
392
- agent-browser set viewport 375 812
393
- agent-browser screenshot mobile.png
394
-
395
- # Retina/HiDPI: same CSS layout at 2x pixel density
396
- # Screenshots stay at logical viewport size, but content renders at higher DPI
397
- agent-browser set viewport 1920 1080 2
398
- agent-browser screenshot retina.png
399
-
400
- # Device emulation (sets viewport + user agent in one step)
401
- agent-browser set device "iPhone 14"
402
- agent-browser screenshot device.png
403
- ```
404
-
405
- The `scale` parameter (3rd argument) sets `window.devicePixelRatio` without changing CSS layout. Use it when testing retina rendering or capturing higher-resolution screenshots.
406
-
407
- ### Visual Browser (Debugging)
408
-
409
- ```bash
410
- agent-browser --headed open https://example.com
411
- agent-browser highlight @e1 # Highlight element
412
- agent-browser inspect # Open Chrome DevTools for the active page
413
- agent-browser record start demo.webm # Record session
414
- agent-browser profiler start # Start Chrome DevTools profiling
415
- agent-browser profiler stop trace.json # Stop and save profile (path optional)
416
- ```
417
-
418
- Use `AGENT_BROWSER_HEADED=1` to enable headed mode via environment variable. Browser extensions work in both headed and headless mode.
419
-
420
- ### Local Files (PDFs, HTML)
421
-
422
- ```bash
423
- # Open local files with file:// URLs
424
- agent-browser --allow-file-access open file:///path/to/document.pdf
425
- agent-browser --allow-file-access open file:///path/to/page.html
426
- agent-browser screenshot output.png
427
- ```
428
-
429
- ### iOS Simulator (Mobile Safari)
430
-
431
- ```bash
432
- # List available iOS simulators
433
- agent-browser device list
434
-
435
- # Launch Safari on a specific device
436
- agent-browser -p ios --device "iPhone 16 Pro" open https://example.com
437
-
438
- # Same workflow as desktop - snapshot, interact, re-snapshot
439
- agent-browser -p ios snapshot -i
440
- agent-browser -p ios tap @e1 # Tap (alias for click)
441
- agent-browser -p ios fill @e2 "text"
442
- agent-browser -p ios swipe up # Mobile-specific gesture
443
-
444
- # Take screenshot
445
- agent-browser -p ios screenshot mobile.png
446
-
447
- # Close session (shuts down simulator)
448
- agent-browser -p ios close
449
- ```
450
-
451
- **Requirements:** macOS with Xcode, Appium (`npm install -g appium && appium driver install xcuitest`)
452
-
453
- **Real devices:** Works with physical iOS devices if pre-configured. Use `--device "<UDID>"` where UDID is from `xcrun xctrace list devices`.
454
-
455
- ## Security
456
-
457
- All security features are opt-in. By default, agent-browser imposes no restrictions on navigation, actions, or output.
458
-
459
- ### Content Boundaries (Recommended for AI Agents)
460
-
461
- Enable `--content-boundaries` to wrap page-sourced output in markers that help LLMs distinguish tool output from untrusted page content:
462
-
463
- ```bash
464
- export AGENT_BROWSER_CONTENT_BOUNDARIES=1
465
- agent-browser snapshot
466
- # Output:
467
- # --- AGENT_BROWSER_PAGE_CONTENT nonce=<hex> origin=https://example.com ---
468
- # [accessibility tree]
469
- # --- END_AGENT_BROWSER_PAGE_CONTENT nonce=<hex> ---
470
- ```
471
-
472
- ### Domain Allowlist
473
-
474
- Restrict navigation to trusted domains. Wildcards like `*.example.com` also match the bare domain `example.com`. Sub-resource requests, WebSocket, and EventSource connections to non-allowed domains are also blocked. Include CDN domains your target pages depend on:
475
-
476
- ```bash
477
- export AGENT_BROWSER_ALLOWED_DOMAINS="example.com,*.example.com"
478
- agent-browser open https://example.com # OK
479
- agent-browser open https://malicious.com # Blocked
480
- ```
481
-
482
- ### Action Policy
483
-
484
- Use a policy file to gate destructive actions:
485
-
486
- ```bash
487
- export AGENT_BROWSER_ACTION_POLICY=./policy.json
488
- ```
489
-
490
- Example `policy.json`:
491
-
492
- ```json
493
- { "default": "deny", "allow": ["navigate", "snapshot", "click", "scroll", "wait", "get"] }
494
- ```
495
-
496
- Auth vault operations (`auth login`, etc.) bypass action policy but domain allowlist still applies.
497
-
498
- ### Output Limits
499
-
500
- Prevent context flooding from large pages:
501
-
502
- ```bash
503
- export AGENT_BROWSER_MAX_OUTPUT=50000
504
- ```
505
-
506
- ## Diffing (Verifying Changes)
507
-
508
- Use `diff snapshot` after performing an action to verify it had the intended effect. This compares the current accessibility tree against the last snapshot taken in the session.
509
-
510
- ```bash
511
- # Typical workflow: snapshot -> action -> diff
512
- agent-browser snapshot -i # Take baseline snapshot
513
- agent-browser click @e2 # Perform action
514
- agent-browser diff snapshot # See what changed (auto-compares to last snapshot)
515
- ```
516
-
517
- For visual regression testing or monitoring:
518
-
519
- ```bash
520
- # Save a baseline screenshot, then compare later
521
- agent-browser screenshot baseline.png
522
- # ... time passes or changes are made ...
523
- agent-browser diff screenshot --baseline baseline.png
524
-
525
- # Compare staging vs production
526
- agent-browser diff url https://staging.example.com https://prod.example.com --screenshot
527
- ```
528
-
529
- `diff snapshot` output uses `+` for additions and `-` for removals, similar to git diff. `diff screenshot` produces a diff image with changed pixels highlighted in red, plus a mismatch percentage.
530
-
531
- ## Timeouts and Slow Pages
532
-
533
- The default timeout is 25 seconds. This can be overridden with the `AGENT_BROWSER_DEFAULT_TIMEOUT` environment variable (value in milliseconds). For slow websites or large pages, use explicit waits instead of relying on the default timeout:
534
-
535
- ```bash
536
- # Wait for network activity to settle (best for slow pages)
537
- agent-browser wait --load networkidle
538
-
539
- # Wait for a specific element to appear
540
- agent-browser wait "#content"
541
- agent-browser wait @e1
542
-
543
- # Wait for a specific URL pattern (useful after redirects)
544
- agent-browser wait --url "**/dashboard"
545
-
546
- # Wait for a JavaScript condition
547
- agent-browser wait --fn "document.readyState === 'complete'"
548
-
549
- # Wait a fixed duration (milliseconds) as a last resort
550
- agent-browser wait 5000
551
- ```
552
-
553
- When dealing with consistently slow websites, use `wait --load networkidle` after `open` to ensure the page is fully loaded before taking a snapshot. If a specific element is slow to render, wait for it directly with `wait <selector>` or `wait @ref`.
554
-
555
- ## JavaScript Dialogs (alert / confirm / prompt)
556
-
557
- When a page opens a JavaScript dialog (`alert()`, `confirm()`, or `prompt()`), it blocks all other browser commands (snapshot, screenshot, click, etc.) until the dialog is dismissed. If commands start timing out unexpectedly, check for a pending dialog:
558
-
559
- ```bash
560
- # Check if a dialog is blocking
561
- agent-browser dialog status
562
-
563
- # Accept the dialog (dismiss the alert / click OK)
564
- agent-browser dialog accept
565
-
566
- # Accept a prompt dialog with input text
567
- agent-browser dialog accept "my input"
568
-
569
- # Dismiss the dialog (click Cancel)
570
- agent-browser dialog dismiss
571
- ```
572
-
573
- When a dialog is pending, all command responses include a `warning` field indicating the dialog type and message. In `--json` mode this appears as a `"warning"` key in the response object.
574
-
575
- ## Session Management and Cleanup
576
-
577
- When running multiple agents or automations concurrently, always use named sessions to avoid conflicts:
578
-
579
- ```bash
580
- # Each agent gets its own isolated session
581
- agent-browser --session agent1 open site-a.com
582
- agent-browser --session agent2 open site-b.com
583
-
584
- # Check active sessions
585
- agent-browser session list
586
- ```
587
-
588
- Always close your browser session when done to avoid leaked processes:
589
-
590
- ```bash
591
- agent-browser close # Close default session
592
- agent-browser --session agent1 close # Close specific session
593
- agent-browser close --all # Close all active sessions
594
- ```
595
-
596
- If a previous session was not closed properly, the daemon may still be running. Use `agent-browser close` to clean it up, or `agent-browser close --all` to shut down every session at once.
597
-
598
- To auto-shutdown the daemon after a period of inactivity (useful for ephemeral/CI environments):
599
-
600
- ```bash
601
- AGENT_BROWSER_IDLE_TIMEOUT_MS=60000 agent-browser open example.com
602
- ```
603
-
604
- ## Ref Lifecycle (Important)
605
-
606
- Refs (`@e1`, `@e2`, etc.) are invalidated when the page changes. Always re-snapshot after:
607
-
608
- - Clicking links or buttons that navigate
609
- - Form submissions
610
- - Dynamic content loading (dropdowns, modals)
611
-
612
- ```bash
613
- agent-browser click @e5 # Navigates to new page
614
- agent-browser snapshot -i # MUST re-snapshot
615
- agent-browser click @e1 # Use new refs
616
- ```
617
-
618
- ## Annotated Screenshots (Vision Mode)
619
-
620
- Use `--annotate` to take a screenshot with numbered labels overlaid on interactive elements. Each label `[N]` maps to ref `@eN`. This also caches refs, so you can interact with elements immediately without a separate snapshot.
621
-
622
- ```bash
623
- agent-browser screenshot --annotate
624
- # Output includes the image path and a legend:
625
- # [1] @e1 button "Submit"
626
- # [2] @e2 link "Home"
627
- # [3] @e3 textbox "Email"
628
- agent-browser click @e2 # Click using ref from annotated screenshot
629
- ```
630
-
631
- Use annotated screenshots when:
632
-
633
- - The page has unlabeled icon buttons or visual-only elements
634
- - You need to verify visual layout or styling
635
- - Canvas or chart elements are present (invisible to text snapshots)
636
- - You need spatial reasoning about element positions
637
-
638
- ## Semantic Locators (Alternative to Refs)
639
-
640
- When refs are unavailable or unreliable, use semantic locators:
641
-
642
- ```bash
643
- agent-browser find text "Sign In" click
644
- agent-browser find label "Email" fill "user@test.com"
645
- agent-browser find role button click --name "Submit"
646
- agent-browser find placeholder "Search" type "query"
647
- agent-browser find testid "submit-btn" click
648
- ```
649
-
650
- ## JavaScript Evaluation (eval)
651
-
652
- Use `eval` to run JavaScript in the browser context. **Shell quoting can corrupt complex expressions** -- use `--stdin` or `-b` to avoid issues.
653
-
654
- ```bash
655
- # Simple expressions work with regular quoting
656
- agent-browser eval 'document.title'
657
- agent-browser eval 'document.querySelectorAll("img").length'
658
-
659
- # Complex JS: use --stdin with heredoc (RECOMMENDED)
660
- agent-browser eval --stdin <<'EVALEOF'
661
- JSON.stringify(
662
- Array.from(document.querySelectorAll("img"))
663
- .filter(i => !i.alt)
664
- .map(i => ({ src: i.src.split("/").pop(), width: i.width }))
665
- )
666
- EVALEOF
667
-
668
- # Alternative: base64 encoding (avoids all shell escaping issues)
669
- agent-browser eval -b "$(echo -n 'Array.from(document.querySelectorAll("a")).map(a => a.href)' | base64)"
670
- ```
671
-
672
- **Why this matters:** When the shell processes your command, inner double quotes, `!` characters (history expansion), backticks, and `$()` can all corrupt the JavaScript before it reaches agent-browser. The `--stdin` and `-b` flags bypass shell interpretation entirely.
673
-
674
- **Rules of thumb:**
675
-
676
- - Single-line, no nested quotes -> regular `eval 'expression'` with single quotes is fine
677
- - Nested quotes, arrow functions, template literals, or multiline -> use `eval --stdin <<'EVALEOF'`
678
- - Programmatic/generated scripts -> use `eval -b` with base64
679
-
680
- ## Configuration File
681
-
682
- Create `agent-browser.json` in the project root for persistent settings:
683
-
684
- ```json
685
- {
686
- "headed": true,
687
- "proxy": "http://localhost:8080",
688
- "profile": "./browser-data"
689
- }
690
- ```
691
-
692
- Priority (lowest to highest): `~/.agent-browser/config.json` < `./agent-browser.json` < env vars < CLI flags. Use `--config <path>` or `AGENT_BROWSER_CONFIG` env var for a custom config file (exits with error if missing/invalid). All CLI options map to camelCase keys (e.g., `--executable-path` -> `"executablePath"`). Boolean flags accept `true`/`false` values (e.g., `--headed false` overrides config). Extensions from user and project configs are merged, not replaced.
693
-
694
- ## Deep-Dive Documentation
695
-
696
- | Reference | When to Use |
697
- | -------------------------------------------------------------------- | --------------------------------------------------------- |
698
- | [references/commands.md](references/commands.md) | Full command reference with all options |
699
- | [references/snapshot-refs.md](references/snapshot-refs.md) | Ref lifecycle, invalidation rules, troubleshooting |
700
- | [references/session-management.md](references/session-management.md) | Parallel sessions, state persistence, concurrent scraping |
701
- | [references/authentication.md](references/authentication.md) | Login flows, OAuth, 2FA handling, state reuse |
702
- | [references/video-recording.md](references/video-recording.md) | Recording workflows for debugging and documentation |
703
- | [references/profiling.md](references/profiling.md) | Chrome DevTools profiling for performance analysis |
704
- | [references/proxy-support.md](references/proxy-support.md) | Proxy configuration, geo-testing, rotating proxies |
705
-
706
- ## Cloud Providers
707
-
708
- Use `-p <provider>` (or `AGENT_BROWSER_PROVIDER`) to run against a cloud browser instead of launching a local Chrome instance. Supported providers: `agentcore`, `browserbase`, `browserless`, `browseruse`, `kernel`.
709
-
710
- ### AgentCore (AWS Bedrock)
711
-
712
- ```bash
713
- # Credentials auto-resolved from env vars or AWS CLI (SSO, IAM roles, etc.)
714
- agent-browser -p agentcore open https://example.com
715
-
716
- # With persistent browser profile
717
- AGENTCORE_PROFILE_ID=my-profile agent-browser -p agentcore open https://example.com
718
-
719
- # With explicit region
720
- AGENTCORE_REGION=eu-west-1 agent-browser -p agentcore open https://example.com
721
- ```
722
-
723
- Set `AWS_PROFILE` to select a named AWS profile.
724
-
725
- ## Browser Engine Selection
726
-
727
- Use `--engine` to choose a local browser engine. The default is `chrome`.
728
-
729
- ```bash
730
- # Use Lightpanda (fast headless browser, requires separate install)
731
- agent-browser --engine lightpanda open example.com
732
-
733
- # Via environment variable
734
- export AGENT_BROWSER_ENGINE=lightpanda
735
- agent-browser open example.com
736
-
737
- # With custom binary path
738
- agent-browser --engine lightpanda --executable-path /path/to/lightpanda open example.com
739
- ```
740
-
741
- Supported engines:
742
- - `chrome` (default) -- Chrome/Chromium via CDP
743
- - `lightpanda` -- Lightpanda headless browser via CDP (10x faster, 10x less memory than Chrome)
744
-
745
- Lightpanda does not support `--extension`, `--profile`, `--state`, or `--allow-file-access`. Install Lightpanda from https://lightpanda.io/docs/open-source/installation.
746
-
747
- ## Observability Dashboard
748
-
749
- The dashboard is a standalone background server that shows live browser viewports, command activity, and console output for all sessions.
750
-
751
- ```bash
752
- # Install the dashboard once
753
- agent-browser dashboard install
754
-
755
- # Start the dashboard server (background, port 4848)
756
- agent-browser dashboard start
757
-
758
- # All sessions are automatically visible in the dashboard
759
- agent-browser open example.com
760
-
761
- # Stop the dashboard
762
- agent-browser dashboard stop
763
- ```
764
-
765
- The dashboard runs independently of browser sessions on port 4848 (configurable with `--port`). All sessions automatically stream to the dashboard. Sessions can also be created from the dashboard UI with local engines or cloud providers.
766
-
767
- ## Ready-to-Use Templates
768
-
769
- | Template | Description |
770
- | ------------------------------------------------------------------------ | ----------------------------------- |
771
- | [templates/form-automation.sh](templates/form-automation.sh) | Form filling with validation |
772
- | [templates/authenticated-session.sh](templates/authenticated-session.sh) | Login once, reuse state |
773
- | [templates/capture-workflow.sh](templates/capture-workflow.sh) | Content extraction with screenshots |
774
-
775
- ```bash
776
- ./templates/form-automation.sh https://example.com/form
777
- ./templates/authenticated-session.sh https://app.example.com/login
778
- ./templates/capture-workflow.sh https://example.com ./output
779
- ```