prose-qa 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/dist/agent/bash.d.ts +1 -1
  2. package/dist/agent/bash.d.ts.map +1 -1
  3. package/dist/agent/bash.js +23 -4
  4. package/dist/agent/bash.js.map +1 -1
  5. package/dist/agent/bash.test.js +27 -3
  6. package/dist/agent/bash.test.js.map +1 -1
  7. package/dist/agent/prompt.d.ts.map +1 -1
  8. package/dist/agent/prompt.js +9 -1
  9. package/dist/agent/prompt.js.map +1 -1
  10. package/dist/agent/runner.d.ts.map +1 -1
  11. package/dist/agent/runner.js +80 -12
  12. package/dist/agent/runner.js.map +1 -1
  13. package/dist/agent/runner.test.d.ts +2 -0
  14. package/dist/agent/runner.test.d.ts.map +1 -0
  15. package/dist/agent/runner.test.js +83 -0
  16. package/dist/agent/runner.test.js.map +1 -0
  17. package/dist/agent/transcript-persist.d.ts +9 -0
  18. package/dist/agent/transcript-persist.d.ts.map +1 -0
  19. package/dist/agent/transcript-persist.js +6 -0
  20. package/dist/agent/transcript-persist.js.map +1 -0
  21. package/dist/agent/transcript-persist.test.d.ts +2 -0
  22. package/dist/agent/transcript-persist.test.d.ts.map +1 -0
  23. package/dist/agent/transcript-persist.test.js +56 -0
  24. package/dist/agent/transcript-persist.test.js.map +1 -0
  25. package/dist/agent/verdict.d.ts +8 -2
  26. package/dist/agent/verdict.d.ts.map +1 -1
  27. package/dist/agent/verdict.js +49 -0
  28. package/dist/agent/verdict.js.map +1 -1
  29. package/dist/agent/verdict.test.js +85 -1
  30. package/dist/agent/verdict.test.js.map +1 -1
  31. package/dist/cli/help.d.ts.map +1 -1
  32. package/dist/cli/help.js +53 -17
  33. package/dist/cli/help.js.map +1 -1
  34. package/dist/cli/help.test.js +1 -0
  35. package/dist/cli/help.test.js.map +1 -1
  36. package/dist/cli/index.js +18 -1
  37. package/dist/cli/index.js.map +1 -1
  38. package/dist/cli/install-browser.d.ts +3 -0
  39. package/dist/cli/install-browser.d.ts.map +1 -0
  40. package/dist/cli/install-browser.js +42 -0
  41. package/dist/cli/install-browser.js.map +1 -0
  42. package/dist/cli/install-browser.test.d.ts +2 -0
  43. package/dist/cli/install-browser.test.d.ts.map +1 -0
  44. package/dist/cli/install-browser.test.js +19 -0
  45. package/dist/cli/install-browser.test.js.map +1 -0
  46. package/dist/cli/run.d.ts.map +1 -1
  47. package/dist/cli/run.js +20 -15
  48. package/dist/cli/run.js.map +1 -1
  49. package/dist/config/lightpanda.d.ts +8 -0
  50. package/dist/config/lightpanda.d.ts.map +1 -1
  51. package/dist/config/lightpanda.js +41 -4
  52. package/dist/config/lightpanda.js.map +1 -1
  53. package/dist/config/lightpanda.test.js +30 -1
  54. package/dist/config/lightpanda.test.js.map +1 -1
  55. package/dist/config/load.d.ts.map +1 -1
  56. package/dist/config/load.js +14 -6
  57. package/dist/config/load.js.map +1 -1
  58. package/dist/config/load.test.js +29 -0
  59. package/dist/config/load.test.js.map +1 -1
  60. package/dist/mcp/server.d.ts.map +1 -1
  61. package/dist/mcp/server.js +2 -1
  62. package/dist/mcp/server.js.map +1 -1
  63. package/dist/redact/env-secrets.d.ts.map +1 -1
  64. package/dist/redact/env-secrets.js +1 -0
  65. package/dist/redact/env-secrets.js.map +1 -1
  66. package/dist/reporter/index.d.ts.map +1 -1
  67. package/dist/reporter/index.js +6 -2
  68. package/dist/reporter/index.js.map +1 -1
  69. package/dist/reporter/index.test.js +59 -1
  70. package/dist/reporter/index.test.js.map +1 -1
  71. package/dist/skills/loader.d.ts +8 -1
  72. package/dist/skills/loader.d.ts.map +1 -1
  73. package/dist/skills/loader.js +31 -5
  74. package/dist/skills/loader.js.map +1 -1
  75. package/dist/skills/loader.test.d.ts +2 -0
  76. package/dist/skills/loader.test.d.ts.map +1 -0
  77. package/dist/skills/loader.test.js +40 -0
  78. package/dist/skills/loader.test.js.map +1 -0
  79. package/dist/skills/on-demand.d.ts +57 -0
  80. package/dist/skills/on-demand.d.ts.map +1 -0
  81. package/dist/skills/on-demand.js +225 -0
  82. package/dist/skills/on-demand.js.map +1 -0
  83. package/dist/skills/on-demand.test.d.ts +2 -0
  84. package/dist/skills/on-demand.test.d.ts.map +1 -0
  85. package/dist/skills/on-demand.test.js +111 -0
  86. package/dist/skills/on-demand.test.js.map +1 -0
  87. package/dist/types/config.d.ts +14 -3
  88. package/dist/types/config.d.ts.map +1 -1
  89. package/dist/types/verdict.d.ts +21 -1
  90. package/dist/types/verdict.d.ts.map +1 -1
  91. package/dist/types/verdict.js +16 -0
  92. package/dist/types/verdict.js.map +1 -1
  93. package/dist/version.d.ts +3 -0
  94. package/dist/version.d.ts.map +1 -0
  95. package/dist/version.js +6 -0
  96. package/dist/version.js.map +1 -0
  97. package/package.json +6 -4
  98. package/pqa.config.ts +8 -3
  99. package/prompt/SYSTEM.md +2 -1
  100. package/scripts/install-lightpanda.mjs +161 -0
  101. package/scripts/sync-skills.mjs +110 -0
  102. package/skills/agent-browser/SKILL.md +0 -1960
  103. package/skills/agent-browser/bundled/agentcore/SKILL.md +115 -0
  104. package/skills/agent-browser/bundled/dogfood/SKILL.md +220 -0
  105. package/skills/agent-browser/bundled/dogfood/references/issue-taxonomy.md +109 -0
  106. package/skills/agent-browser/bundled/dogfood/templates/dogfood-report-template.md +53 -0
  107. package/skills/agent-browser/bundled/electron/SKILL.md +236 -0
  108. package/skills/agent-browser/bundled/slack/SKILL.md +285 -0
  109. package/skills/agent-browser/bundled/slack/references/slack-tasks.md +348 -0
  110. package/skills/agent-browser/bundled/slack/templates/slack-report-template.md +163 -0
  111. package/skills/agent-browser/bundled/vercel-sandbox/SKILL.md +280 -0
  112. package/skills/agent-browser/manifest.json +42 -0
  113. package/skills/agent-browser/references/authentication.md +303 -0
  114. package/skills/agent-browser/references/commands.md +398 -0
  115. package/skills/agent-browser/references/profiling.md +120 -0
  116. package/skills/agent-browser/references/proxy-support.md +194 -0
  117. package/skills/agent-browser/references/session-management.md +193 -0
  118. package/skills/agent-browser/references/snapshot-refs.md +219 -0
  119. package/skills/agent-browser/references/trust-boundaries.md +89 -0
  120. package/skills/agent-browser/references/video-recording.md +175 -0
  121. package/skills/agent-browser/templates/authenticated-session.sh +105 -0
  122. package/skills/agent-browser/templates/capture-workflow.sh +69 -0
  123. package/skills/agent-browser/templates/form-automation.sh +62 -0
