@divebell/agent-browser 0.33.1-divebell.1

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 (47) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +1831 -0
  3. package/bin/agent-browser-darwin-arm64 +0 -0
  4. package/bin/agent-browser-darwin-x64 +0 -0
  5. package/bin/agent-browser-linux-arm64 +0 -0
  6. package/bin/agent-browser-linux-musl-arm64 +0 -0
  7. package/bin/agent-browser-linux-musl-x64 +0 -0
  8. package/bin/agent-browser-linux-x64 +0 -0
  9. package/bin/agent-browser-win32-x64.exe +0 -0
  10. package/bin/agent-browser.js +120 -0
  11. package/cli/src/native/a11y/LICENSE-axe-core-THIRD-PARTY.txt +66 -0
  12. package/cli/src/native/a11y/LICENSE-axe-core.txt +362 -0
  13. package/package.json +61 -0
  14. package/scripts/build-all-platforms.sh +85 -0
  15. package/scripts/check-version-sync.js +81 -0
  16. package/scripts/copy-native.js +36 -0
  17. package/scripts/postinstall.js +321 -0
  18. package/scripts/sync-version.js +125 -0
  19. package/scripts/windows-debug/provision.sh +220 -0
  20. package/scripts/windows-debug/run.sh +92 -0
  21. package/scripts/windows-debug/start.sh +43 -0
  22. package/scripts/windows-debug/stop.sh +28 -0
  23. package/scripts/windows-debug/sync.sh +27 -0
  24. package/skill-data/agentcore/SKILL.md +115 -0
  25. package/skill-data/core/SKILL.md +518 -0
  26. package/skill-data/core/references/authentication.md +380 -0
  27. package/skill-data/core/references/commands.md +511 -0
  28. package/skill-data/core/references/profiling.md +120 -0
  29. package/skill-data/core/references/proxy-support.md +194 -0
  30. package/skill-data/core/references/session-management.md +180 -0
  31. package/skill-data/core/references/snapshot-refs.md +219 -0
  32. package/skill-data/core/references/trust-boundaries.md +51 -0
  33. package/skill-data/core/references/video-recording.md +175 -0
  34. package/skill-data/core/references/webgpu.md +118 -0
  35. package/skill-data/core/templates/authenticated-session.sh +105 -0
  36. package/skill-data/core/templates/capture-workflow.sh +69 -0
  37. package/skill-data/core/templates/form-automation.sh +62 -0
  38. package/skill-data/derive-client/SKILL.md +86 -0
  39. package/skill-data/dogfood/SKILL.md +220 -0
  40. package/skill-data/dogfood/references/issue-taxonomy.md +109 -0
  41. package/skill-data/dogfood/templates/dogfood-report-template.md +53 -0
  42. package/skill-data/electron/SKILL.md +236 -0
  43. package/skill-data/slack/SKILL.md +285 -0
  44. package/skill-data/slack/references/slack-tasks.md +348 -0
  45. package/skill-data/slack/templates/slack-report-template.md +163 -0
  46. package/skill-data/vercel-sandbox/SKILL.md +213 -0
  47. package/skills/agent-browser/SKILL.md +51 -0
