agent-browser 0.6.0 → 0.7.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.
- package/README.md +90 -9
- package/bin/agent-browser-darwin-arm64 +0 -0
- package/bin/agent-browser-darwin-x64 +0 -0
- package/bin/agent-browser-linux-arm64 +0 -0
- package/bin/agent-browser-linux-x64 +0 -0
- package/bin/agent-browser-win32-x64.exe +0 -0
- package/dist/actions.js +17 -11
- package/dist/actions.js.map +1 -1
- package/dist/browser.d.ts +24 -1
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +241 -21
- package/dist/browser.js.map +1 -1
- package/dist/daemon.d.ts +5 -0
- package/dist/daemon.d.ts.map +1 -1
- package/dist/daemon.js +51 -5
- package/dist/daemon.js.map +1 -1
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +11 -0
- package/dist/protocol.js.map +1 -1
- package/dist/types.d.ts +5 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +26 -23
- package/scripts/build-all-platforms.sh +0 -0
- package/scripts/copy-native.js +2 -1
- package/scripts/postinstall.js +1 -1
- package/skills/agent-browser/SKILL.md +132 -35
- package/skills/agent-browser/references/authentication.md +188 -0
- package/skills/agent-browser/references/proxy-support.md +175 -0
- package/skills/agent-browser/references/session-management.md +181 -0
- package/skills/agent-browser/references/snapshot-refs.md +186 -0
- package/skills/agent-browser/references/video-recording.md +162 -0
- package/skills/agent-browser/templates/authenticated-session.sh +91 -0
- package/skills/agent-browser/templates/capture-workflow.sh +68 -0
- package/skills/agent-browser/templates/form-automation.sh +64 -0
- package/dist/browser.test.d.ts +0 -2
- package/dist/browser.test.d.ts.map +0 -1
- package/dist/browser.test.js +0 -136
- package/dist/browser.test.js.map +0 -1
- package/dist/protocol.test.d.ts +0 -2
- package/dist/protocol.test.d.ts.map +0 -1
- package/dist/protocol.test.js +0 -176
- package/dist/protocol.test.js.map +0 -1
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# Session Management
|
|
2
|
+
|
|
3
|
+
Run multiple isolated browser sessions concurrently with state persistence.
|
|
4
|
+
|
|
5
|
+
## Named Sessions
|
|
6
|
+
|
|
7
|
+
Use `--session` flag to isolate browser contexts:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# Session 1: Authentication flow
|
|
11
|
+
agent-browser --session auth open https://app.example.com/login
|
|
12
|
+
|
|
13
|
+
# Session 2: Public browsing (separate cookies, storage)
|
|
14
|
+
agent-browser --session public open https://example.com
|
|
15
|
+
|
|
16
|
+
# Commands are isolated by session
|
|
17
|
+
agent-browser --session auth fill @e1 "user@example.com"
|
|
18
|
+
agent-browser --session public get text body
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Session Isolation Properties
|
|
22
|
+
|
|
23
|
+
Each session has independent:
|
|
24
|
+
- Cookies
|
|
25
|
+
- LocalStorage / SessionStorage
|
|
26
|
+
- IndexedDB
|
|
27
|
+
- Cache
|
|
28
|
+
- Browsing history
|
|
29
|
+
- Open tabs
|
|
30
|
+
|
|
31
|
+
## Session State Persistence
|
|
32
|
+
|
|
33
|
+
### Save Session State
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# Save cookies, storage, and auth state
|
|
37
|
+
agent-browser state save /path/to/auth-state.json
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Load Session State
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
# Restore saved state
|
|
44
|
+
agent-browser state load /path/to/auth-state.json
|
|
45
|
+
|
|
46
|
+
# Continue with authenticated session
|
|
47
|
+
agent-browser open https://app.example.com/dashboard
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### State File Contents
|
|
51
|
+
|
|
52
|
+
```json
|
|
53
|
+
{
|
|
54
|
+
"cookies": [...],
|
|
55
|
+
"localStorage": {...},
|
|
56
|
+
"sessionStorage": {...},
|
|
57
|
+
"origins": [...]
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Common Patterns
|
|
62
|
+
|
|
63
|
+
### Authenticated Session Reuse
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
#!/bin/bash
|
|
67
|
+
# Save login state once, reuse many times
|
|
68
|
+
|
|
69
|
+
STATE_FILE="/tmp/auth-state.json"
|
|
70
|
+
|
|
71
|
+
# Check if we have saved state
|
|
72
|
+
if [[ -f "$STATE_FILE" ]]; then
|
|
73
|
+
agent-browser state load "$STATE_FILE"
|
|
74
|
+
agent-browser open https://app.example.com/dashboard
|
|
75
|
+
else
|
|
76
|
+
# Perform login
|
|
77
|
+
agent-browser open https://app.example.com/login
|
|
78
|
+
agent-browser snapshot -i
|
|
79
|
+
agent-browser fill @e1 "$USERNAME"
|
|
80
|
+
agent-browser fill @e2 "$PASSWORD"
|
|
81
|
+
agent-browser click @e3
|
|
82
|
+
agent-browser wait --load networkidle
|
|
83
|
+
|
|
84
|
+
# Save for future use
|
|
85
|
+
agent-browser state save "$STATE_FILE"
|
|
86
|
+
fi
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Concurrent Scraping
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
#!/bin/bash
|
|
93
|
+
# Scrape multiple sites concurrently
|
|
94
|
+
|
|
95
|
+
# Start all sessions
|
|
96
|
+
agent-browser --session site1 open https://site1.com &
|
|
97
|
+
agent-browser --session site2 open https://site2.com &
|
|
98
|
+
agent-browser --session site3 open https://site3.com &
|
|
99
|
+
wait
|
|
100
|
+
|
|
101
|
+
# Extract from each
|
|
102
|
+
agent-browser --session site1 get text body > site1.txt
|
|
103
|
+
agent-browser --session site2 get text body > site2.txt
|
|
104
|
+
agent-browser --session site3 get text body > site3.txt
|
|
105
|
+
|
|
106
|
+
# Cleanup
|
|
107
|
+
agent-browser --session site1 close
|
|
108
|
+
agent-browser --session site2 close
|
|
109
|
+
agent-browser --session site3 close
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### A/B Testing Sessions
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
# Test different user experiences
|
|
116
|
+
agent-browser --session variant-a open "https://app.com?variant=a"
|
|
117
|
+
agent-browser --session variant-b open "https://app.com?variant=b"
|
|
118
|
+
|
|
119
|
+
# Compare
|
|
120
|
+
agent-browser --session variant-a screenshot /tmp/variant-a.png
|
|
121
|
+
agent-browser --session variant-b screenshot /tmp/variant-b.png
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Default Session
|
|
125
|
+
|
|
126
|
+
When `--session` is omitted, commands use the default session:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
# These use the same default session
|
|
130
|
+
agent-browser open https://example.com
|
|
131
|
+
agent-browser snapshot -i
|
|
132
|
+
agent-browser close # Closes default session
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Session Cleanup
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
# Close specific session
|
|
139
|
+
agent-browser --session auth close
|
|
140
|
+
|
|
141
|
+
# List active sessions
|
|
142
|
+
agent-browser session list
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Best Practices
|
|
146
|
+
|
|
147
|
+
### 1. Name Sessions Semantically
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
# GOOD: Clear purpose
|
|
151
|
+
agent-browser --session github-auth open https://github.com
|
|
152
|
+
agent-browser --session docs-scrape open https://docs.example.com
|
|
153
|
+
|
|
154
|
+
# AVOID: Generic names
|
|
155
|
+
agent-browser --session s1 open https://github.com
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### 2. Always Clean Up
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
# Close sessions when done
|
|
162
|
+
agent-browser --session auth close
|
|
163
|
+
agent-browser --session scrape close
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### 3. Handle State Files Securely
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
# Don't commit state files (contain auth tokens!)
|
|
170
|
+
echo "*.auth-state.json" >> .gitignore
|
|
171
|
+
|
|
172
|
+
# Delete after use
|
|
173
|
+
rm /tmp/auth-state.json
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### 4. Timeout Long Sessions
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
# Set timeout for automated scripts
|
|
180
|
+
timeout 60 agent-browser --session long-task get text body
|
|
181
|
+
```
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# Snapshot + Refs Workflow
|
|
2
|
+
|
|
3
|
+
The core innovation of agent-browser: compact element references that reduce context usage dramatically for AI agents.
|
|
4
|
+
|
|
5
|
+
## How It Works
|
|
6
|
+
|
|
7
|
+
### The Problem
|
|
8
|
+
Traditional browser automation sends full DOM to AI agents:
|
|
9
|
+
```
|
|
10
|
+
Full DOM/HTML sent → AI parses → Generates CSS selector → Executes action
|
|
11
|
+
~3000-5000 tokens per interaction
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
### The Solution
|
|
15
|
+
agent-browser uses compact snapshots with refs:
|
|
16
|
+
```
|
|
17
|
+
Compact snapshot → @refs assigned → Direct ref interaction
|
|
18
|
+
~200-400 tokens per interaction
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## The Snapshot Command
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# Basic snapshot (shows page structure)
|
|
25
|
+
agent-browser snapshot
|
|
26
|
+
|
|
27
|
+
# Interactive snapshot (-i flag) - RECOMMENDED
|
|
28
|
+
agent-browser snapshot -i
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Snapshot Output Format
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
Page: Example Site - Home
|
|
35
|
+
URL: https://example.com
|
|
36
|
+
|
|
37
|
+
@e1 [header]
|
|
38
|
+
@e2 [nav]
|
|
39
|
+
@e3 [a] "Home"
|
|
40
|
+
@e4 [a] "Products"
|
|
41
|
+
@e5 [a] "About"
|
|
42
|
+
@e6 [button] "Sign In"
|
|
43
|
+
|
|
44
|
+
@e7 [main]
|
|
45
|
+
@e8 [h1] "Welcome"
|
|
46
|
+
@e9 [form]
|
|
47
|
+
@e10 [input type="email"] placeholder="Email"
|
|
48
|
+
@e11 [input type="password"] placeholder="Password"
|
|
49
|
+
@e12 [button type="submit"] "Log In"
|
|
50
|
+
|
|
51
|
+
@e13 [footer]
|
|
52
|
+
@e14 [a] "Privacy Policy"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Using Refs
|
|
56
|
+
|
|
57
|
+
Once you have refs, interact directly:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
# Click the "Sign In" button
|
|
61
|
+
agent-browser click @e6
|
|
62
|
+
|
|
63
|
+
# Fill email input
|
|
64
|
+
agent-browser fill @e10 "user@example.com"
|
|
65
|
+
|
|
66
|
+
# Fill password
|
|
67
|
+
agent-browser fill @e11 "password123"
|
|
68
|
+
|
|
69
|
+
# Submit the form
|
|
70
|
+
agent-browser click @e12
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Ref Lifecycle
|
|
74
|
+
|
|
75
|
+
**IMPORTANT**: Refs are invalidated when the page changes!
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# Get initial snapshot
|
|
79
|
+
agent-browser snapshot -i
|
|
80
|
+
# @e1 [button] "Next"
|
|
81
|
+
|
|
82
|
+
# Click triggers page change
|
|
83
|
+
agent-browser click @e1
|
|
84
|
+
|
|
85
|
+
# MUST re-snapshot to get new refs!
|
|
86
|
+
agent-browser snapshot -i
|
|
87
|
+
# @e1 [h1] "Page 2" ← Different element now!
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Best Practices
|
|
91
|
+
|
|
92
|
+
### 1. Always Snapshot Before Interacting
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
# CORRECT
|
|
96
|
+
agent-browser open https://example.com
|
|
97
|
+
agent-browser snapshot -i # Get refs first
|
|
98
|
+
agent-browser click @e1 # Use ref
|
|
99
|
+
|
|
100
|
+
# WRONG
|
|
101
|
+
agent-browser open https://example.com
|
|
102
|
+
agent-browser click @e1 # Ref doesn't exist yet!
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### 2. Re-Snapshot After Navigation
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
agent-browser click @e5 # Navigates to new page
|
|
109
|
+
agent-browser snapshot -i # Get new refs
|
|
110
|
+
agent-browser click @e1 # Use new refs
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### 3. Re-Snapshot After Dynamic Changes
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
agent-browser click @e1 # Opens dropdown
|
|
117
|
+
agent-browser snapshot -i # See dropdown items
|
|
118
|
+
agent-browser click @e7 # Select item
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### 4. Snapshot Specific Regions
|
|
122
|
+
|
|
123
|
+
For complex pages, snapshot specific areas:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
# Snapshot just the form
|
|
127
|
+
agent-browser snapshot @e9
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Ref Notation Details
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
@e1 [tag type="value"] "text content" placeholder="hint"
|
|
134
|
+
│ │ │ │ │
|
|
135
|
+
│ │ │ │ └─ Additional attributes
|
|
136
|
+
│ │ │ └─ Visible text
|
|
137
|
+
│ │ └─ Key attributes shown
|
|
138
|
+
│ └─ HTML tag name
|
|
139
|
+
└─ Unique ref ID
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Common Patterns
|
|
143
|
+
|
|
144
|
+
```
|
|
145
|
+
@e1 [button] "Submit" # Button with text
|
|
146
|
+
@e2 [input type="email"] # Email input
|
|
147
|
+
@e3 [input type="password"] # Password input
|
|
148
|
+
@e4 [a href="/page"] "Link Text" # Anchor link
|
|
149
|
+
@e5 [select] # Dropdown
|
|
150
|
+
@e6 [textarea] placeholder="Message" # Text area
|
|
151
|
+
@e7 [div class="modal"] # Container (when relevant)
|
|
152
|
+
@e8 [img alt="Logo"] # Image
|
|
153
|
+
@e9 [checkbox] checked # Checked checkbox
|
|
154
|
+
@e10 [radio] selected # Selected radio
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Troubleshooting
|
|
158
|
+
|
|
159
|
+
### "Ref not found" Error
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
# Ref may have changed - re-snapshot
|
|
163
|
+
agent-browser snapshot -i
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Element Not Visible in Snapshot
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
# Scroll to reveal element
|
|
170
|
+
agent-browser scroll --bottom
|
|
171
|
+
agent-browser snapshot -i
|
|
172
|
+
|
|
173
|
+
# Or wait for dynamic content
|
|
174
|
+
agent-browser wait 1000
|
|
175
|
+
agent-browser snapshot -i
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Too Many Elements
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
# Snapshot specific container
|
|
182
|
+
agent-browser snapshot @e5
|
|
183
|
+
|
|
184
|
+
# Or use get text for content-only extraction
|
|
185
|
+
agent-browser get text @e5
|
|
186
|
+
```
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# Video Recording
|
|
2
|
+
|
|
3
|
+
Capture browser automation sessions as video for debugging, documentation, or verification.
|
|
4
|
+
|
|
5
|
+
## Basic Recording
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Start recording
|
|
9
|
+
agent-browser record start ./demo.webm
|
|
10
|
+
|
|
11
|
+
# Perform actions
|
|
12
|
+
agent-browser open https://example.com
|
|
13
|
+
agent-browser snapshot -i
|
|
14
|
+
agent-browser click @e1
|
|
15
|
+
agent-browser fill @e2 "test input"
|
|
16
|
+
|
|
17
|
+
# Stop and save
|
|
18
|
+
agent-browser record stop
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Recording Commands
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# Start recording to file
|
|
25
|
+
agent-browser record start ./output.webm
|
|
26
|
+
|
|
27
|
+
# Stop current recording
|
|
28
|
+
agent-browser record stop
|
|
29
|
+
|
|
30
|
+
# Restart with new file (stops current + starts new)
|
|
31
|
+
agent-browser record restart ./take2.webm
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Use Cases
|
|
35
|
+
|
|
36
|
+
### Debugging Failed Automation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
#!/bin/bash
|
|
40
|
+
# Record automation for debugging
|
|
41
|
+
|
|
42
|
+
agent-browser record start ./debug-$(date +%Y%m%d-%H%M%S).webm
|
|
43
|
+
|
|
44
|
+
# Run your automation
|
|
45
|
+
agent-browser open https://app.example.com
|
|
46
|
+
agent-browser snapshot -i
|
|
47
|
+
agent-browser click @e1 || {
|
|
48
|
+
echo "Click failed - check recording"
|
|
49
|
+
agent-browser record stop
|
|
50
|
+
exit 1
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
agent-browser record stop
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Documentation Generation
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
#!/bin/bash
|
|
60
|
+
# Record workflow for documentation
|
|
61
|
+
|
|
62
|
+
agent-browser record start ./docs/how-to-login.webm
|
|
63
|
+
|
|
64
|
+
agent-browser open https://app.example.com/login
|
|
65
|
+
agent-browser wait 1000 # Pause for visibility
|
|
66
|
+
|
|
67
|
+
agent-browser snapshot -i
|
|
68
|
+
agent-browser fill @e1 "demo@example.com"
|
|
69
|
+
agent-browser wait 500
|
|
70
|
+
|
|
71
|
+
agent-browser fill @e2 "password"
|
|
72
|
+
agent-browser wait 500
|
|
73
|
+
|
|
74
|
+
agent-browser click @e3
|
|
75
|
+
agent-browser wait --load networkidle
|
|
76
|
+
agent-browser wait 1000 # Show result
|
|
77
|
+
|
|
78
|
+
agent-browser record stop
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### CI/CD Test Evidence
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
#!/bin/bash
|
|
85
|
+
# Record E2E test runs for CI artifacts
|
|
86
|
+
|
|
87
|
+
TEST_NAME="${1:-e2e-test}"
|
|
88
|
+
RECORDING_DIR="./test-recordings"
|
|
89
|
+
mkdir -p "$RECORDING_DIR"
|
|
90
|
+
|
|
91
|
+
agent-browser record start "$RECORDING_DIR/$TEST_NAME-$(date +%s).webm"
|
|
92
|
+
|
|
93
|
+
# Run test
|
|
94
|
+
if run_e2e_test; then
|
|
95
|
+
echo "Test passed"
|
|
96
|
+
else
|
|
97
|
+
echo "Test failed - recording saved"
|
|
98
|
+
fi
|
|
99
|
+
|
|
100
|
+
agent-browser record stop
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Best Practices
|
|
104
|
+
|
|
105
|
+
### 1. Add Pauses for Clarity
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
# Slow down for human viewing
|
|
109
|
+
agent-browser click @e1
|
|
110
|
+
agent-browser wait 500 # Let viewer see result
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### 2. Use Descriptive Filenames
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
# Include context in filename
|
|
117
|
+
agent-browser record start ./recordings/login-flow-2024-01-15.webm
|
|
118
|
+
agent-browser record start ./recordings/checkout-test-run-42.webm
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### 3. Handle Recording in Error Cases
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
#!/bin/bash
|
|
125
|
+
set -e
|
|
126
|
+
|
|
127
|
+
cleanup() {
|
|
128
|
+
agent-browser record stop 2>/dev/null || true
|
|
129
|
+
agent-browser close 2>/dev/null || true
|
|
130
|
+
}
|
|
131
|
+
trap cleanup EXIT
|
|
132
|
+
|
|
133
|
+
agent-browser record start ./automation.webm
|
|
134
|
+
# ... automation steps ...
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### 4. Combine with Screenshots
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
# Record video AND capture key frames
|
|
141
|
+
agent-browser record start ./flow.webm
|
|
142
|
+
|
|
143
|
+
agent-browser open https://example.com
|
|
144
|
+
agent-browser screenshot ./screenshots/step1-homepage.png
|
|
145
|
+
|
|
146
|
+
agent-browser click @e1
|
|
147
|
+
agent-browser screenshot ./screenshots/step2-after-click.png
|
|
148
|
+
|
|
149
|
+
agent-browser record stop
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Output Format
|
|
153
|
+
|
|
154
|
+
- Default format: WebM (VP8/VP9 codec)
|
|
155
|
+
- Compatible with all modern browsers and video players
|
|
156
|
+
- Compressed but high quality
|
|
157
|
+
|
|
158
|
+
## Limitations
|
|
159
|
+
|
|
160
|
+
- Recording adds slight overhead to automation
|
|
161
|
+
- Large recordings can consume significant disk space
|
|
162
|
+
- Some headless environments may have codec limitations
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Template: Authenticated Session Workflow
|
|
3
|
+
# Login once, save state, reuse for subsequent runs
|
|
4
|
+
#
|
|
5
|
+
# Usage:
|
|
6
|
+
# ./authenticated-session.sh <login-url> [state-file]
|
|
7
|
+
#
|
|
8
|
+
# Setup:
|
|
9
|
+
# 1. Run once to see your form structure
|
|
10
|
+
# 2. Note the @refs for your fields
|
|
11
|
+
# 3. Uncomment LOGIN FLOW section and update refs
|
|
12
|
+
|
|
13
|
+
set -euo pipefail
|
|
14
|
+
|
|
15
|
+
LOGIN_URL="${1:?Usage: $0 <login-url> [state-file]}"
|
|
16
|
+
STATE_FILE="${2:-./auth-state.json}"
|
|
17
|
+
|
|
18
|
+
echo "Authentication workflow for: $LOGIN_URL"
|
|
19
|
+
|
|
20
|
+
# ══════════════════════════════════════════════════════════════
|
|
21
|
+
# SAVED STATE: Skip login if we have valid saved state
|
|
22
|
+
# ══════════════════════════════════════════════════════════════
|
|
23
|
+
if [[ -f "$STATE_FILE" ]]; then
|
|
24
|
+
echo "Loading saved authentication state..."
|
|
25
|
+
agent-browser state load "$STATE_FILE"
|
|
26
|
+
agent-browser open "$LOGIN_URL"
|
|
27
|
+
agent-browser wait --load networkidle
|
|
28
|
+
|
|
29
|
+
CURRENT_URL=$(agent-browser get url)
|
|
30
|
+
if [[ "$CURRENT_URL" != *"login"* ]] && [[ "$CURRENT_URL" != *"signin"* ]]; then
|
|
31
|
+
echo "Session restored successfully!"
|
|
32
|
+
agent-browser snapshot -i
|
|
33
|
+
exit 0
|
|
34
|
+
fi
|
|
35
|
+
echo "Session expired, performing fresh login..."
|
|
36
|
+
rm -f "$STATE_FILE"
|
|
37
|
+
fi
|
|
38
|
+
|
|
39
|
+
# ══════════════════════════════════════════════════════════════
|
|
40
|
+
# DISCOVERY MODE: Show form structure (remove after setup)
|
|
41
|
+
# ══════════════════════════════════════════════════════════════
|
|
42
|
+
echo "Opening login page..."
|
|
43
|
+
agent-browser open "$LOGIN_URL"
|
|
44
|
+
agent-browser wait --load networkidle
|
|
45
|
+
|
|
46
|
+
echo ""
|
|
47
|
+
echo "┌─────────────────────────────────────────────────────────┐"
|
|
48
|
+
echo "│ LOGIN FORM STRUCTURE │"
|
|
49
|
+
echo "├─────────────────────────────────────────────────────────┤"
|
|
50
|
+
agent-browser snapshot -i
|
|
51
|
+
echo "└─────────────────────────────────────────────────────────┘"
|
|
52
|
+
echo ""
|
|
53
|
+
echo "Next steps:"
|
|
54
|
+
echo " 1. Note refs: @e? = username, @e? = password, @e? = submit"
|
|
55
|
+
echo " 2. Uncomment LOGIN FLOW section below"
|
|
56
|
+
echo " 3. Replace @e1, @e2, @e3 with your refs"
|
|
57
|
+
echo " 4. Delete this DISCOVERY MODE section"
|
|
58
|
+
echo ""
|
|
59
|
+
agent-browser close
|
|
60
|
+
exit 0
|
|
61
|
+
|
|
62
|
+
# ══════════════════════════════════════════════════════════════
|
|
63
|
+
# LOGIN FLOW: Uncomment and customize after discovery
|
|
64
|
+
# ══════════════════════════════════════════════════════════════
|
|
65
|
+
# : "${APP_USERNAME:?Set APP_USERNAME environment variable}"
|
|
66
|
+
# : "${APP_PASSWORD:?Set APP_PASSWORD environment variable}"
|
|
67
|
+
#
|
|
68
|
+
# agent-browser open "$LOGIN_URL"
|
|
69
|
+
# agent-browser wait --load networkidle
|
|
70
|
+
# agent-browser snapshot -i
|
|
71
|
+
#
|
|
72
|
+
# # Fill credentials (update refs to match your form)
|
|
73
|
+
# agent-browser fill @e1 "$APP_USERNAME"
|
|
74
|
+
# agent-browser fill @e2 "$APP_PASSWORD"
|
|
75
|
+
# agent-browser click @e3
|
|
76
|
+
# agent-browser wait --load networkidle
|
|
77
|
+
#
|
|
78
|
+
# # Verify login succeeded
|
|
79
|
+
# FINAL_URL=$(agent-browser get url)
|
|
80
|
+
# if [[ "$FINAL_URL" == *"login"* ]] || [[ "$FINAL_URL" == *"signin"* ]]; then
|
|
81
|
+
# echo "ERROR: Login failed - still on login page"
|
|
82
|
+
# agent-browser screenshot /tmp/login-failed.png
|
|
83
|
+
# agent-browser close
|
|
84
|
+
# exit 1
|
|
85
|
+
# fi
|
|
86
|
+
#
|
|
87
|
+
# # Save state for future runs
|
|
88
|
+
# echo "Saving authentication state to: $STATE_FILE"
|
|
89
|
+
# agent-browser state save "$STATE_FILE"
|
|
90
|
+
# echo "Login successful!"
|
|
91
|
+
# agent-browser snapshot -i
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Template: Content Capture Workflow
|
|
3
|
+
# Extract content from web pages with optional authentication
|
|
4
|
+
|
|
5
|
+
set -euo pipefail
|
|
6
|
+
|
|
7
|
+
TARGET_URL="${1:?Usage: $0 <url> [output-dir]}"
|
|
8
|
+
OUTPUT_DIR="${2:-.}"
|
|
9
|
+
|
|
10
|
+
echo "Capturing content from: $TARGET_URL"
|
|
11
|
+
mkdir -p "$OUTPUT_DIR"
|
|
12
|
+
|
|
13
|
+
# Optional: Load authentication state if needed
|
|
14
|
+
# if [[ -f "./auth-state.json" ]]; then
|
|
15
|
+
# agent-browser state load "./auth-state.json"
|
|
16
|
+
# fi
|
|
17
|
+
|
|
18
|
+
# Navigate to target page
|
|
19
|
+
agent-browser open "$TARGET_URL"
|
|
20
|
+
agent-browser wait --load networkidle
|
|
21
|
+
|
|
22
|
+
# Get page metadata
|
|
23
|
+
echo "Page title: $(agent-browser get title)"
|
|
24
|
+
echo "Page URL: $(agent-browser get url)"
|
|
25
|
+
|
|
26
|
+
# Capture full page screenshot
|
|
27
|
+
agent-browser screenshot --full "$OUTPUT_DIR/page-full.png"
|
|
28
|
+
echo "Screenshot saved: $OUTPUT_DIR/page-full.png"
|
|
29
|
+
|
|
30
|
+
# Get page structure
|
|
31
|
+
agent-browser snapshot -i > "$OUTPUT_DIR/page-structure.txt"
|
|
32
|
+
echo "Structure saved: $OUTPUT_DIR/page-structure.txt"
|
|
33
|
+
|
|
34
|
+
# Extract main content
|
|
35
|
+
# Adjust selector based on target site structure
|
|
36
|
+
# agent-browser get text @e1 > "$OUTPUT_DIR/main-content.txt"
|
|
37
|
+
|
|
38
|
+
# Extract specific elements (uncomment as needed)
|
|
39
|
+
# agent-browser get text "article" > "$OUTPUT_DIR/article.txt"
|
|
40
|
+
# agent-browser get text "main" > "$OUTPUT_DIR/main.txt"
|
|
41
|
+
# agent-browser get text ".content" > "$OUTPUT_DIR/content.txt"
|
|
42
|
+
|
|
43
|
+
# Get full page text
|
|
44
|
+
agent-browser get text body > "$OUTPUT_DIR/page-text.txt"
|
|
45
|
+
echo "Text content saved: $OUTPUT_DIR/page-text.txt"
|
|
46
|
+
|
|
47
|
+
# Optional: Save as PDF
|
|
48
|
+
agent-browser pdf "$OUTPUT_DIR/page.pdf"
|
|
49
|
+
echo "PDF saved: $OUTPUT_DIR/page.pdf"
|
|
50
|
+
|
|
51
|
+
# Optional: Capture with scrolling for infinite scroll pages
|
|
52
|
+
# scroll_and_capture() {
|
|
53
|
+
# local count=0
|
|
54
|
+
# while [[ $count -lt 5 ]]; do
|
|
55
|
+
# agent-browser scroll down 1000
|
|
56
|
+
# agent-browser wait 1000
|
|
57
|
+
# ((count++))
|
|
58
|
+
# done
|
|
59
|
+
# agent-browser screenshot --full "$OUTPUT_DIR/page-scrolled.png"
|
|
60
|
+
# }
|
|
61
|
+
# scroll_and_capture
|
|
62
|
+
|
|
63
|
+
# Cleanup
|
|
64
|
+
agent-browser close
|
|
65
|
+
|
|
66
|
+
echo ""
|
|
67
|
+
echo "Capture complete! Files saved to: $OUTPUT_DIR"
|
|
68
|
+
ls -la "$OUTPUT_DIR"
|