@@ -0,0 +1,280 @@
1
+ ---
2
+ name: vercel-sandbox
3
+ description: Run agent-browser + Chrome inside Vercel Sandbox microVMs for browser automation from any Vercel-deployed app. Use when the user needs browser automation in a Vercel app (Next.js, SvelteKit, Nuxt, Remix, Astro, etc.), wants to run headless Chrome without binary size limits, needs persistent browser sessions across commands, or wants ephemeral isolated browser environments. Triggers include "Vercel Sandbox browser", "microVM Chrome", "agent-browser in sandbox", "browser automation on Vercel", or any task requiring Chrome in a Vercel Sandbox.
4
+ ---
5
+
6
+ # Browser Automation with Vercel Sandbox
7
+
8
+ Run agent-browser + headless Chrome inside ephemeral Vercel Sandbox microVMs. A Linux VM spins up on demand, executes browser commands, and shuts down. Works with any Vercel-deployed framework (Next.js, SvelteKit, Nuxt, Remix, Astro, etc.).
9
+
10
+ ## Dependencies
11
+
12
+ ```bash
13
+ pnpm add @vercel/sandbox
14
+ ```
15
+
16
+ The sandbox VM needs system dependencies for Chromium plus agent-browser itself. Use sandbox snapshots (below) to pre-install everything for sub-second startup.
17
+
18
+ ## Core Pattern
19
+
20
+ ```ts
21
+ import { Sandbox } from "@vercel/sandbox";
22
+
23
+ // System libraries required by Chromium on the sandbox VM (Amazon Linux / dnf)
24
+ const CHROMIUM_SYSTEM_DEPS = [
25
+ "nss", "nspr", "libxkbcommon", "atk", "at-spi2-atk", "at-spi2-core",
26
+ "libXcomposite", "libXdamage", "libXrandr", "libXfixes", "libXcursor",
27
+ "libXi", "libXtst", "libXScrnSaver", "libXext", "mesa-libgbm", "libdrm",
28
+ "mesa-libGL", "mesa-libEGL", "cups-libs", "alsa-lib", "pango", "cairo",
29
+ "gtk3", "dbus-libs",
30
+ ];
31
+
32
+ function getSandboxCredentials() {
33
+ if (
34
+ process.env.VERCEL_TOKEN &&
35
+ process.env.VERCEL_TEAM_ID &&
36
+ process.env.VERCEL_PROJECT_ID
37
+ ) {
38
+ return {
39
+ token: process.env.VERCEL_TOKEN,
40
+ teamId: process.env.VERCEL_TEAM_ID,
41
+ projectId: process.env.VERCEL_PROJECT_ID,
42
+ };
43
+ }
44
+ return {};
45
+ }
46
+
47
+ async function withBrowser<T>(
48
+ fn: (sandbox: InstanceType<typeof Sandbox>) => Promise<T>,
49
+ ): Promise<T> {
50
+ const snapshotId = process.env.AGENT_BROWSER_SNAPSHOT_ID;
51
+ const credentials = getSandboxCredentials();
52
+
53
+ const sandbox = snapshotId
54
+ ? await Sandbox.create({
55
+ ...credentials,
56
+ source: { type: "snapshot", snapshotId },
57
+ timeout: 120_000,
58
+ })
59
+ : await Sandbox.create({ ...credentials, runtime: "node24", timeout: 120_000 });
60
+
61
+ if (!snapshotId) {
62
+ await sandbox.runCommand("sh", [
63
+ "-c",
64
+ `sudo dnf clean all 2>&1 && sudo dnf install -y --skip-broken ${CHROMIUM_SYSTEM_DEPS.join(" ")} 2>&1 && sudo ldconfig 2>&1`,
65
+ ]);
66
+ await sandbox.runCommand("npm", ["install", "-g", "agent-browser"]);
67
+ await sandbox.runCommand("npx", ["agent-browser", "install"]);
68
+ }
69
+
70
+ try {
71
+ return await fn(sandbox);
72
+ } finally {
73
+ await sandbox.stop();
74
+ }
75
+ }
76
+ ```
77
+
78
+ ## Screenshot
79
+
80
+ The `screenshot --json` command saves to a file and returns the path. Read the file back as base64:
81
+
82
+ ```ts
83
+ export async function screenshotUrl(url: string) {
84
+ return withBrowser(async (sandbox) => {
85
+ await sandbox.runCommand("agent-browser", ["open", url]);
86
+
87
+ const titleResult = await sandbox.runCommand("agent-browser", [
88
+ "get", "title", "--json",
89
+ ]);
90
+ const title = JSON.parse(await titleResult.stdout())?.data?.title || url;
91
+
92
+ const ssResult = await sandbox.runCommand("agent-browser", [
93
+ "screenshot", "--json",
94
+ ]);
95
+ const ssPath = JSON.parse(await ssResult.stdout())?.data?.path;
96
+ const b64Result = await sandbox.runCommand("base64", ["-w", "0", ssPath]);
97
+ const screenshot = (await b64Result.stdout()).trim();
98
+
99
+ await sandbox.runCommand("agent-browser", ["close"]);
100
+
101
+ return { title, screenshot };
102
+ });
103
+ }
104
+ ```
105
+
106
+ ## Accessibility Snapshot
107
+
108
+ ```ts
109
+ export async function snapshotUrl(url: string) {
110
+ return withBrowser(async (sandbox) => {
111
+ await sandbox.runCommand("agent-browser", ["open", url]);
112
+
113
+ const titleResult = await sandbox.runCommand("agent-browser", [
114
+ "get", "title", "--json",
115
+ ]);
116
+ const title = JSON.parse(await titleResult.stdout())?.data?.title || url;
117
+
118
+ const snapResult = await sandbox.runCommand("agent-browser", [
119
+ "snapshot", "-i", "-c",
120
+ ]);
121
+ const snapshot = await snapResult.stdout();
122
+
123
+ await sandbox.runCommand("agent-browser", ["close"]);
124
+
125
+ return { title, snapshot };
126
+ });
127
+ }
128
+ ```
129
+
130
+ ## Multi-Step Workflows
131
+
132
+ The sandbox persists between commands, so you can run full automation sequences:
133
+
134
+ ```ts
135
+ export async function fillAndSubmitForm(url: string, data: Record<string, string>) {
136
+ return withBrowser(async (sandbox) => {
137
+ await sandbox.runCommand("agent-browser", ["open", url]);
138
+
139
+ const snapResult = await sandbox.runCommand("agent-browser", [
140
+ "snapshot", "-i",
141
+ ]);
142
+ const snapshot = await snapResult.stdout();
143
+ // Parse snapshot to find element refs...
144
+
145
+ for (const [ref, value] of Object.entries(data)) {
146
+ await sandbox.runCommand("agent-browser", ["fill", ref, value]);
147
+ }
148
+
149
+ await sandbox.runCommand("agent-browser", ["click", "@e5"]);
150
+ await sandbox.runCommand("agent-browser", ["wait", "--load", "networkidle"]);
151
+
152
+ const ssResult = await sandbox.runCommand("agent-browser", [
153
+ "screenshot", "--json",
154
+ ]);
155
+ const ssPath = JSON.parse(await ssResult.stdout())?.data?.path;
156
+ const b64Result = await sandbox.runCommand("base64", ["-w", "0", ssPath]);
157
+ const screenshot = (await b64Result.stdout()).trim();
158
+
159
+ await sandbox.runCommand("agent-browser", ["close"]);
160
+
161
+ return { screenshot };
162
+ });
163
+ }
164
+ ```
165
+
166
+ ## Sandbox Snapshots (Fast Startup)
167
+
168
+ A **sandbox snapshot** is a saved VM image of a Vercel Sandbox with system dependencies + agent-browser + Chromium already installed. Think of it like a Docker image -- instead of installing dependencies from scratch every time, the sandbox boots from the pre-built image.
169
+
170
+ This is unrelated to agent-browser's *accessibility snapshot* feature (`agent-browser snapshot`), which dumps a page's accessibility tree. A sandbox snapshot is a Vercel infrastructure concept for fast VM startup.
171
+
172
+ Without a sandbox snapshot, each run installs system deps + agent-browser + Chromium (~30s). With one, startup is sub-second.
173
+
174
+ ### Creating a sandbox snapshot
175
+
176
+ The snapshot must include system dependencies (via `dnf`), agent-browser, and Chromium:
177
+
178
+ ```ts
179
+ import { Sandbox } from "@vercel/sandbox";
180
+
181
+ const CHROMIUM_SYSTEM_DEPS = [
182
+ "nss", "nspr", "libxkbcommon", "atk", "at-spi2-atk", "at-spi2-core",
183
+ "libXcomposite", "libXdamage", "libXrandr", "libXfixes", "libXcursor",
184
+ "libXi", "libXtst", "libXScrnSaver", "libXext", "mesa-libgbm", "libdrm",
185
+ "mesa-libGL", "mesa-libEGL", "cups-libs", "alsa-lib", "pango", "cairo",
186
+ "gtk3", "dbus-libs",
187
+ ];
188
+
189
+ async function createSnapshot(): Promise<string> {
190
+ const sandbox = await Sandbox.create({
191
+ runtime: "node24",
192
+ timeout: 300_000,
193
+ });
194
+
195
+ await sandbox.runCommand("sh", [
196
+ "-c",
197
+ `sudo dnf clean all 2>&1 && sudo dnf install -y --skip-broken ${CHROMIUM_SYSTEM_DEPS.join(" ")} 2>&1 && sudo ldconfig 2>&1`,
198
+ ]);
199
+ await sandbox.runCommand("npm", ["install", "-g", "agent-browser"]);
200
+ await sandbox.runCommand("npx", ["agent-browser", "install"]);
201
+
202
+ const snapshot = await sandbox.snapshot();
203
+ return snapshot.snapshotId;
204
+ }
205
+ ```
206
+
207
+ Run this once, then set the environment variable:
208
+
209
+ ```bash
210
+ AGENT_BROWSER_SNAPSHOT_ID=snap_xxxxxxxxxxxx
211
+ ```
212
+
213
+ A helper script is available in the demo app:
214
+
215
+ ```bash
216
+ npx tsx examples/environments/scripts/create-snapshot.ts
217
+ ```
218
+
219
+ Recommended for any production deployment using the Sandbox pattern.
220
+
221
+ ## Authentication
222
+
223
+ On Vercel deployments, the Sandbox SDK authenticates automatically via OIDC. For local development or explicit control, set:
224
+
225
+ ```bash
226
+ VERCEL_TOKEN=<personal-access-token>
227
+ VERCEL_TEAM_ID=<team-id>
228
+ VERCEL_PROJECT_ID=<project-id>
229
+ ```
230
+
231
+ These are spread into `Sandbox.create()` calls. When absent, the SDK falls back to `VERCEL_OIDC_TOKEN` (automatic on Vercel).
232
+
233
+ ## Scheduled Workflows (Cron)
234
+
235
+ Combine with Vercel Cron Jobs for recurring browser tasks:
236
+
237
+ ```ts
238
+ // app/api/cron/route.ts (or equivalent in your framework)
239
+ export async function GET() {
240
+ const result = await withBrowser(async (sandbox) => {
241
+ await sandbox.runCommand("agent-browser", ["open", "https://example.com/pricing"]);
242
+ const snap = await sandbox.runCommand("agent-browser", ["snapshot", "-i", "-c"]);
243
+ await sandbox.runCommand("agent-browser", ["close"]);
244
+ return await snap.stdout();
245
+ });
246
+
247
+ // Process results, send alerts, store data...
248
+ return Response.json({ ok: true, snapshot: result });
249
+ }
250
+ ```
251
+
252
+ ```json
253
+ // vercel.json
254
+ { "crons": [{ "path": "/api/cron", "schedule": "0 9 * * *" }] }
255
+ ```
256
+
257
+ ## Environment Variables
258
+
259
+ | Variable | Required | Description |
260
+ |---|---|---|
261
+ | `AGENT_BROWSER_SNAPSHOT_ID` | No (but recommended) | Pre-built sandbox snapshot ID for sub-second startup (see above) |
262
+ | `VERCEL_TOKEN` | No | Vercel personal access token (for local dev; OIDC is automatic on Vercel) |
263
+ | `VERCEL_TEAM_ID` | No | Vercel team ID (for local dev) |
264
+ | `VERCEL_PROJECT_ID` | No | Vercel project ID (for local dev) |
265
+
266
+ ## Framework Examples
267
+
268
+ The pattern works identically across frameworks. The only difference is where you put the server-side code:
269
+
270
+ | Framework | Server code location |
271
+ |---|---|
272
+ | Next.js | Server actions, API routes, route handlers |
273
+ | SvelteKit | `+page.server.ts`, `+server.ts` |
274
+ | Nuxt | `server/api/`, `server/routes/` |
275
+ | Remix | `loader`, `action` functions |
276
+ | Astro | `.astro` frontmatter, API routes |
277
+
278
+ ## Example
279
+
280
+ See `examples/environments/` in the agent-browser repo for a working app with the Vercel Sandbox pattern, including a sandbox snapshot creation script, streaming progress UI, and rate limiting.
@@ -0,0 +1,42 @@
1
+ {
2
+ "version": 1,
3
+ "core": {
4
+ "references": [
5
+ "authentication",
6
+ "commands",
7
+ "profiling",
8
+ "proxy-support",
9
+ "session-management",
10
+ "snapshot-refs",
11
+ "trust-boundaries",
12
+ "video-recording"
13
+ ],
14
+ "templates": [
15
+ "authenticated-session",
16
+ "capture-workflow",
17
+ "form-automation"
18
+ ]
19
+ },
20
+ "bundled": [
21
+ {
22
+ "name": "agentcore",
23
+ "description": "Run agent-browser on AWS Bedrock AgentCore cloud browsers. Use when the user wants to use AgentCore, run browser automation on AWS, use a cloud browser with AWS credentials, or needs a managed browser session backed by AWS infrastructure. Triggers include \"use agentcore\", \"run on AWS\", \"cloud browser with AWS\", \"bedrock browser\", \"agentcore session\", or any task requiring AWS-hosted browser automation."
24
+ },
25
+ {
26
+ "name": "dogfood",
27
+ "description": "Systematically explore and test a web application to find bugs, UX issues, and other problems. Use when asked to \"dogfood\", \"QA\", \"exploratory test\", \"find issues\", \"bug hunt\", \"test this app/site/platform\", or review the quality of a web application. Produces a structured report with full reproduction evidence -- step-by-step screenshots, repro videos, and detailed repro steps for every issue -- so findings can be handed directly to the responsible teams."
28
+ },
29
+ {
30
+ "name": "electron",
31
+ "description": "Automate Electron desktop apps (VS Code, Slack, Discord, Figma, Notion, Spotify, etc.) using agent-browser via Chrome DevTools Protocol. Use when the user needs to interact with an Electron app, automate a desktop app, connect to a running app, control a native app, or test an Electron application. Triggers include \"automate Slack app\", \"control VS Code\", \"interact with Discord app\", \"test this Electron app\", \"connect to desktop app\", or any task requiring automation of a native Electron application."
32
+ },
33
+ {
34
+ "name": "slack",
35
+ "description": "Interact with Slack workspaces using browser automation. Use when the user needs to check unread channels, navigate Slack, send messages, extract data, find information, search conversations, or automate any Slack task. Triggers include \"check my Slack\", \"what channels have unreads\", \"send a message to\", \"search Slack for\", \"extract from Slack\", \"find who said\", or any task requiring programmatic Slack interaction."
36
+ },
37
+ {
38
+ "name": "vercel-sandbox",
39
+ "description": "Run agent-browser + Chrome inside Vercel Sandbox microVMs for browser automation from any Vercel-deployed app. Use when the user needs browser automation in a Vercel app (Next.js, SvelteKit, Nuxt, Remix, Astro, etc.), wants to run headless Chrome without binary size limits, needs persistent browser sessions across commands, or wants ephemeral isolated browser environments. Triggers include \"Vercel Sandbox browser\", \"microVM Chrome\", \"agent-browser in sandbox\", \"browser automation on Vercel\", or any task requiring Chrome in a Vercel Sandbox."
40
+ }
41
+ ]
42
+ }
@@ -0,0 +1,303 @@
1
+ # Authentication Patterns
2
+
3
+ Login flows, session persistence, OAuth, 2FA, and authenticated browsing.
4
+
5
+ **Related**: [session-management.md](session-management.md) for state persistence details, [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
+ ```