@@ -0,0 +1,511 @@
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 # Launch browser (no navigation); stays on about:blank.
9
+ # Pair with `network route`, `cookies set --curl`, or
10
+ # `addinitscript` to stage state before the first navigation.
11
+ agent-browser open <url> # Launch + navigate (aliases: goto, navigate)
12
+ # Supports: https://, http://, file://, about:, data://
13
+ # Auto-prepends https:// if no protocol given
14
+ agent-browser read [url] # Fetch agent-readable text, or read rendered active-tab DOM
15
+ # Explicit URLs send Accept: text/markdown, then try .md if needed
16
+ # Walks ancestor paths for llms.txt before HTML fallback
17
+ # --llms and --require-md without URL use the active tab URL
18
+ # --filter narrows page content to matching heading sections
19
+ # Honors --allowed-domains, --content-boundaries, and --max-output
20
+ # Options: --raw, --require-md, --outline, --llms <index|full>, --filter, --timeout <ms>
21
+ agent-browser back # Go back
22
+ agent-browser forward # Go forward
23
+ agent-browser reload # Reload page
24
+ agent-browser pushstate <url> # SPA client-side navigation. Auto-detects
25
+ # window.next.router.push (triggers RSC fetch on Next.js);
26
+ # falls back to history.pushState + popstate/navigate events.
27
+ agent-browser close # Close browser (aliases: quit, exit)
28
+ agent-browser connect 9222 # Connect to browser via CDP port
29
+ ```
30
+
31
+ ### Pre-navigation setup (one-turn batch)
32
+
33
+ ```bash
34
+ agent-browser batch \
35
+ '["open"]' \
36
+ '["network","route","*","--abort","--resource-type","script"]' \
37
+ '["cookies","set","--curl","cookies.curl","--domain","localhost"]' \
38
+ '["navigate","http://localhost:3000/target"]'
39
+ ```
40
+
41
+ `open` with no URL gives you a clean launch so any interception, cookies, or init scripts you register take effect on the *first* real navigation. Use for SSR-only debug (`--resource-type script`), protected-origin auth, or capturing fresh `react suspense`/`vitals` state without noise from a prior page.
42
+
43
+ ## Snapshot (page analysis)
44
+
45
+ ```bash
46
+ agent-browser snapshot # Full accessibility tree
47
+ agent-browser snapshot -i # Interactive elements only (recommended)
48
+ agent-browser snapshot -c # Compact output
49
+ agent-browser snapshot -d 3 # Limit depth to 3
50
+ agent-browser snapshot -s "#main" # Scope to CSS selector
51
+ ```
52
+
53
+ ## Interactions (use @refs from snapshot)
54
+
55
+ ```bash
56
+ agent-browser click @e1 # Click
57
+ agent-browser click @e1 --new-tab # Click and open in new tab
58
+ agent-browser dblclick @e1 # Double-click
59
+ agent-browser focus @e1 # Focus element
60
+ agent-browser fill @e2 "text" # Clear and type
61
+ agent-browser type @e2 "text" # Type without clearing
62
+ agent-browser press Enter # Press key (alias: key)
63
+ agent-browser press Control+a # Key combination
64
+ agent-browser keydown Shift # Hold key down
65
+ agent-browser keyup Shift # Release key
66
+ agent-browser hover @e1 # Hover
67
+ agent-browser check @e1 # Check checkbox
68
+ agent-browser uncheck @e1 # Uncheck checkbox
69
+ agent-browser select @e1 "value" # Select dropdown option
70
+ agent-browser select @e1 "a" "b" # Select multiple options
71
+ agent-browser scroll down 500 # Scroll page (default: down 300px)
72
+ agent-browser scrollintoview @e1 # Scroll element into view (alias: scrollinto)
73
+ agent-browser drag @e1 @e2 # Drag and drop
74
+ agent-browser upload @e1 file.pdf # Upload files
75
+ ```
76
+
77
+ Clicks fail before dispatch when another element covers the target's click point. The error names the covering element, for example `covered by <div#consent-banner>`. Dismiss or interact with that element, run a fresh snapshot, then retry the original action.
78
+
79
+ ## Get Information
80
+
81
+ ```bash
82
+ agent-browser get text @e1 # Get element text
83
+ agent-browser get html @e1 # Get innerHTML
84
+ agent-browser get value @e1 # Get input value
85
+ agent-browser get attr @e1 href # Get attribute
86
+ agent-browser get title # Get page title
87
+ agent-browser get url # Get current URL
88
+ agent-browser get cdp-url # Get CDP WebSocket URL
89
+ agent-browser get count ".item" # Count matching elements
90
+ agent-browser get box @e1 # Get bounding box
91
+ agent-browser get styles @e1 # Get computed styles (font, color, bg, etc.)
92
+ ```
93
+
94
+ ## Check State
95
+
96
+ ```bash
97
+ agent-browser is visible @e1 # Check if visible
98
+ agent-browser is enabled @e1 # Check if enabled
99
+ agent-browser is checked @e1 # Check if checked
100
+ ```
101
+
102
+ ## Screenshots and PDF
103
+
104
+ ```bash
105
+ agent-browser screenshot # Save to temporary directory
106
+ agent-browser screenshot path.png # Save to specific path
107
+ agent-browser screenshot --full # Full page
108
+ agent-browser pdf output.pdf # Save as PDF
109
+ ```
110
+
111
+ Headless Chromium screenshots hide native scrollbars for consistent image output. Pass `--hide-scrollbars false` when launching to keep native scrollbars visible.
112
+
113
+ ## Video Recording
114
+
115
+ ```bash
116
+ agent-browser open https://example.com # Launch a browser session first
117
+ agent-browser record start ./demo.webm # Start recording
118
+ agent-browser click @e1 # Perform actions
119
+ agent-browser record stop # Stop and save video
120
+ agent-browser record restart ./take2.webm # Stop current + start new
121
+ ```
122
+
123
+ ## Wait
124
+
125
+ ```bash
126
+ agent-browser wait @e1 # Wait for element
127
+ agent-browser wait 2000 # Wait milliseconds
128
+ agent-browser wait --text "Success" # Wait for text (or -t)
129
+ agent-browser wait --url "**/dashboard" # Wait for URL pattern (or -u)
130
+ agent-browser wait --load networkidle # Wait for network idle (or -l)
131
+ agent-browser wait --fn "window.ready" # Wait for JS condition (or -f)
132
+ ```
133
+
134
+ ## Mouse Control
135
+
136
+ ```bash
137
+ agent-browser mouse move 100 200 # Move mouse
138
+ agent-browser mouse down left # Press button
139
+ agent-browser mouse up left # Release button
140
+ agent-browser mouse wheel 100 # Scroll wheel
141
+ ```
142
+
143
+ ## Semantic Locators (alternative to refs)
144
+
145
+ ```bash
146
+ agent-browser find role button click --name "Submit"
147
+ agent-browser find role heading text --name "Skills" # implicit roles work: <h2>=heading, <ul>=list, top-level <header>=banner
148
+ agent-browser find text "Sign In" click
149
+ agent-browser find text "Sign In" click --exact # Exact match only
150
+ agent-browser find label "Email" fill "user@test.com"
151
+ agent-browser find placeholder "Search" fill "query"
152
+ agent-browser find alt "Logo" click
153
+ agent-browser find title "Close" click
154
+ agent-browser find testid "submit-btn" click
155
+ agent-browser find first ".item" click
156
+ agent-browser find last ".item" click
157
+ agent-browser find nth 2 "a" hover
158
+ ```
159
+
160
+ ## Browser Settings
161
+
162
+ ```bash
163
+ agent-browser set viewport 1920 1080 # Set viewport size
164
+ agent-browser set viewport 1920 1080 2 # 2x retina (same CSS size, higher res screenshots)
165
+ agent-browser set device "iPhone 14" # Emulate device
166
+ agent-browser set geo 37.7749 -122.4194 # Set geolocation (alias: geolocation)
167
+ agent-browser set offline on # Toggle offline mode
168
+ agent-browser set headers '{"X-Key":"v"}' # Extra HTTP headers
169
+ agent-browser set credentials user pass # HTTP basic auth (alias: auth)
170
+ agent-browser set media dark # Emulate color scheme
171
+ agent-browser set media light reduced-motion # Light mode + reduced motion
172
+ ```
173
+
174
+ ## Cookies and Storage
175
+
176
+ ```bash
177
+ agent-browser cookies # Get all cookies
178
+ agent-browser cookies set name value # Set cookie
179
+ agent-browser cookies clear # Clear cookies
180
+ agent-browser storage local # Get all localStorage
181
+ agent-browser storage local key # Get specific key
182
+ agent-browser storage local set k v # Set value
183
+ agent-browser storage local clear # Clear all
184
+ ```
185
+
186
+ ## Network
187
+
188
+ ```bash
189
+ agent-browser network route <url> # Intercept requests
190
+ agent-browser network route <url> --abort # Block requests
191
+ agent-browser network route <url> --body '{}' # Mock response
192
+ agent-browser network unroute [url] # Remove routes
193
+ agent-browser network requests # View tracked requests
194
+ agent-browser network requests --filter api # Filter requests
195
+ agent-browser network request <requestId> # Full request/response detail incl. body
196
+ agent-browser network har start # Record traffic (embeds text response bodies)
197
+ agent-browser network har start --content all # Embed all bodies (binary as base64)
198
+ agent-browser network har start --content none # Sizes and headers only
199
+ agent-browser network har stop [output.har] # Stop and save HAR
200
+ ```
201
+
202
+ ## Tabs and Windows
203
+
204
+ ```bash
205
+ agent-browser tab # List tabs with tabId and label
206
+ agent-browser tab new [url] # New tab
207
+ agent-browser tab new --label docs [url] # New tab with a memorable label
208
+ agent-browser tab t2 # Switch to tab by id
209
+ agent-browser tab docs # Switch to tab by label
210
+ agent-browser tab close # Close current tab
211
+ agent-browser tab close t2 # Close tab by id
212
+ agent-browser tab close docs # Close tab by label
213
+ agent-browser window new # New window
214
+ ```
215
+
216
+ Tab ids are stable strings of the form `t1`, `t2`, `t3`. They're never reused within a session, so the same id keeps referring to the same tab across commands. Positional integers are **not** accepted — `tab 2` errors with a teaching message; use `t2`.
217
+
218
+ User-assigned labels (`docs`, `app`, `admin`) are interchangeable with ids everywhere a tab ref is accepted. Labels are the agent-friendly way to write multi-tab workflows:
219
+
220
+ ```bash
221
+ agent-browser tab new --label docs https://docs.example.com
222
+ agent-browser tab new --label app https://app.example.com
223
+ agent-browser tab docs # switch to docs
224
+ agent-browser snapshot # populate refs for docs
225
+ agent-browser click @e1 # ref click on docs
226
+ agent-browser tab app # switch to app
227
+ agent-browser tab close docs # close by label
228
+ ```
229
+
230
+ Labels are never auto-generated, never rewritten on navigation, and must be unique within a session. To interact with another tab, switch to it first: the daemon maintains a single active tab, so refs (`@eN`) belong to the tab that was active when the snapshot ran.
231
+
232
+ Switching to a tab that the browser discarded to save memory reactivates it, since a discarded tab has no renderer to drive. Reactivation reloads the page and resets its unsaved state, and the switch result adds `"revived": true` so the reload is not silent. A tab whose page is paused by a JavaScript dialog is alive rather than discarded: the switch leaves it untouched and adds `"dialogBlocked": true`. Resolve the dialog with `dialog accept`/`dialog dismiss` and its state is preserved. Closing the active tab onto a discarded successor revives it the same way and reports `"activeTabRevived": true`.
233
+
234
+ ## Frames
235
+
236
+ ```bash
237
+ agent-browser frame "#iframe" # Switch to iframe by CSS selector
238
+ agent-browser frame @e3 # Switch to iframe by element ref
239
+ agent-browser frame main # Back to main frame
240
+ ```
241
+
242
+ ### Iframe support
243
+
244
+ Iframes are detected automatically during snapshots. When the main-frame snapshot runs, `Iframe` nodes are resolved and their content is inlined beneath the iframe element in the output (one level of nesting; iframes within iframes are not expanded).
245
+
246
+ ```bash
247
+ agent-browser snapshot -i
248
+ # @e3 [Iframe] "payment-frame"
249
+ # @e4 [input] "Card number"
250
+ # @e5 [button] "Pay"
251
+
252
+ # Interact directly — refs inside iframes already work
253
+ agent-browser fill @e4 "4111111111111111"
254
+ agent-browser click @e5
255
+
256
+ # Or switch frame context for scoped snapshots
257
+ agent-browser frame @e3 # Switch using element ref
258
+ agent-browser snapshot -i # Snapshot scoped to that iframe
259
+ agent-browser frame main # Return to main frame
260
+ ```
261
+
262
+ The `frame` command accepts:
263
+ - **Element refs** — `frame @e3` resolves the ref to an iframe element
264
+ - **CSS selectors** — `frame "#payment-iframe"` finds the iframe by selector
265
+ - **Frame name/URL** — matches against the browser's frame tree
266
+
267
+ ## Dialogs
268
+
269
+ By default, `alert` and `beforeunload` dialogs are automatically accepted so they never block the agent. `confirm` and `prompt` dialogs still require explicit handling. Use `--no-auto-dialog` to disable this behavior.
270
+
271
+ ```bash
272
+ agent-browser dialog accept [text] # Accept dialog
273
+ agent-browser dialog dismiss # Dismiss dialog
274
+ agent-browser dialog status # Check if a dialog is currently open
275
+ ```
276
+
277
+ ## JavaScript
278
+
279
+ ```bash
280
+ agent-browser eval "document.title" # Simple expressions only
281
+ agent-browser eval -b "<base64>" # Any JavaScript (base64 encoded)
282
+ agent-browser eval --stdin # Read script from stdin
283
+ ```
284
+
285
+ Use `-b`/`--base64` or `--stdin` for reliable execution. Shell escaping with nested quotes and special characters is error-prone.
286
+
287
+ ```bash
288
+ # Base64 encode your script, then:
289
+ agent-browser eval -b "ZG9jdW1lbnQucXVlcnlTZWxlY3RvcignW3NyYyo9Il9uZXh0Il0nKQ=="
290
+
291
+ # Or use stdin with heredoc for multiline scripts:
292
+ cat <<'EOF' | agent-browser eval --stdin
293
+ const links = document.querySelectorAll('a');
294
+ Array.from(links).map(a => a.href);
295
+ EOF
296
+ ```
297
+
298
+ ## Authentication and Plugins
299
+
300
+ ```bash
301
+ agent-browser auth save <name> --url <url> --username <user> --password-stdin
302
+ agent-browser auth login <name> # Login using saved credentials
303
+ agent-browser auth login <name> --credential-provider <plugin> [--item <ref>] [--url <url>]
304
+ agent-browser auth login <name> --username-selector <s> --password-selector <s> [--submit-selector <s>]
305
+ agent-browser auth list # List saved auth profiles
306
+ agent-browser auth show <name> # Show profile metadata, no passwords
307
+ agent-browser auth delete <name> # Delete a saved profile
308
+ agent-browser plugin add <ref> # Add a plugin from npm or GitHub
309
+ agent-browser plugin list # List configured plugins
310
+ agent-browser plugin show <name> # Show one configured plugin
311
+ agent-browser plugin run <name> <type> --payload <json>
312
+ # Run an arbitrary plugin request
313
+ ```
314
+
315
+ Credential provider plugins run out-of-process over the `agent-browser.plugin.v1` stdio JSON protocol and must declare `credential.read`. Use `--confirm-actions plugin:<name>:credential.read` to require explicit approval before a plugin resolves secrets.
316
+
317
+ Other capabilities use the same protocol:
318
+ - `browser.provider`: `agent-browser --provider <name> open <url>`
319
+ - `launch.mutate`: append local launch args, extensions, or init scripts
320
+ - `command.run`: `agent-browser plugin run <name> <type> --payload <json>`
321
+
322
+ `plugin run` is for `command.run` and custom capabilities. Core capabilities and protocol request types use their dedicated command paths.
323
+
324
+ ## State Management
325
+
326
+ ```bash
327
+ agent-browser state save auth.json # Save cookies, storage, auth state
328
+ agent-browser state load auth.json # Restore saved state
329
+ ```
330
+
331
+ ## MCP Server
332
+
333
+ ```bash
334
+ agent-browser mcp
335
+ agent-browser mcp --tools all
336
+ agent-browser mcp --tools core,network,react
337
+ ```
338
+
339
+ Starts a stdio Model Context Protocol server. MCP clients should configure the server command as `agent-browser` with args `["mcp"]`. The server defaults to MCP protocol 2025-11-25 and accepts older supported client protocol versions during initialization.
340
+
341
+ The default tools profile is `core`, which keeps MCP context small for everyday browser automation. Use `--tools all` for the full typed CLI parity surface, or combine profiles with commas, such as `--tools core,network,react`.
342
+
343
+ Profiles:
344
+
345
+ - `core` - Default. Navigation, snapshots, interaction, waits, reads, screenshots, JavaScript eval, close, tab basics, and profile discovery
346
+ - `network` - Network routes, request inspection, HAR, headers, credentials, offline
347
+ - `state` - Cookies, storage, auth, saved state, sessions, profiles, skills
348
+ - `debug` - Console/errors, tracing, profiling, recording, a11y audit, clipboard, plugins, doctor, dashboard, install, upgrade, chat, diff, batch, confirm/deny
349
+ - `tabs` - Back/forward/reload, tabs, windows, frames, dialogs
350
+ - `react` - React tree/inspect/renders/suspense, vitals, pushstate
351
+ - `mobile` - Viewport/device/geolocation/media, touch, swipe, mouse, keyboard
352
+ - `all` - Every MCP tool, including the full typed CLI parity surface
353
+
354
+ Common tools include:
355
+
356
+ - `agent_browser_tools_profiles`
357
+ - `agent_browser_open`
358
+ - `agent_browser_snapshot`
359
+ - `agent_browser_click`
360
+ - `agent_browser_fill`
361
+ - `agent_browser_type`
362
+ - `agent_browser_press`
363
+ - `agent_browser_wait_for_selector`
364
+ - `agent_browser_screenshot`
365
+ - `agent_browser_get_url`
366
+ - `agent_browser_eval`
367
+ - `agent_browser_close`
368
+
369
+ Tool calls use the same config files and environment variables as the CLI. Each tool accepts typed arguments plus `extraArgs` for advanced CLI flags and exact CLI parity. The common `allowedDomains` array maps to `--allowed-domains` and activates the same WebRTC containment and launch-mode restrictions. Tool discovery is paginated and includes read-only/open-world annotations so modern MCP clients can load the large typed surface incrementally. Use the `session` tool argument or `AGENT_BROWSER_SESSION` to isolate browser state.
370
+
371
+ ## Global Options
372
+
373
+ ```bash
374
+ agent-browser --session <name> ... # Isolated browser session
375
+ agent-browser --json ... # JSON output for parsing
376
+ agent-browser --headed ... # Show browser window (not headless; on displayless Linux an Xvfb display starts automatically)
377
+ agent-browser --webgpu ... # Enable WebGPU (SwiftShader software Vulkan on Linux, no GPU needed)
378
+ agent-browser --cdp <port> ... # Connect via Chrome DevTools Protocol
379
+ agent-browser -p <provider> ... # Browser provider or configured provider plugin
380
+ agent-browser --proxy <url> ... # Use proxy server
381
+ agent-browser --proxy-bypass <hosts> # Hosts to bypass proxy
382
+ agent-browser --headers <json> ... # HTTP headers scoped to URL's origin
383
+ agent-browser --executable-path <p> # Custom browser executable
384
+ agent-browser --extension <path> ... # Load browser extension (repeatable)
385
+ agent-browser --ignore-https-errors # Ignore SSL certificate errors
386
+ agent-browser --hide-scrollbars false # Keep native scrollbars visible in headless Chromium screenshots
387
+ agent-browser --help # Show help (-h)
388
+ agent-browser --version # Show version (-V)
389
+ agent-browser <command> --help # Show detailed help for a command
390
+ ```
391
+
392
+ ## Debugging
393
+
394
+ ```bash
395
+ agent-browser --headed open example.com # Show browser window
396
+ agent-browser --cdp 9222 snapshot # Connect via CDP port
397
+ agent-browser connect 9222 # Alternative: connect command
398
+ agent-browser console # View console messages
399
+ agent-browser console --clear # Clear console
400
+ agent-browser errors # View page errors
401
+ agent-browser errors --clear # Clear errors
402
+ agent-browser highlight @e1 # Highlight element
403
+ agent-browser inspect # Open Chrome DevTools for this session
404
+ agent-browser trace start # Start recording trace
405
+ agent-browser trace stop trace.json # Stop and save trace
406
+ agent-browser profiler start # Start Chrome DevTools profiling
407
+ agent-browser profiler stop trace.json # Stop and save profile
408
+ ```
409
+
410
+ ## Memory diagnostics
411
+
412
+ Memory commands require Chrome or Chromium. They reuse the current browser session and return `memory_unsupported_engine` on Lightpanda, Safari, or other unsupported engines.
413
+
414
+ ```bash
415
+ agent-browser memory metrics
416
+ agent-browser memory status
417
+ agent-browser memory sampling start [--sampling-interval <bytes>]
418
+ agent-browser memory sampling stop [path] [--top <count>] [--max-size <bytes>]
419
+ agent-browser memory snapshot [path] [--no-gc] [--timeout <ms>] [--max-size <bytes>]
420
+ agent-browser memory collect-garbage
421
+ agent-browser memory cancel
422
+ ```
423
+
424
+ `memory metrics` returns the current JavaScript heap used and total sizes plus document, DOM node, and JavaScript event-listener counts. Use it for a cheap trend signal, not as proof of a leak.
425
+
426
+ `memory sampling start` records allocation call stacks on the current page. The default average sampling interval is 32768 bytes. `memory sampling stop` always stops the original page, saves the full `.heapprofile`, and returns the largest allocation sites with function name, script URL, line, column, and sampled bytes. Switching tabs does not change the capture target.
427
+
428
+ `memory snapshot` asks for garbage collection by default, then writes each Chrome snapshot chunk directly to a `.heapsnapshot` file. It validates that the artifact contains snapshot metadata, nodes, edges, and strings before reporting success. The default timeout is 120000 milliseconds and the default size limit is 1 GiB. Pass `--no-gc` only when the pre-collection state itself is relevant.
429
+
430
+ If no output path is supplied, profiles are saved below the runtime temporary directory under `agent-browser-memory/<session>/`. Default artifacts older than 24 hours are cleaned when a new capture starts. Command output contains only summaries and file paths. Raw artifacts are never printed into agent context.
431
+
432
+ Only one sampling or snapshot task may be active per session. `memory status` includes the capture ID, type, original target, URL, start time, output path when known, and cancellation state. `memory cancel` stops allocation sampling or interrupts a snapshot and removes partial output. Closing the captured page, closing the browser, or stopping the daemon also clears capture state.
433
+
434
+ JSON failures include a stable `errorCode`: `memory_unsupported_engine`, `memory_capture_active`, `memory_no_capture`, `memory_target_gone`, `memory_capture_cancelled`, `memory_capture_timeout`, `memory_size_limit`, `memory_invalid_artifact`, or `memory_command_failed`.
435
+
436
+ Heap snapshots and allocation profiles can contain user-visible text, application data, credentials, and tokens. Save them only on trusted local storage, never commit them, and delete them after diagnosis.
437
+
438
+ ## React / Web Vitals
439
+
440
+ Requires `--enable react-devtools` at launch for the `react ...` commands. `vitals` and `pushstate` are framework-agnostic.
441
+
442
+ ```bash
443
+ agent-browser open --enable react-devtools <url> # Launch with React hook installed
444
+ agent-browser react tree # Full component tree
445
+ agent-browser react inspect <fiberId> # Props, hooks, state, source
446
+ agent-browser react renders start # Begin re-render recording
447
+ agent-browser react renders stop [--json] # Stop and print render profile
448
+ agent-browser react suspense [--only-dynamic] [--json] # Suspense boundaries + classifier
449
+ # --only-dynamic hides the "static" list
450
+ agent-browser vitals [url] [--json] # LCP/CLS/TTFB/FCP/INP + hydration
451
+ agent-browser pushstate <url> # SPA client-side nav (auto-detects Next router)
452
+ ```
453
+
454
+ `vitals` prints a summary by default and uses the same fields as the structured `--json` response.
455
+
456
+ ## Accessibility audit
457
+
458
+ Runs an embedded axe-core audit with no CDN fetch. The vendored engine runs private partial audits through CDP across the page's frame tree and merges serialized results without page messaging, so page CSP does not block it, page-provided `window.axe` values remain intact, and iframe violations retain their frame selector paths. Accessibility audits require a CDP browser and are not available with Safari or iOS WebDriver sessions. Reports WCAG violations with impact, rule id, fix guidance URL, and failing-node selectors.
459
+
460
+ ```bash
461
+ agent-browser a11y # Audit the current page
462
+ agent-browser a11y <url> # Navigate, then audit
463
+ agent-browser a11y --tags wcag2a,wcag2aa # Only rules with these axe tags
464
+ agent-browser a11y --selector "#main" # Scope audit to a subtree
465
+ agent-browser a11y <url> --json # Structured results for automation
466
+ ```
467
+
468
+ `--json` returns `counts` plus `violations`/`incomplete` arrays; each entry has `id`, `impact`, `help`, `helpUrl`, `tags`, `nodeCount`, and up to 10 `nodes` (`target` selector path arrays, `html` snippet, `failureSummary`). Nested `target` arrays preserve shadow DOM boundaries. `incomplete` lists rules axe could not evaluate automatically — review those manually.
469
+
470
+ ## Init scripts
471
+
472
+ ```bash
473
+ agent-browser open --init-script <path> # Register before first navigation (repeatable)
474
+ agent-browser addinitscript <js> # Register at runtime (returns identifier)
475
+ agent-browser removeinitscript <identifier> # Remove a previously registered init script
476
+ ```
477
+
478
+ ## cURL cookie import
479
+
480
+ ```bash
481
+ agent-browser cookies set --curl <file> # Auto-detects JSON/cURL/Cookie-header
482
+ agent-browser cookies set --curl <file> --domain example.com # Scope to a domain
483
+ ```
484
+
485
+ Supported formats: JSON array of `{name, value}`, a cURL dump from DevTools -> Network -> Copy as cURL, or a bare Cookie header. Errors never echo cookie values.
486
+
487
+ ## Network route by resource type
488
+
489
+ ```bash
490
+ agent-browser network route '*' --abort --resource-type script # Block scripts only (SSR-lock pattern)
491
+ agent-browser network route '*' --resource-type image,font --body '' # Stub images and fonts
492
+ ```
493
+
494
+ ## Environment Variables
495
+
496
+ ```bash
497
+ AGENT_BROWSER_SESSION="mysession" # Default session name
498
+ AGENT_BROWSER_EXECUTABLE_PATH="/path/chrome" # Custom browser path
499
+ AGENT_BROWSER_EXTENSIONS="/ext1,/ext2" # Comma-separated extension paths
500
+ AGENT_BROWSER_INIT_SCRIPTS="/a.js,/b.js" # Comma-separated init script paths
501
+ AGENT_BROWSER_ENABLE="react-devtools" # Comma-separated built-in init script features
502
+ AGENT_BROWSER_HIDE_SCROLLBARS="false" # Keep native scrollbars visible in headless Chromium screenshots
503
+ AGENT_BROWSER_WEBGPU="1" # Enable the WebGPU launch preset (see references/webgpu.md)
504
+ AGENT_BROWSER_NO_XVFB="1" # Disable automatic Xvfb for headed mode on displayless Linux
505
+ AGENT_BROWSER_PROVIDER="browserbase" # Browser provider or configured provider plugin
506
+ AGENT_BROWSER_STREAM_PORT="9223" # Override WebSocket streaming port (default: OS-assigned)
507
+ AGENT_BROWSER_CONFIG="./agent-browser.json" # Custom config file
508
+ AGENT_BROWSER_CDP="9222" # Connect daemon to CDP port or WebSocket URL
509
+ AGENT_BROWSER_ALLOWED_DOMAINS="example.com" # Restrict network domains; requires a fresh controllable browser context without profile/session startup args, restore/state replay, or direct-page provider plugins
510
+ AGENT_BROWSER_PLUGINS='[{"name":"vault","command":"agent-browser-plugin-vault","capabilities":["credential.read"]},{"name":"stealth","command":"agent-browser-plugin-stealth","capabilities":["launch.mutate"]}]'
511
+ ```
@@ -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 networkidle
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 networkidle
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.