slipwing 0.0.0-stage → 0.1.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.
- package/LICENSE +202 -0
- package/README.md +143 -3
- package/bin/agent-desktop-win32-x64.exe +0 -0
- package/bin/workflow.js +512 -0
- package/browser/LICENSE +201 -0
- package/browser/LICENSE-axe-core-THIRD-PARTY.txt +66 -0
- package/browser/LICENSE-axe-core.txt +362 -0
- package/browser/bin/agent-browser-win32-x64.exe +0 -0
- package/browser/skill-data/agentcore/SKILL.md +115 -0
- package/browser/skill-data/core/SKILL.md +279 -0
- package/browser/skill-data/core/references/authentication.md +413 -0
- package/browser/skill-data/core/references/commands.md +727 -0
- package/browser/skill-data/core/references/profiling.md +120 -0
- package/browser/skill-data/core/references/proxy-support.md +221 -0
- package/browser/skill-data/core/references/session-management.md +215 -0
- package/browser/skill-data/core/references/snapshot-refs.md +244 -0
- package/browser/skill-data/core/references/streaming.md +107 -0
- package/browser/skill-data/core/references/trust-boundaries.md +69 -0
- package/browser/skill-data/core/references/video-recording.md +254 -0
- package/browser/skill-data/core/references/webgpu.md +118 -0
- package/browser/skill-data/core/templates/authenticated-session.sh +109 -0
- package/browser/skill-data/core/templates/capture-workflow.sh +69 -0
- package/browser/skill-data/core/templates/form-automation.sh +63 -0
- package/browser/skill-data/derive-client/SKILL.md +88 -0
- package/browser/skill-data/dogfood/SKILL.md +224 -0
- package/browser/skill-data/dogfood/references/issue-taxonomy.md +109 -0
- package/browser/skill-data/dogfood/templates/dogfood-report-template.md +53 -0
- package/browser/skill-data/electron/SKILL.md +236 -0
- package/browser/skill-data/modern-web-guidance/SKILL.md +165 -0
- package/browser/skill-data/slack/SKILL.md +288 -0
- package/browser/skill-data/slack/references/slack-tasks.md +349 -0
- package/browser/skill-data/slack/templates/slack-report-template.md +163 -0
- package/browser/skill-data/vercel/SKILL.md +160 -0
- package/browser/skill-data/vercel-sandbox/SKILL.md +237 -0
- package/browser/skill-data/webmcp-gen/SKILL.md +52 -0
- package/browser/skills/agent-browser/SKILL.md +51 -0
- package/bundle.json +19 -0
- package/lib/browser-move.js +185 -0
- package/lib/bundle-version.js +32 -0
- package/lib/choose.js +382 -0
- package/lib/cli-options.js +47 -0
- package/lib/control-changes.js +47 -0
- package/lib/current-page.js +165 -0
- package/lib/error-code.js +19 -0
- package/lib/final-picture.js +31 -0
- package/lib/final-words.json +7 -0
- package/lib/flow-record.js +32 -0
- package/lib/host-client.js +65 -0
- package/lib/host-command.js +175 -0
- package/lib/host-paths.js +22 -0
- package/lib/host-server.js +383 -0
- package/lib/host-waits.js +12 -0
- package/lib/host-watch.js +340 -0
- package/lib/mcp-guide.js +45 -0
- package/lib/mcp-server.js +264 -0
- package/lib/notify.js +31 -0
- package/lib/page-choice.js +273 -0
- package/lib/page-input.js +141 -0
- package/lib/page-lease.js +87 -0
- package/lib/page-line.js +83 -0
- package/lib/page-pointer.js +191 -0
- package/lib/page-read.js +44 -0
- package/lib/platform.js +89 -0
- package/lib/png-mark.js +83 -0
- package/lib/prefs.js +228 -0
- package/lib/routine-approvals.js +67 -0
- package/lib/routine-command.js +150 -0
- package/lib/routine-effects.js +119 -0
- package/lib/routine-store.js +143 -0
- package/lib/script-args.js +48 -0
- package/lib/script-call.js +63 -0
- package/lib/script-desktop.js +731 -0
- package/lib/script-final.js +93 -0
- package/lib/script-fix.js +121 -0
- package/lib/script-input.js +25 -0
- package/lib/script-match.js +90 -0
- package/lib/script-picture.js +104 -0
- package/lib/script-repeat.js +43 -0
- package/lib/script-run.js +367 -0
- package/lib/script-screen.js +53 -0
- package/lib/script-visible.js +228 -0
- package/lib/script-wait.js +15 -0
- package/lib/script-web.js +338 -0
- package/lib/skill-command.js +81 -0
- package/lib/space.js +56 -0
- package/lib/text-match.js +18 -0
- package/lib/watch-helper.ps1 +200 -0
- package/lib/web-page.js +214 -0
- package/lib/window-move.js +213 -0
- package/lib/windows-bin.js +44 -0
- package/package.json +32 -5
- package/scripts/initialize-state.ps1 +13 -0
- package/skills/slipwing/SKILL.md +189 -0
- package/skills/slipwing/chrome.md +62 -0
- package/skills/slipwing/desktop.md +82 -0
- package/skills/slipwing/human.md +63 -0
- package/skills/slipwing/jobs.md +82 -0
- package/skills/slipwing/routines.md +73 -0
- package/skills/slipwing/watches.md +37 -0
|
@@ -0,0 +1,413 @@
|
|
|
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
|
+
- [Plugins](#plugins)
|
|
14
|
+
- [Saving Authentication State](#saving-authentication-state)
|
|
15
|
+
- [Restoring Authentication](#restoring-authentication)
|
|
16
|
+
- [OAuth / SSO Flows](#oauth--sso-flows)
|
|
17
|
+
- [Two-Factor Authentication](#two-factor-authentication)
|
|
18
|
+
- [HTTP Basic Auth](#http-basic-auth)
|
|
19
|
+
- [Cookie-Based Auth](#cookie-based-auth)
|
|
20
|
+
- [Token Refresh Handling](#token-refresh-handling)
|
|
21
|
+
- [Security Best Practices](#security-best-practices)
|
|
22
|
+
|
|
23
|
+
## Import Auth from Your Browser
|
|
24
|
+
|
|
25
|
+
The fastest way to authenticate is to reuse cookies from a Chrome session you are already logged into.
|
|
26
|
+
|
|
27
|
+
**Step 1: Start Chrome with remote debugging**
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# macOS
|
|
31
|
+
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --remote-debugging-port=9222
|
|
32
|
+
|
|
33
|
+
# Linux
|
|
34
|
+
google-chrome --remote-debugging-port=9222
|
|
35
|
+
|
|
36
|
+
# Windows
|
|
37
|
+
"C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Log in to your target site(s) in this Chrome window as you normally would.
|
|
41
|
+
|
|
42
|
+
> **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.
|
|
43
|
+
|
|
44
|
+
**Step 2: Grab the auth state**
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# Auto-discover the running Chrome and save its cookies + localStorage
|
|
48
|
+
agent-browser --auto-connect state save ./my-auth.json
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**Step 3: Reuse in automation**
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
# Load auth at launch
|
|
55
|
+
agent-browser --state ./my-auth.json open https://app.example.com/dashboard
|
|
56
|
+
|
|
57
|
+
# Or load into an already-launched session
|
|
58
|
+
agent-browser open about:blank
|
|
59
|
+
agent-browser state load ./my-auth.json
|
|
60
|
+
agent-browser open https://app.example.com/dashboard
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
This works for any site, including those with complex OAuth flows, SSO, or 2FA, as long as Chrome already has valid session cookies.
|
|
64
|
+
|
|
65
|
+
Saved localStorage and sessionStorage are written through Chrome DevTools, not page JavaScript, and only while the page is on the saved origin. If an origin redirects elsewhere or fails to load, its storage is skipped, the rest still loads, and `state load` lists it under `skippedOrigins`. For `--state` and `--restore` at launch, `session info` lists it under `restoreSkippedOrigins`.
|
|
66
|
+
|
|
67
|
+
> **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).
|
|
68
|
+
|
|
69
|
+
**Tip:** Combine with `--session <id> --restore` so the imported auth auto-persists across restarts:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
SESSION="$(agent-browser session id --scope worktree --prefix myapp)"
|
|
73
|
+
agent-browser --session "$SESSION" --restore --state ./my-auth.json open https://app.example.com/dashboard
|
|
74
|
+
# From now on, state is auto-saved/restored for this session
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Persistent Profiles
|
|
78
|
+
|
|
79
|
+
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:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# First run: login once
|
|
83
|
+
agent-browser --profile ~/.myapp-profile open https://app.example.com/login
|
|
84
|
+
# ... complete login flow ...
|
|
85
|
+
|
|
86
|
+
# All subsequent runs: already authenticated
|
|
87
|
+
agent-browser --profile ~/.myapp-profile open https://app.example.com/dashboard
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Use different paths for different projects or test users:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
agent-browser --profile ~/.profiles/admin open https://app.example.com
|
|
94
|
+
agent-browser --profile ~/.profiles/viewer open https://app.example.com
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Or set via environment variable:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
export AGENT_BROWSER_PROFILE=~/.myapp-profile
|
|
101
|
+
agent-browser open https://app.example.com/dashboard
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Session Persistence
|
|
105
|
+
|
|
106
|
+
Use `--restore` with a stable `--session` to auto-save and restore cookies + localStorage without managing files:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
# Auto-saves state on close, auto-restores on next launch
|
|
110
|
+
SESSION="$(agent-browser session id --scope worktree --prefix twitter)"
|
|
111
|
+
agent-browser --session "$SESSION" --restore open https://twitter.com
|
|
112
|
+
# ... login flow ...
|
|
113
|
+
agent-browser --session "$SESSION" --restore close # state saved to ~/.agent-browser/sessions/
|
|
114
|
+
|
|
115
|
+
# Next time: state is automatically restored
|
|
116
|
+
agent-browser --session "$SESSION" --restore open https://twitter.com
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Encrypt state at rest:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
export AGENT_BROWSER_ENCRYPTION_KEY=$(openssl rand -hex 32)
|
|
123
|
+
agent-browser --session secure --restore open https://app.example.com
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Basic Login Flow
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
# Navigate to login page
|
|
130
|
+
agent-browser open https://app.example.com/login
|
|
131
|
+
agent-browser wait --load domcontentloaded
|
|
132
|
+
agent-browser wait --fn "(() => { const usable = (el) => { const style = getComputedStyle(el); return !el.disabled && !el.readOnly && style.display !== 'none' && style.visibility !== 'hidden' && el.getClientRects().length > 0; }; const username = Array.from(document.querySelectorAll('input[type=email], input[type=text], input[autocomplete=username], input[name*=email i], input[name*=user i], input[name*=login i]')).some(usable); const password = Array.from(document.querySelectorAll('input[type=password]')).some(usable); return username && password; })()"
|
|
133
|
+
|
|
134
|
+
# Get form elements
|
|
135
|
+
agent-browser snapshot -i
|
|
136
|
+
# Output: @e1 [input type="email"], @e2 [input type="password"], @e3 [button] "Sign In"
|
|
137
|
+
|
|
138
|
+
# Fill credentials
|
|
139
|
+
agent-browser fill @e1 "user@example.com"
|
|
140
|
+
agent-browser fill @e2 "password123"
|
|
141
|
+
|
|
142
|
+
# Submit
|
|
143
|
+
agent-browser click @e3
|
|
144
|
+
agent-browser wait --url "**/dashboard"
|
|
145
|
+
|
|
146
|
+
# Verify login succeeded
|
|
147
|
+
agent-browser get url # Should be dashboard, not login
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
After submitting, wait for the authenticated destination, a success message, or another app-specific condition. Do not use `networkidle` as a generic login wait because long-lived background connections can keep it from resolving.
|
|
151
|
+
|
|
152
|
+
`auth login` filters matching controls by their layout size, computed visibility and opacity, and disabled/readonly state, including custom CSS selectors. If a selected credential field is replaced or redirects focus before entry, the command fails without submitting.
|
|
153
|
+
|
|
154
|
+
For a form reached through an in-page click, challenge clearance, consent dismissal, or another stateful step, use the auth vault without discarding the prepared document:
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
agent-browser open https://app.example.com/
|
|
158
|
+
agent-browser click "a[href='/login']"
|
|
159
|
+
agent-browser auth login my-app --no-navigate
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
`--no-navigate` suppresses only the initial navigation that `auth login` normally performs. An existing active top-level HTTP(S) page is required. Before either credential is filled, agent-browser compares the page origin with the effective credential URL using scheme, host, and effective port. Paths, queries, and fragments may differ. Selector waits, credential filling, submit clicking, and submit-triggered navigation remain unchanged.
|
|
163
|
+
|
|
164
|
+
The command-level `--url` override takes precedence over stored profile or credential-provider URL metadata. In no-navigation mode it is an expected-origin constraint, not a navigation destination. This supports hosted identity-provider flows:
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
agent-browser auth login work --no-navigate --url https://identity.example.com/login
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Plugins
|
|
171
|
+
|
|
172
|
+
Use credential provider plugins when credentials live in external vault software. Plugins are configured in `~/.agent-browser/config.json` or a file loaded with `--config` and run as external executables over the `agent-browser.plugin.v1` stdio JSON protocol. The auto-discovered `./agent-browser.json` ignores `plugins` with a warning. An explicitly loaded file replaces default config discovery.
|
|
173
|
+
|
|
174
|
+
Add a plugin with `plugin add`, which writes `~/.agent-browser/config.json` by default; use `--project` for `./agent-browser.json` (only used with `--config`). A plain `name` or `@scope/name` resolves from npm; `owner/repo` resolves from GitHub:
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
agent-browser plugin add agent-browser-plugin-vault --name vault
|
|
178
|
+
agent-browser plugin add @company/agent-browser-plugin-vault --name vault
|
|
179
|
+
agent-browser plugin add org/agent-browser-plugin-cloud-browser
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
```json
|
|
183
|
+
{
|
|
184
|
+
"plugins": [
|
|
185
|
+
{
|
|
186
|
+
"name": "vault",
|
|
187
|
+
"command": "agent-browser-plugin-vault",
|
|
188
|
+
"capabilities": ["credential.read"]
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
"name": "cloud-browser",
|
|
192
|
+
"command": "agent-browser-plugin-cloud-browser",
|
|
193
|
+
"capabilities": ["browser.provider"]
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
"name": "stealth",
|
|
197
|
+
"command": "agent-browser-plugin-stealth",
|
|
198
|
+
"capabilities": ["launch.mutate"]
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
"name": "captcha",
|
|
202
|
+
"command": "agent-browser-plugin-captcha",
|
|
203
|
+
"capabilities": ["command.run", "captcha.solve"]
|
|
204
|
+
}
|
|
205
|
+
]
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Inspect configured plugins before use:
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
agent-browser plugin list
|
|
213
|
+
agent-browser plugin show vault
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Resolve credentials just-in-time for one login:
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
agent-browser auth login my-app --credential-provider vault --item "My App"
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
After stateful setup, combine the provider with no-navigation mode. The provider secret remains in memory and does not enter generated process arguments or normal output:
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
agent-browser auth login my-app --credential-provider vault --item "My App" --no-navigate --url https://identity.example.com/login
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Use a plugin as a browser provider or a generic domain command:
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
agent-browser --provider cloud-browser open https://example.com
|
|
232
|
+
agent-browser plugin run captcha captcha.solve --payload '{"siteKey":"...","url":"https://example.com"}'
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
`plugin run` is for `command.run` and custom capabilities. Core capabilities and protocol request types use their dedicated command paths.
|
|
236
|
+
|
|
237
|
+
Credential resolution, browser launch and cleanup, and launch mutation errors omit plugin response error text and unsupported protocol values from diagnostics. Manifest discovery and `plugin run` retain detailed errors. Plugins remain trusted local executables; this redaction does not sandbox them.
|
|
238
|
+
|
|
239
|
+
Use `--url`, `--username-selector`, `--password-selector`, and `--submit-selector` on `auth login` to override plugin-provided metadata for the current login only.
|
|
240
|
+
|
|
241
|
+
Gate plugin secret access separately from normal login automation:
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
agent-browser --confirm-actions plugin:vault:credential.read auth login my-app --credential-provider vault --item "My App"
|
|
245
|
+
agent-browser --confirm-actions plugin:cloud-browser:browser.provider --provider cloud-browser open https://example.com
|
|
246
|
+
agent-browser --confirm-actions plugin:stealth:launch.mutate open https://example.com
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
Do not put vault tokens or passwords in plugin command args. Use the vault vendor's own login/session mechanism or environment outside agent-browser config.
|
|
250
|
+
|
|
251
|
+
## Saving Authentication State
|
|
252
|
+
|
|
253
|
+
After logging in, save state for reuse:
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
# Login first (see above)
|
|
257
|
+
agent-browser open https://app.example.com/login
|
|
258
|
+
agent-browser snapshot -i
|
|
259
|
+
agent-browser fill @e1 "user@example.com"
|
|
260
|
+
agent-browser fill @e2 "password123"
|
|
261
|
+
agent-browser click @e3
|
|
262
|
+
agent-browser wait --url "**/dashboard"
|
|
263
|
+
|
|
264
|
+
# Save authenticated state
|
|
265
|
+
agent-browser state save ./auth-state.json
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## Restoring Authentication
|
|
269
|
+
|
|
270
|
+
Skip login by loading saved state:
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
# Load saved auth state
|
|
274
|
+
agent-browser state load ./auth-state.json
|
|
275
|
+
|
|
276
|
+
# Navigate directly to protected page
|
|
277
|
+
agent-browser open https://app.example.com/dashboard
|
|
278
|
+
|
|
279
|
+
# Verify authenticated
|
|
280
|
+
agent-browser snapshot -i
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
## OAuth / SSO Flows
|
|
284
|
+
|
|
285
|
+
For OAuth redirects:
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
# Start OAuth flow
|
|
289
|
+
agent-browser open https://app.example.com/auth/google
|
|
290
|
+
|
|
291
|
+
# Handle redirects automatically
|
|
292
|
+
agent-browser wait --url "**/accounts.google.com**"
|
|
293
|
+
agent-browser snapshot -i
|
|
294
|
+
|
|
295
|
+
# Fill Google credentials
|
|
296
|
+
agent-browser fill @e1 "user@gmail.com"
|
|
297
|
+
agent-browser click @e2 # Next button
|
|
298
|
+
agent-browser wait 2000
|
|
299
|
+
agent-browser snapshot -i
|
|
300
|
+
agent-browser fill @e3 "password"
|
|
301
|
+
agent-browser click @e4 # Sign in
|
|
302
|
+
|
|
303
|
+
# Wait for redirect back
|
|
304
|
+
agent-browser wait --url "**/app.example.com**"
|
|
305
|
+
agent-browser state save ./oauth-state.json
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
## Two-Factor Authentication
|
|
309
|
+
|
|
310
|
+
Handle 2FA with manual intervention:
|
|
311
|
+
|
|
312
|
+
```bash
|
|
313
|
+
# Login with credentials
|
|
314
|
+
agent-browser open https://app.example.com/login --headed # Show browser
|
|
315
|
+
agent-browser snapshot -i
|
|
316
|
+
agent-browser fill @e1 "user@example.com"
|
|
317
|
+
agent-browser fill @e2 "password123"
|
|
318
|
+
agent-browser click @e3
|
|
319
|
+
|
|
320
|
+
# Wait for user to complete 2FA manually
|
|
321
|
+
echo "Complete 2FA in the browser window..."
|
|
322
|
+
agent-browser wait --url "**/dashboard" --timeout 120000
|
|
323
|
+
|
|
324
|
+
# Save state after 2FA
|
|
325
|
+
agent-browser state save ./2fa-state.json
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
## HTTP Basic Auth
|
|
329
|
+
|
|
330
|
+
For sites using HTTP Basic Authentication:
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
# Set credentials before navigation
|
|
334
|
+
agent-browser set credentials username password
|
|
335
|
+
|
|
336
|
+
# Navigate to protected resource
|
|
337
|
+
agent-browser open https://protected.example.com/api
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
The credentials also apply to tabs opened later through `tab new` or `click --new-tab`, including their first document request.
|
|
341
|
+
|
|
342
|
+
## Cookie-Based Auth
|
|
343
|
+
|
|
344
|
+
Manually set authentication cookies:
|
|
345
|
+
|
|
346
|
+
```bash
|
|
347
|
+
# Set auth cookie
|
|
348
|
+
agent-browser cookies set session_token "abc123xyz"
|
|
349
|
+
|
|
350
|
+
# Navigate to protected page
|
|
351
|
+
agent-browser open https://app.example.com/dashboard
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
## Token Refresh Handling
|
|
355
|
+
|
|
356
|
+
For sessions with expiring tokens:
|
|
357
|
+
|
|
358
|
+
```bash
|
|
359
|
+
#!/bin/bash
|
|
360
|
+
# Wrapper that handles token refresh
|
|
361
|
+
|
|
362
|
+
STATE_FILE="./auth-state.json"
|
|
363
|
+
|
|
364
|
+
# Try loading existing state
|
|
365
|
+
if [[ -f "$STATE_FILE" ]]; then
|
|
366
|
+
agent-browser state load "$STATE_FILE"
|
|
367
|
+
agent-browser open https://app.example.com/dashboard
|
|
368
|
+
|
|
369
|
+
# Check if session is still valid
|
|
370
|
+
URL=$(agent-browser get url)
|
|
371
|
+
if [[ "$URL" == *"/login"* ]]; then
|
|
372
|
+
echo "Session expired, re-authenticating..."
|
|
373
|
+
# Perform fresh login
|
|
374
|
+
agent-browser snapshot -i
|
|
375
|
+
agent-browser fill @e1 "$USERNAME"
|
|
376
|
+
agent-browser fill @e2 "$PASSWORD"
|
|
377
|
+
agent-browser click @e3
|
|
378
|
+
agent-browser wait --url "**/dashboard"
|
|
379
|
+
agent-browser state save "$STATE_FILE"
|
|
380
|
+
fi
|
|
381
|
+
else
|
|
382
|
+
# First-time login
|
|
383
|
+
agent-browser open https://app.example.com/login
|
|
384
|
+
# ... login flow ...
|
|
385
|
+
fi
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
## Security Best Practices
|
|
389
|
+
|
|
390
|
+
1. **Never commit state files** - They contain session tokens
|
|
391
|
+
```bash
|
|
392
|
+
echo "*.auth-state.json" >> .gitignore
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
2. **Use environment variables for credentials**
|
|
396
|
+
```bash
|
|
397
|
+
agent-browser fill @e1 "$APP_USERNAME"
|
|
398
|
+
agent-browser fill @e2 "$APP_PASSWORD"
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
3. **Clean up after automation**
|
|
402
|
+
```bash
|
|
403
|
+
agent-browser cookies clear
|
|
404
|
+
rm -f ./auth-state.json
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
4. **Use short-lived sessions for CI/CD**
|
|
408
|
+
```bash
|
|
409
|
+
# Don't persist state in CI
|
|
410
|
+
agent-browser open https://app.example.com/login
|
|
411
|
+
# ... login and perform actions ...
|
|
412
|
+
agent-browser close # Session ends, nothing persisted
|
|
413
|
+
```
|