@every-env/compound-plugin 2.36.5 → 2.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,303 @@
1
+ # Authentication Patterns
2
+
3
+ Login flows, session persistence, OAuth, 2FA, and authenticated browsing.
4
+
5
+ **Related**: [commands.md](commands.md) for full command reference, [SKILL.md](../SKILL.md) for quick start.
6
+
7
+ ## Contents
8
+
9
+ - [Import Auth from Your Browser](#import-auth-from-your-browser)
10
+ - [Persistent Profiles](#persistent-profiles)
11
+ - [Session Persistence](#session-persistence)
12
+ - [Basic Login Flow](#basic-login-flow)
13
+ - [Saving Authentication State](#saving-authentication-state)
14
+ - [Restoring Authentication](#restoring-authentication)
15
+ - [OAuth / SSO Flows](#oauth--sso-flows)
16
+ - [Two-Factor Authentication](#two-factor-authentication)
17
+ - [HTTP Basic Auth](#http-basic-auth)
18
+ - [Cookie-Based Auth](#cookie-based-auth)
19
+ - [Token Refresh Handling](#token-refresh-handling)
20
+ - [Security Best Practices](#security-best-practices)
21
+
22
+ ## Import Auth from Your Browser
23
+
24
+ The fastest way to authenticate is to reuse cookies from a Chrome session you are already logged into.
25
+
26
+ **Step 1: Start Chrome with remote debugging**
27
+
28
+ ```bash
29
+ # macOS
30
+ "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --remote-debugging-port=9222
31
+
32
+ # Linux
33
+ google-chrome --remote-debugging-port=9222
34
+
35
+ # Windows
36
+ "C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222
37
+ ```
38
+
39
+ Log in to your target site(s) in this Chrome window as you normally would.
40
+
41
+ > **Security note:** `--remote-debugging-port` exposes full browser control on localhost. Any local process can connect and read cookies, execute JS, etc. Only use on trusted machines and close Chrome when done.
42
+
43
+ **Step 2: Grab the auth state**
44
+
45
+ ```bash
46
+ # Auto-discover the running Chrome and save its cookies + localStorage
47
+ agent-browser --auto-connect state save ./my-auth.json
48
+ ```
49
+
50
+ **Step 3: Reuse in automation**
51
+
52
+ ```bash
53
+ # Load auth at launch
54
+ agent-browser --state ./my-auth.json open https://app.example.com/dashboard
55
+
56
+ # Or load into an existing session
57
+ agent-browser state load ./my-auth.json
58
+ agent-browser open https://app.example.com/dashboard
59
+ ```
60
+
61
+ This works for any site, including those with complex OAuth flows, SSO, or 2FA -- as long as Chrome already has valid session cookies.
62
+
63
+ > **Security note:** State files contain session tokens in plaintext. Add them to `.gitignore`, delete when no longer needed, and set `AGENT_BROWSER_ENCRYPTION_KEY` for encryption at rest. See [Security Best Practices](#security-best-practices).
64
+
65
+ **Tip:** Combine with `--session-name` so the imported auth auto-persists across restarts:
66
+
67
+ ```bash
68
+ agent-browser --session-name myapp state load ./my-auth.json
69
+ # From now on, state is auto-saved/restored for "myapp"
70
+ ```
71
+
72
+ ## Persistent Profiles
73
+
74
+ Use `--profile` to point agent-browser at a Chrome user data directory. This persists everything (cookies, IndexedDB, service workers, cache) across browser restarts without explicit save/load:
75
+
76
+ ```bash
77
+ # First run: login once
78
+ agent-browser --profile ~/.myapp-profile open https://app.example.com/login
79
+ # ... complete login flow ...
80
+
81
+ # All subsequent runs: already authenticated
82
+ agent-browser --profile ~/.myapp-profile open https://app.example.com/dashboard
83
+ ```
84
+
85
+ Use different paths for different projects or test users:
86
+
87
+ ```bash
88
+ agent-browser --profile ~/.profiles/admin open https://app.example.com
89
+ agent-browser --profile ~/.profiles/viewer open https://app.example.com
90
+ ```
91
+
92
+ Or set via environment variable:
93
+
94
+ ```bash
95
+ export AGENT_BROWSER_PROFILE=~/.myapp-profile
96
+ agent-browser open https://app.example.com/dashboard
97
+ ```
98
+
99
+ ## Session Persistence
100
+
101
+ Use `--session-name` to auto-save and restore cookies + localStorage by name, without managing files:
102
+
103
+ ```bash
104
+ # Auto-saves state on close, auto-restores on next launch
105
+ agent-browser --session-name twitter open https://twitter.com
106
+ # ... login flow ...
107
+ agent-browser close # state saved to ~/.agent-browser/sessions/
108
+
109
+ # Next time: state is automatically restored
110
+ agent-browser --session-name twitter open https://twitter.com
111
+ ```
112
+
113
+ Encrypt state at rest:
114
+
115
+ ```bash
116
+ export AGENT_BROWSER_ENCRYPTION_KEY=$(openssl rand -hex 32)
117
+ agent-browser --session-name secure open https://app.example.com
118
+ ```
119
+
120
+ ## Basic Login Flow
121
+
122
+ ```bash
123
+ # Navigate to login page
124
+ agent-browser open https://app.example.com/login
125
+ agent-browser wait --load networkidle
126
+
127
+ # Get form elements
128
+ agent-browser snapshot -i
129
+ # Output: @e1 [input type="email"], @e2 [input type="password"], @e3 [button] "Sign In"
130
+
131
+ # Fill credentials
132
+ agent-browser fill @e1 "user@example.com"
133
+ agent-browser fill @e2 "password123"
134
+
135
+ # Submit
136
+ agent-browser click @e3
137
+ agent-browser wait --load networkidle
138
+
139
+ # Verify login succeeded
140
+ agent-browser get url # Should be dashboard, not login
141
+ ```
142
+
143
+ ## Saving Authentication State
144
+
145
+ After logging in, save state for reuse:
146
+
147
+ ```bash
148
+ # Login first (see above)
149
+ agent-browser open https://app.example.com/login
150
+ agent-browser snapshot -i
151
+ agent-browser fill @e1 "user@example.com"
152
+ agent-browser fill @e2 "password123"
153
+ agent-browser click @e3
154
+ agent-browser wait --url "**/dashboard"
155
+
156
+ # Save authenticated state
157
+ agent-browser state save ./auth-state.json
158
+ ```
159
+
160
+ ## Restoring Authentication
161
+
162
+ Skip login by loading saved state:
163
+
164
+ ```bash
165
+ # Load saved auth state
166
+ agent-browser state load ./auth-state.json
167
+
168
+ # Navigate directly to protected page
169
+ agent-browser open https://app.example.com/dashboard
170
+
171
+ # Verify authenticated
172
+ agent-browser snapshot -i
173
+ ```
174
+
175
+ ## OAuth / SSO Flows
176
+
177
+ For OAuth redirects:
178
+
179
+ ```bash
180
+ # Start OAuth flow
181
+ agent-browser open https://app.example.com/auth/google
182
+
183
+ # Handle redirects automatically
184
+ agent-browser wait --url "**/accounts.google.com**"
185
+ agent-browser snapshot -i
186
+
187
+ # Fill Google credentials
188
+ agent-browser fill @e1 "user@gmail.com"
189
+ agent-browser click @e2 # Next button
190
+ agent-browser wait 2000
191
+ agent-browser snapshot -i
192
+ agent-browser fill @e3 "password"
193
+ agent-browser click @e4 # Sign in
194
+
195
+ # Wait for redirect back
196
+ agent-browser wait --url "**/app.example.com**"
197
+ agent-browser state save ./oauth-state.json
198
+ ```
199
+
200
+ ## Two-Factor Authentication
201
+
202
+ Handle 2FA with manual intervention:
203
+
204
+ ```bash
205
+ # Login with credentials
206
+ agent-browser open https://app.example.com/login --headed # Show browser
207
+ agent-browser snapshot -i
208
+ agent-browser fill @e1 "user@example.com"
209
+ agent-browser fill @e2 "password123"
210
+ agent-browser click @e3
211
+
212
+ # Wait for user to complete 2FA manually
213
+ echo "Complete 2FA in the browser window..."
214
+ agent-browser wait --url "**/dashboard" --timeout 120000
215
+
216
+ # Save state after 2FA
217
+ agent-browser state save ./2fa-state.json
218
+ ```
219
+
220
+ ## HTTP Basic Auth
221
+
222
+ For sites using HTTP Basic Authentication:
223
+
224
+ ```bash
225
+ # Set credentials before navigation
226
+ agent-browser set credentials username password
227
+
228
+ # Navigate to protected resource
229
+ agent-browser open https://protected.example.com/api
230
+ ```
231
+
232
+ ## Cookie-Based Auth
233
+
234
+ Manually set authentication cookies:
235
+
236
+ ```bash
237
+ # Set auth cookie
238
+ agent-browser cookies set session_token "abc123xyz"
239
+
240
+ # Navigate to protected page
241
+ agent-browser open https://app.example.com/dashboard
242
+ ```
243
+
244
+ ## Token Refresh Handling
245
+
246
+ For sessions with expiring tokens:
247
+
248
+ ```bash
249
+ #!/bin/bash
250
+ # Wrapper that handles token refresh
251
+
252
+ STATE_FILE="./auth-state.json"
253
+
254
+ # Try loading existing state
255
+ if [[ -f "$STATE_FILE" ]]; then
256
+ agent-browser state load "$STATE_FILE"
257
+ agent-browser open https://app.example.com/dashboard
258
+
259
+ # Check if session is still valid
260
+ URL=$(agent-browser get url)
261
+ if [[ "$URL" == *"/login"* ]]; then
262
+ echo "Session expired, re-authenticating..."
263
+ # Perform fresh login
264
+ agent-browser snapshot -i
265
+ agent-browser fill @e1 "$USERNAME"
266
+ agent-browser fill @e2 "$PASSWORD"
267
+ agent-browser click @e3
268
+ agent-browser wait --url "**/dashboard"
269
+ agent-browser state save "$STATE_FILE"
270
+ fi
271
+ else
272
+ # First-time login
273
+ agent-browser open https://app.example.com/login
274
+ # ... login flow ...
275
+ fi
276
+ ```
277
+
278
+ ## Security Best Practices
279
+
280
+ 1. **Never commit state files** - They contain session tokens
281
+ ```bash
282
+ echo "*.auth-state.json" >> .gitignore
283
+ ```
284
+
285
+ 2. **Use environment variables for credentials**
286
+ ```bash
287
+ agent-browser fill @e1 "$APP_USERNAME"
288
+ agent-browser fill @e2 "$APP_PASSWORD"
289
+ ```
290
+
291
+ 3. **Clean up after automation**
292
+ ```bash
293
+ agent-browser cookies clear
294
+ rm -f ./auth-state.json
295
+ ```
296
+
297
+ 4. **Use short-lived sessions for CI/CD**
298
+ ```bash
299
+ # Don't persist state in CI
300
+ agent-browser open https://app.example.com/login
301
+ # ... login and perform actions ...
302
+ agent-browser close # Session ends, nothing persisted
303
+ ```
@@ -0,0 +1,266 @@
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 click @e1 --new-tab # Click and open in new tab
33
+ agent-browser dblclick @e1 # Double-click
34
+ agent-browser focus @e1 # Focus element
35
+ agent-browser fill @e2 "text" # Clear and type
36
+ agent-browser type @e2 "text" # Type without clearing
37
+ agent-browser press Enter # Press key (alias: key)
38
+ agent-browser press Control+a # Key combination
39
+ agent-browser keydown Shift # Hold key down
40
+ agent-browser keyup Shift # Release key
41
+ agent-browser hover @e1 # Hover
42
+ agent-browser check @e1 # Check checkbox
43
+ agent-browser uncheck @e1 # Uncheck checkbox
44
+ agent-browser select @e1 "value" # Select dropdown option
45
+ agent-browser select @e1 "a" "b" # Select multiple options
46
+ agent-browser scroll down 500 # Scroll page (default: down 300px)
47
+ agent-browser scrollintoview @e1 # Scroll element into view (alias: scrollinto)
48
+ agent-browser drag @e1 @e2 # Drag and drop
49
+ agent-browser upload @e1 file.pdf # Upload files
50
+ ```
51
+
52
+ ## Get Information
53
+
54
+ ```bash
55
+ agent-browser get text @e1 # Get element text
56
+ agent-browser get html @e1 # Get innerHTML
57
+ agent-browser get value @e1 # Get input value
58
+ agent-browser get attr @e1 href # Get attribute
59
+ agent-browser get title # Get page title
60
+ agent-browser get url # Get current URL
61
+ agent-browser get cdp-url # Get CDP WebSocket URL
62
+ agent-browser get count ".item" # Count matching elements
63
+ agent-browser get box @e1 # Get bounding box
64
+ agent-browser get styles @e1 # Get computed styles (font, color, bg, etc.)
65
+ ```
66
+
67
+ ## Check State
68
+
69
+ ```bash
70
+ agent-browser is visible @e1 # Check if visible
71
+ agent-browser is enabled @e1 # Check if enabled
72
+ agent-browser is checked @e1 # Check if checked
73
+ ```
74
+
75
+ ## Screenshots and PDF
76
+
77
+ ```bash
78
+ agent-browser screenshot # Save to temporary directory
79
+ agent-browser screenshot path.png # Save to specific path
80
+ agent-browser screenshot --full # Full page
81
+ agent-browser pdf output.pdf # Save as PDF
82
+ ```
83
+
84
+ ## Video Recording
85
+
86
+ ```bash
87
+ agent-browser record start ./demo.webm # Start recording
88
+ agent-browser click @e1 # Perform actions
89
+ agent-browser record stop # Stop and save video
90
+ agent-browser record restart ./take2.webm # Stop current + start new
91
+ ```
92
+
93
+ ## Wait
94
+
95
+ ```bash
96
+ agent-browser wait @e1 # Wait for element
97
+ agent-browser wait 2000 # Wait milliseconds
98
+ agent-browser wait --text "Success" # Wait for text (or -t)
99
+ agent-browser wait --url "**/dashboard" # Wait for URL pattern (or -u)
100
+ agent-browser wait --load networkidle # Wait for network idle (or -l)
101
+ agent-browser wait --fn "window.ready" # Wait for JS condition (or -f)
102
+ ```
103
+
104
+ ## Mouse Control
105
+
106
+ ```bash
107
+ agent-browser mouse move 100 200 # Move mouse
108
+ agent-browser mouse down left # Press button
109
+ agent-browser mouse up left # Release button
110
+ agent-browser mouse wheel 100 # Scroll wheel
111
+ ```
112
+
113
+ ## Semantic Locators (alternative to refs)
114
+
115
+ ```bash
116
+ agent-browser find role button click --name "Submit"
117
+ agent-browser find text "Sign In" click
118
+ agent-browser find text "Sign In" click --exact # Exact match only
119
+ agent-browser find label "Email" fill "user@test.com"
120
+ agent-browser find placeholder "Search" type "query"
121
+ agent-browser find alt "Logo" click
122
+ agent-browser find title "Close" click
123
+ agent-browser find testid "submit-btn" click
124
+ agent-browser find first ".item" click
125
+ agent-browser find last ".item" click
126
+ agent-browser find nth 2 "a" hover
127
+ ```
128
+
129
+ ## Browser Settings
130
+
131
+ ```bash
132
+ agent-browser set viewport 1920 1080 # Set viewport size
133
+ agent-browser set viewport 1920 1080 2 # 2x retina (same CSS size, higher res screenshots)
134
+ agent-browser set device "iPhone 14" # Emulate device
135
+ agent-browser set geo 37.7749 -122.4194 # Set geolocation (alias: geolocation)
136
+ agent-browser set offline on # Toggle offline mode
137
+ agent-browser set headers '{"X-Key":"v"}' # Extra HTTP headers
138
+ agent-browser set credentials user pass # HTTP basic auth (alias: auth)
139
+ agent-browser set media dark # Emulate color scheme
140
+ agent-browser set media light reduced-motion # Light mode + reduced motion
141
+ ```
142
+
143
+ ## Cookies and Storage
144
+
145
+ ```bash
146
+ agent-browser cookies # Get all cookies
147
+ agent-browser cookies set name value # Set cookie
148
+ agent-browser cookies clear # Clear cookies
149
+ agent-browser storage local # Get all localStorage
150
+ agent-browser storage local key # Get specific key
151
+ agent-browser storage local set k v # Set value
152
+ agent-browser storage local clear # Clear all
153
+ ```
154
+
155
+ ## Network
156
+
157
+ ```bash
158
+ agent-browser network route <url> # Intercept requests
159
+ agent-browser network route <url> --abort # Block requests
160
+ agent-browser network route <url> --body '{}' # Mock response
161
+ agent-browser network unroute [url] # Remove routes
162
+ agent-browser network requests # View tracked requests
163
+ agent-browser network requests --filter api # Filter requests
164
+ ```
165
+
166
+ ## Tabs and Windows
167
+
168
+ ```bash
169
+ agent-browser tab # List tabs
170
+ agent-browser tab new [url] # New tab
171
+ agent-browser tab 2 # Switch to tab by index
172
+ agent-browser tab close # Close current tab
173
+ agent-browser tab close 2 # Close tab by index
174
+ agent-browser window new # New window
175
+ ```
176
+
177
+ ## Frames
178
+
179
+ ```bash
180
+ agent-browser frame "#iframe" # Switch to iframe
181
+ agent-browser frame main # Back to main frame
182
+ ```
183
+
184
+ ## Dialogs
185
+
186
+ ```bash
187
+ agent-browser dialog accept [text] # Accept dialog
188
+ agent-browser dialog dismiss # Dismiss dialog
189
+ ```
190
+
191
+ ## JavaScript
192
+
193
+ ```bash
194
+ agent-browser eval "document.title" # Simple expressions only
195
+ agent-browser eval -b "<base64>" # Any JavaScript (base64 encoded)
196
+ agent-browser eval --stdin # Read script from stdin
197
+ ```
198
+
199
+ Use `-b`/`--base64` or `--stdin` for reliable execution. Shell escaping with nested quotes and special characters is error-prone.
200
+
201
+ ```bash
202
+ # Base64 encode your script, then:
203
+ agent-browser eval -b "ZG9jdW1lbnQucXVlcnlTZWxlY3RvcignW3NyYyo9Il9uZXh0Il0nKQ=="
204
+
205
+ # Or use stdin with heredoc for multiline scripts:
206
+ cat <<'EOF' | agent-browser eval --stdin
207
+ const links = document.querySelectorAll('a');
208
+ Array.from(links).map(a => a.href);
209
+ EOF
210
+ ```
211
+
212
+ ## State Management
213
+
214
+ ```bash
215
+ agent-browser state save auth.json # Save cookies, storage, auth state
216
+ agent-browser state load auth.json # Restore saved state
217
+ ```
218
+
219
+ ## Global Options
220
+
221
+ ```bash
222
+ agent-browser --session <name> ... # Isolated browser session
223
+ agent-browser --json ... # JSON output for parsing
224
+ agent-browser --headed ... # Show browser window (not headless)
225
+ agent-browser --full ... # Full page screenshot (-f)
226
+ agent-browser --cdp <port> ... # Connect via Chrome DevTools Protocol
227
+ agent-browser -p <provider> ... # Cloud browser provider (--provider)
228
+ agent-browser --proxy <url> ... # Use proxy server
229
+ agent-browser --proxy-bypass <hosts> # Hosts to bypass proxy
230
+ agent-browser --headers <json> ... # HTTP headers scoped to URL's origin
231
+ agent-browser --executable-path <p> # Custom browser executable
232
+ agent-browser --extension <path> ... # Load browser extension (repeatable)
233
+ agent-browser --ignore-https-errors # Ignore SSL certificate errors
234
+ agent-browser --help # Show help (-h)
235
+ agent-browser --version # Show version (-V)
236
+ agent-browser <command> --help # Show detailed help for a command
237
+ ```
238
+
239
+ ## Debugging
240
+
241
+ ```bash
242
+ agent-browser --headed open example.com # Show browser window
243
+ agent-browser --cdp 9222 snapshot # Connect via CDP port
244
+ agent-browser connect 9222 # Alternative: connect command
245
+ agent-browser console # View console messages
246
+ agent-browser console --clear # Clear console
247
+ agent-browser errors # View page errors
248
+ agent-browser errors --clear # Clear errors
249
+ agent-browser highlight @e1 # Highlight element
250
+ agent-browser inspect # Open Chrome DevTools for this session
251
+ agent-browser trace start # Start recording trace
252
+ agent-browser trace stop trace.zip # Stop and save trace
253
+ agent-browser profiler start # Start Chrome DevTools profiling
254
+ agent-browser profiler stop trace.json # Stop and save profile
255
+ ```
256
+
257
+ ## Environment Variables
258
+
259
+ ```bash
260
+ AGENT_BROWSER_SESSION="mysession" # Default session name
261
+ AGENT_BROWSER_EXECUTABLE_PATH="/path/chrome" # Custom browser path
262
+ AGENT_BROWSER_EXTENSIONS="/ext1,/ext2" # Comma-separated extension paths
263
+ AGENT_BROWSER_PROVIDER="browserbase" # Cloud browser provider
264
+ AGENT_BROWSER_STREAM_PORT="9223" # WebSocket streaming port
265
+ AGENT_BROWSER_HOME="/path/to/agent-browser" # Custom install location
266
+ ```
@@ -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.