cbrowser 5.1.0 → 5.3.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/README.md +323 -256
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +22 -0
- package/dist/browser.js.map +1 -1
- package/dist/cli.js +209 -13
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -1
- package/dist/config.js.map +1 -1
- package/dist/personas.d.ts +31 -1
- package/dist/personas.d.ts.map +1 -1
- package/dist/personas.js +349 -2
- package/dist/personas.js.map +1 -1
- package/docs/INSTALL.md +1 -1
- package/examples/basic-usage.ts +3 -1
- package/examples/smart-automation.ts +184 -0
- package/package.json +13 -7
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# CBrowser
|
|
2
2
|
|
|
3
|
-
**The browser that thinks.** AI-powered browser automation with
|
|
3
|
+
**The browser that thinks.** AI-powered browser automation with self-healing selectors, natural language assertions, constitutional safety, and autonomous journeys.
|
|
4
4
|
|
|
5
|
-
[](https://
|
|
5
|
+
[](https://www.npmjs.com/package/cbrowser)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
7
7
|
|
|
8
8
|
## What Makes This Different
|
|
@@ -10,82 +10,225 @@
|
|
|
10
10
|
| Traditional Automation | CBrowser |
|
|
11
11
|
|------------------------|----------|
|
|
12
12
|
| Brittle CSS selectors | AI vision: "click the blue login button" |
|
|
13
|
-
| Breaks when DOM changes | Self-healing
|
|
14
|
-
|
|
|
15
|
-
|
|
|
16
|
-
|
|
|
13
|
+
| Breaks when DOM changes | **Self-healing selectors** adapt automatically |
|
|
14
|
+
| Crashes on element not found | **Smart retry** finds alternatives |
|
|
15
|
+
| Manual test assertions | **Natural language assertions** |
|
|
16
|
+
| Scripted tests only | **AI test generation** from page analysis |
|
|
17
|
+
| Stateless between runs | Persistent sessions, cookies, localStorage |
|
|
17
18
|
| No user context | Personas with goals, behaviors, limitations |
|
|
18
|
-
|
|
|
19
|
-
| Scripted tests only | Autonomous goal-driven journeys |
|
|
19
|
+
| Standalone tool | **MCP Server** for Claude integration |
|
|
20
20
|
|
|
21
21
|
## Quick Start
|
|
22
22
|
|
|
23
23
|
### Installation
|
|
24
24
|
|
|
25
25
|
```bash
|
|
26
|
-
#
|
|
26
|
+
# npm
|
|
27
27
|
npm install cbrowser
|
|
28
28
|
|
|
29
|
-
#
|
|
29
|
+
# bun (recommended)
|
|
30
30
|
bun add cbrowser
|
|
31
31
|
|
|
32
|
-
#
|
|
32
|
+
# yarn
|
|
33
33
|
yarn add cbrowser
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
### Install Playwright Browsers
|
|
37
37
|
|
|
38
38
|
```bash
|
|
39
|
-
# Install Chromium (default)
|
|
40
39
|
npx playwright install chromium
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Basic Usage
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# Navigate to a URL
|
|
46
|
+
npx cbrowser navigate "https://example.com"
|
|
47
|
+
|
|
48
|
+
# Click with auto-retry and self-healing
|
|
49
|
+
npx cbrowser smart-click "Add to Cart"
|
|
41
50
|
|
|
42
|
-
#
|
|
43
|
-
npx
|
|
51
|
+
# Natural language assertions
|
|
52
|
+
npx cbrowser assert "page contains 'Welcome'"
|
|
53
|
+
|
|
54
|
+
# Generate tests from any page
|
|
55
|
+
npx cbrowser generate-tests "https://example.com"
|
|
44
56
|
```
|
|
45
57
|
|
|
46
|
-
|
|
58
|
+
## v5.0.0 Features
|
|
47
59
|
|
|
48
|
-
|
|
60
|
+
### Smart Click with Auto-Retry
|
|
49
61
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
62
|
+
When an element isn't found, CBrowser automatically:
|
|
63
|
+
1. Checks the self-healing cache for known alternatives
|
|
64
|
+
2. Generates alternative selectors (text variants, ARIA roles, attributes)
|
|
65
|
+
3. Tries each alternative with configurable retry logic
|
|
66
|
+
4. Caches working selectors for future use
|
|
55
67
|
|
|
56
68
|
```bash
|
|
57
|
-
#
|
|
58
|
-
npx cbrowser
|
|
69
|
+
# Smart click with retry
|
|
70
|
+
npx cbrowser smart-click "Submit" --max-retries 5
|
|
59
71
|
|
|
60
|
-
#
|
|
61
|
-
npx cbrowser
|
|
72
|
+
# Navigate then click
|
|
73
|
+
npx cbrowser smart-click "Login" --url "https://example.com"
|
|
74
|
+
```
|
|
62
75
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
76
|
+
```typescript
|
|
77
|
+
import { CBrowser } from 'cbrowser';
|
|
78
|
+
|
|
79
|
+
const browser = new CBrowser();
|
|
80
|
+
const result = await browser.smartClick("Submit Button", { maxRetries: 3 });
|
|
81
|
+
|
|
82
|
+
console.log(result.success); // true/false
|
|
83
|
+
console.log(result.finalSelector); // The selector that worked
|
|
84
|
+
console.log(result.attempts); // Array of all attempts
|
|
85
|
+
console.log(result.aiSuggestion); // AI suggestion if failed
|
|
66
86
|
```
|
|
67
87
|
|
|
68
|
-
###
|
|
88
|
+
### Natural Language Assertions
|
|
89
|
+
|
|
90
|
+
Write assertions in plain English:
|
|
69
91
|
|
|
70
92
|
```bash
|
|
71
|
-
#
|
|
72
|
-
npx cbrowser
|
|
93
|
+
# Title assertions
|
|
94
|
+
npx cbrowser assert "title contains 'Dashboard'"
|
|
95
|
+
npx cbrowser assert "title is 'Home Page'"
|
|
96
|
+
|
|
97
|
+
# URL assertions
|
|
98
|
+
npx cbrowser assert "url contains '/login'"
|
|
73
99
|
|
|
74
|
-
#
|
|
75
|
-
npx cbrowser
|
|
100
|
+
# Content assertions
|
|
101
|
+
npx cbrowser assert "page contains 'Welcome back'"
|
|
76
102
|
|
|
77
|
-
#
|
|
78
|
-
npx cbrowser
|
|
103
|
+
# Element assertions
|
|
104
|
+
npx cbrowser assert "'#submit-btn' exists"
|
|
79
105
|
|
|
80
|
-
#
|
|
81
|
-
npx cbrowser
|
|
106
|
+
# Count assertions
|
|
107
|
+
npx cbrowser assert "5 buttons"
|
|
108
|
+
npx cbrowser assert "3 links"
|
|
82
109
|
```
|
|
83
110
|
|
|
84
|
-
|
|
111
|
+
```typescript
|
|
112
|
+
const result = await browser.assert("page contains 'Success'");
|
|
113
|
+
console.log(result.passed); // true/false
|
|
114
|
+
console.log(result.message); // Human-readable result
|
|
115
|
+
console.log(result.actual); // What was found
|
|
116
|
+
console.log(result.expected); // What was expected
|
|
117
|
+
```
|
|
85
118
|
|
|
86
|
-
###
|
|
119
|
+
### Self-Healing Selector Cache
|
|
120
|
+
|
|
121
|
+
CBrowser remembers which selectors work on each domain:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
# View cache statistics
|
|
125
|
+
npx cbrowser heal-stats
|
|
126
|
+
|
|
127
|
+
# Clear the cache
|
|
128
|
+
npx cbrowser heal-clear
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
const stats = browser.getSelectorCacheStats();
|
|
133
|
+
console.log(stats.totalEntries); // 42
|
|
134
|
+
console.log(stats.totalSuccesses); // 156
|
|
135
|
+
console.log(stats.topDomains); // [{ domain: 'example.com', count: 15 }, ...]
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### AI Test Generation
|
|
139
|
+
|
|
140
|
+
Analyze any page and generate test scenarios automatically:
|
|
87
141
|
|
|
88
|
-
|
|
142
|
+
```bash
|
|
143
|
+
# Generate tests for a page
|
|
144
|
+
npx cbrowser generate-tests "https://example.com"
|
|
145
|
+
|
|
146
|
+
# Output specific format
|
|
147
|
+
npx cbrowser generate-tests "https://example.com" --format playwright
|
|
148
|
+
npx cbrowser generate-tests "https://example.com" --format cbrowser
|
|
149
|
+
|
|
150
|
+
# Save to file
|
|
151
|
+
npx cbrowser generate-tests "https://example.com" --output tests.ts
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
const result = await browser.generateTests("https://example.com");
|
|
156
|
+
|
|
157
|
+
console.log(result.analysis); // Page structure analysis
|
|
158
|
+
console.log(result.tests); // Generated test scenarios
|
|
159
|
+
console.log(result.playwrightCode); // Playwright test code
|
|
160
|
+
console.log(result.cbrowserScript); // CBrowser CLI script
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**Example generated test:**
|
|
164
|
+
```typescript
|
|
165
|
+
test('Login - Valid Credentials', async ({ page }) => {
|
|
166
|
+
await page.goto('https://example.com');
|
|
167
|
+
await page.locator('[name="email"]').fill('test@example.com');
|
|
168
|
+
await page.locator('[name="password"]').fill('password123');
|
|
169
|
+
await page.locator('button[type="submit"]').click();
|
|
170
|
+
await expect(page).toHaveURL(/dashboard/);
|
|
171
|
+
});
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Page Analysis
|
|
175
|
+
|
|
176
|
+
Understand any page's structure:
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
npx cbrowser analyze "https://example.com"
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Output:
|
|
183
|
+
```
|
|
184
|
+
📊 Page Analysis:
|
|
185
|
+
Title: Example Domain
|
|
186
|
+
Forms: 1
|
|
187
|
+
- form#login (3 fields)
|
|
188
|
+
🔐 Login form detected
|
|
189
|
+
Buttons: 5
|
|
190
|
+
Links: 12
|
|
191
|
+
Has Login: ✅
|
|
192
|
+
Has Search: ❌
|
|
193
|
+
Has Navigation: ✅
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### MCP Server Mode
|
|
197
|
+
|
|
198
|
+
Run CBrowser as an MCP server for Claude Desktop integration:
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
npx cbrowser mcp-server
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Add to Claude Desktop config (`~/.config/claude-desktop/config.json`):
|
|
205
|
+
|
|
206
|
+
```json
|
|
207
|
+
{
|
|
208
|
+
"mcpServers": {
|
|
209
|
+
"cbrowser": {
|
|
210
|
+
"command": "npx",
|
|
211
|
+
"args": ["cbrowser", "mcp-server"]
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
**Available MCP Tools:**
|
|
218
|
+
- `navigate` - Navigate to URL and screenshot
|
|
219
|
+
- `click` / `smart_click` - Click elements
|
|
220
|
+
- `fill` - Fill form fields
|
|
221
|
+
- `screenshot` - Capture page
|
|
222
|
+
- `extract` - Extract page data
|
|
223
|
+
- `assert` - Natural language assertions
|
|
224
|
+
- `analyze_page` - Analyze page structure
|
|
225
|
+
- `generate_tests` - Generate test scenarios
|
|
226
|
+
- `save_session` / `load_session` - Session management
|
|
227
|
+
- `heal_stats` - Self-healing cache stats
|
|
228
|
+
|
|
229
|
+
## Core Features
|
|
230
|
+
|
|
231
|
+
### AI-Powered Element Selection
|
|
89
232
|
|
|
90
233
|
```bash
|
|
91
234
|
# Natural language
|
|
@@ -101,39 +244,40 @@ cbrowser click "visual:red button in header"
|
|
|
101
244
|
# Semantic type
|
|
102
245
|
cbrowser fill "semantic:email" "user@example.com"
|
|
103
246
|
|
|
104
|
-
# Fallback to CSS
|
|
247
|
+
# Fallback to CSS
|
|
105
248
|
cbrowser click "css:#login-btn"
|
|
106
249
|
```
|
|
107
250
|
|
|
108
251
|
### Session Persistence
|
|
109
252
|
|
|
110
|
-
Save and restore complete browser sessions:
|
|
111
|
-
|
|
112
253
|
```bash
|
|
113
|
-
# Save
|
|
114
|
-
cbrowser session save "
|
|
254
|
+
# Save session (cookies, localStorage, sessionStorage)
|
|
255
|
+
cbrowser session save "logged-in" --url "https://example.com"
|
|
115
256
|
|
|
116
|
-
# Load
|
|
117
|
-
cbrowser session load "
|
|
257
|
+
# Load session
|
|
258
|
+
cbrowser session load "logged-in"
|
|
118
259
|
|
|
119
|
-
# List
|
|
260
|
+
# List sessions
|
|
120
261
|
cbrowser session list
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### Persistent Browser Context
|
|
265
|
+
|
|
266
|
+
Enable persistent mode to keep cookies and localStorage between CLI calls:
|
|
121
267
|
|
|
122
|
-
|
|
123
|
-
cbrowser
|
|
268
|
+
```bash
|
|
269
|
+
npx cbrowser navigate "https://example.com" --persistent
|
|
124
270
|
```
|
|
125
271
|
|
|
126
272
|
### Persona-Driven Testing
|
|
127
273
|
|
|
128
|
-
Test your site from different user perspectives:
|
|
129
|
-
|
|
130
274
|
```bash
|
|
131
|
-
# Run
|
|
275
|
+
# Run autonomous journey as a persona
|
|
132
276
|
cbrowser journey "first-timer" \
|
|
133
277
|
--start "https://mysite.com" \
|
|
134
|
-
--goal "Complete signup
|
|
278
|
+
--goal "Complete signup"
|
|
135
279
|
|
|
136
|
-
# List
|
|
280
|
+
# List personas
|
|
137
281
|
cbrowser persona list
|
|
138
282
|
```
|
|
139
283
|
|
|
@@ -141,290 +285,213 @@ cbrowser persona list
|
|
|
141
285
|
|
|
142
286
|
| Persona | Description |
|
|
143
287
|
|---------|-------------|
|
|
144
|
-
| `power-user` | Tech-savvy
|
|
145
|
-
| `first-timer` | New user
|
|
146
|
-
| `mobile-user` |
|
|
147
|
-
| `
|
|
148
|
-
| `
|
|
149
|
-
| `impatient-user` | Quick to abandon slow experiences |
|
|
288
|
+
| `power-user` | Tech-savvy, expects efficiency |
|
|
289
|
+
| `first-timer` | New user, slow and exploratory |
|
|
290
|
+
| `mobile-user` | Touch interface, small screen |
|
|
291
|
+
| `elderly-user` | Vision/motor limitations |
|
|
292
|
+
| `impatient-user` | Quick to abandon |
|
|
150
293
|
|
|
151
|
-
|
|
294
|
+
**AI Persona Creation (v5.3.0):**
|
|
152
295
|
|
|
153
|
-
|
|
296
|
+
Create custom personas from natural language descriptions:
|
|
154
297
|
|
|
155
298
|
```bash
|
|
156
|
-
#
|
|
157
|
-
cbrowser
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
# List stored credentials
|
|
162
|
-
cbrowser creds list
|
|
163
|
-
|
|
164
|
-
# Authenticate using stored credentials
|
|
165
|
-
cbrowser auth "github"
|
|
166
|
-
```
|
|
299
|
+
# Describe the user - AI generates all parameters
|
|
300
|
+
npx cbrowser persona create "impatient developer who hates slow UIs" --name speed-demon
|
|
301
|
+
npx cbrowser persona create "elderly grandmother new to computers with tremors" --name grandma
|
|
302
|
+
npx cbrowser persona create "distracted teenager on their phone"
|
|
167
303
|
|
|
168
|
-
|
|
304
|
+
# List all personas (built-in + custom)
|
|
305
|
+
npx cbrowser persona list
|
|
169
306
|
|
|
170
|
-
|
|
307
|
+
# View full persona config
|
|
308
|
+
npx cbrowser persona show speed-demon
|
|
171
309
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
cbrowser
|
|
175
|
-
|
|
176
|
-
# Extract headings
|
|
177
|
-
cbrowser extract "headings"
|
|
178
|
-
|
|
179
|
-
# Extract form data
|
|
180
|
-
cbrowser extract "forms"
|
|
310
|
+
# Export/import for sharing
|
|
311
|
+
npx cbrowser persona export speed-demon
|
|
312
|
+
npx cbrowser persona import custom-persona.json
|
|
181
313
|
|
|
182
|
-
#
|
|
183
|
-
cbrowser
|
|
314
|
+
# Delete custom persona
|
|
315
|
+
npx cbrowser persona delete speed-demon
|
|
184
316
|
```
|
|
185
317
|
|
|
186
|
-
|
|
318
|
+
The AI analyzes your description and generates appropriate:
|
|
319
|
+
- **Timing**: reaction times, click delays, typing speed
|
|
320
|
+
- **Error rates**: misclicks, typos, accidental double-clicks
|
|
321
|
+
- **Mouse behavior**: movement speed, jitter, overshoot
|
|
322
|
+
- **Attention patterns**: reading style, scroll behavior, focus areas
|
|
323
|
+
- **Viewport**: device-appropriate screen size
|
|
187
324
|
|
|
188
|
-
|
|
325
|
+
### Multi-Browser Support
|
|
189
326
|
|
|
190
327
|
```bash
|
|
191
|
-
#
|
|
192
|
-
cbrowser
|
|
193
|
-
|
|
194
|
-
# Preview cleanup
|
|
195
|
-
cbrowser cleanup --dry-run
|
|
328
|
+
# Firefox
|
|
329
|
+
npx cbrowser navigate "https://example.com" --browser firefox
|
|
196
330
|
|
|
197
|
-
#
|
|
198
|
-
cbrowser
|
|
331
|
+
# WebKit (Safari)
|
|
332
|
+
npx cbrowser navigate "https://example.com" --browser webkit
|
|
199
333
|
```
|
|
200
334
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
### Data Directory
|
|
204
|
-
|
|
205
|
-
By default, CBrowser stores data in `~/.cbrowser/`. Override with:
|
|
335
|
+
### Device Emulation
|
|
206
336
|
|
|
207
337
|
```bash
|
|
208
|
-
#
|
|
209
|
-
|
|
338
|
+
# Mobile
|
|
339
|
+
npx cbrowser navigate "https://example.com" --device iphone-15
|
|
210
340
|
|
|
211
|
-
#
|
|
212
|
-
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
### Directory Structure
|
|
341
|
+
# Tablet
|
|
342
|
+
npx cbrowser navigate "https://example.com" --device ipad-pro-12
|
|
216
343
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
├── sessions/ # Saved browser sessions
|
|
220
|
-
├── screenshots/ # Captured screenshots
|
|
221
|
-
├── personas/ # Custom persona definitions
|
|
222
|
-
├── scenarios/ # Test scenarios
|
|
223
|
-
├── helpers/ # Learned site patterns
|
|
224
|
-
├── audit/ # Action audit logs
|
|
225
|
-
└── credentials.json # Encrypted credentials
|
|
344
|
+
# List devices
|
|
345
|
+
npx cbrowser device list
|
|
226
346
|
```
|
|
227
347
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
CBrowser implements a safety framework with action zones:
|
|
231
|
-
|
|
232
|
-
| Zone | Actions | Behavior |
|
|
233
|
-
|------|---------|----------|
|
|
234
|
-
| **Green** | Navigate, read, screenshot, scroll | Auto-execute |
|
|
235
|
-
| **Yellow** | Click buttons, fill forms, select | Log and proceed |
|
|
236
|
-
| **Red** | Submit, delete, purchase, account changes | Requires `--force` |
|
|
237
|
-
| **Black** | Bypass auth, violate ToS, inject scripts | Never execute |
|
|
238
|
-
|
|
239
|
-
### Safety Bypass
|
|
240
|
-
|
|
241
|
-
For automated testing, you can bypass yellow/red zone warnings:
|
|
348
|
+
### Performance Metrics
|
|
242
349
|
|
|
243
350
|
```bash
|
|
244
|
-
|
|
351
|
+
# Core Web Vitals
|
|
352
|
+
npx cbrowser perf "https://example.com"
|
|
353
|
+
|
|
354
|
+
# With budget
|
|
355
|
+
npx cbrowser perf audit "https://example.com" --budget-lcp 2500
|
|
245
356
|
```
|
|
246
357
|
|
|
247
358
|
## API Usage
|
|
248
359
|
|
|
249
|
-
Use CBrowser programmatically:
|
|
250
|
-
|
|
251
360
|
```typescript
|
|
252
361
|
import { CBrowser } from 'cbrowser';
|
|
253
362
|
|
|
254
363
|
const browser = new CBrowser({
|
|
255
|
-
dataDir: './my-data',
|
|
256
364
|
headless: true,
|
|
365
|
+
persistent: true, // Persist cookies between sessions
|
|
257
366
|
});
|
|
258
367
|
|
|
368
|
+
// Navigate
|
|
259
369
|
await browser.navigate('https://example.com');
|
|
260
|
-
await browser.click('Sign In');
|
|
261
|
-
await browser.fill('email', 'user@example.com');
|
|
262
|
-
await browser.fill('password', 'secret123');
|
|
263
|
-
await browser.click('Submit');
|
|
264
370
|
|
|
265
|
-
|
|
266
|
-
await browser.
|
|
267
|
-
```
|
|
371
|
+
// Smart click with retry
|
|
372
|
+
const clickResult = await browser.smartClick('Sign In');
|
|
268
373
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
```typescript
|
|
272
|
-
import { CBrowser } from 'cbrowser';
|
|
273
|
-
|
|
274
|
-
const browser = new CBrowser();
|
|
374
|
+
// Fill form
|
|
375
|
+
await browser.fill('email', 'user@example.com');
|
|
275
376
|
|
|
276
|
-
//
|
|
277
|
-
const
|
|
278
|
-
if (!
|
|
279
|
-
|
|
280
|
-
await browser.fill('email', 'user@example.com');
|
|
281
|
-
await browser.fill('password', 'secret');
|
|
282
|
-
await browser.click('Login');
|
|
283
|
-
await browser.saveSession('my-app');
|
|
377
|
+
// Assert
|
|
378
|
+
const assertion = await browser.assert("page contains 'Welcome'");
|
|
379
|
+
if (!assertion.passed) {
|
|
380
|
+
console.error(assertion.message);
|
|
284
381
|
}
|
|
285
382
|
|
|
286
|
-
//
|
|
287
|
-
await browser.
|
|
383
|
+
// Generate tests
|
|
384
|
+
const tests = await browser.generateTests();
|
|
385
|
+
console.log(tests.playwrightCode);
|
|
386
|
+
|
|
387
|
+
// Cleanup
|
|
388
|
+
await browser.close();
|
|
288
389
|
```
|
|
289
390
|
|
|
290
|
-
|
|
391
|
+
## Configuration
|
|
291
392
|
|
|
292
|
-
|
|
293
|
-
import { CBrowser } from 'cbrowser';
|
|
393
|
+
### Environment Variables
|
|
294
394
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
});
|
|
395
|
+
| Variable | Default | Description |
|
|
396
|
+
|----------|---------|-------------|
|
|
397
|
+
| `CBROWSER_DATA_DIR` | `~/.cbrowser` | Data storage directory |
|
|
398
|
+
| `CBROWSER_HEADLESS` | `true` | Run headless (set to `false` for GUI) |
|
|
399
|
+
| `CBROWSER_BROWSER` | `chromium` | Browser engine |
|
|
400
|
+
| `CBROWSER_TIMEOUT` | `30000` | Default timeout (ms) |
|
|
302
401
|
|
|
303
|
-
|
|
304
|
-
console.log('Friction points:', result.frictionPoints);
|
|
305
|
-
console.log('Console logs:', result.consoleLogs);
|
|
306
|
-
```
|
|
402
|
+
### Config File
|
|
307
403
|
|
|
308
|
-
|
|
404
|
+
Create `.cbrowserrc.json`:
|
|
309
405
|
|
|
310
|
-
|
|
406
|
+
```json
|
|
407
|
+
{
|
|
408
|
+
"headless": true,
|
|
409
|
+
"timeout": 60000,
|
|
410
|
+
"persistent": true,
|
|
411
|
+
"viewport": {
|
|
412
|
+
"width": 1920,
|
|
413
|
+
"height": 1080
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
```
|
|
311
417
|
|
|
312
|
-
|
|
313
|
-
// tests/checkout.test.ts
|
|
314
|
-
import { CBrowser } from 'cbrowser';
|
|
418
|
+
## Constitutional Safety
|
|
315
419
|
|
|
316
|
-
|
|
317
|
-
let browser: CBrowser;
|
|
420
|
+
CBrowser classifies actions by risk level:
|
|
318
421
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
422
|
+
| Zone | Actions | Behavior |
|
|
423
|
+
|------|---------|----------|
|
|
424
|
+
| **Green** | Navigate, read, screenshot | Auto-execute |
|
|
425
|
+
| **Yellow** | Click, fill forms | Log and proceed |
|
|
426
|
+
| **Red** | Submit, delete, purchase | Requires `--force` |
|
|
427
|
+
| **Black** | Bypass auth, inject scripts | Never execute |
|
|
323
428
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
429
|
+
```bash
|
|
430
|
+
# Bypass safety for testing
|
|
431
|
+
cbrowser click "Delete Account" --force
|
|
432
|
+
```
|
|
327
433
|
|
|
328
|
-
|
|
329
|
-
await browser.navigate('https://shop.example.com/products');
|
|
330
|
-
await browser.click('Add to Cart');
|
|
331
|
-
await browser.click('View Cart');
|
|
434
|
+
## Performance
|
|
332
435
|
|
|
333
|
-
|
|
334
|
-
expect(cartItems.length).toBeGreaterThan(0);
|
|
335
|
-
});
|
|
336
|
-
});
|
|
337
|
-
```
|
|
436
|
+
CBrowser uses optimized Chromium launch flags for fast startup:
|
|
338
437
|
|
|
339
|
-
|
|
438
|
+
- **~1 second** browser cold start (vs 3-5s default)
|
|
439
|
+
- **Persistent context** keeps cookies between calls
|
|
440
|
+
- **Self-healing cache** reduces retry overhead
|
|
340
441
|
|
|
341
|
-
|
|
342
|
-
import { CBrowser } from 'cbrowser';
|
|
442
|
+
## Examples
|
|
343
443
|
|
|
344
|
-
|
|
345
|
-
const results = [];
|
|
346
|
-
|
|
347
|
-
for (const persona of personas) {
|
|
348
|
-
const browser = new CBrowser();
|
|
349
|
-
const result = await browser.journey({
|
|
350
|
-
persona,
|
|
351
|
-
startUrl: 'https://example.com',
|
|
352
|
-
goal: 'Complete checkout',
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
results.push({
|
|
356
|
-
persona,
|
|
357
|
-
success: result.success,
|
|
358
|
-
timeMs: result.totalTime,
|
|
359
|
-
frictionPoints: result.frictionPoints,
|
|
360
|
-
});
|
|
361
|
-
|
|
362
|
-
await browser.close();
|
|
363
|
-
}
|
|
444
|
+
See the [`examples/`](examples/) directory:
|
|
364
445
|
|
|
365
|
-
|
|
366
|
-
|
|
446
|
+
- `basic-usage.ts` - Navigation, extraction, sessions
|
|
447
|
+
- `smart-automation.ts` - Smart click, assertions, test generation
|
|
448
|
+
- `journeys/checkout-flow.json` - Persona journey definition
|
|
449
|
+
- `personas/custom-persona.json` - Custom persona template
|
|
367
450
|
|
|
368
451
|
## Troubleshooting
|
|
369
452
|
|
|
370
453
|
### Browser Not Starting
|
|
371
454
|
|
|
372
455
|
```bash
|
|
373
|
-
|
|
374
|
-
npx playwright install chromium
|
|
375
|
-
|
|
376
|
-
# Check for display issues (Linux servers)
|
|
377
|
-
export DISPLAY=:0
|
|
378
|
-
# Or run headless
|
|
379
|
-
cbrowser navigate "https://example.com" --headless
|
|
456
|
+
npx playwright install chromium --force
|
|
380
457
|
```
|
|
381
458
|
|
|
382
|
-
###
|
|
459
|
+
### Display Issues (Linux)
|
|
383
460
|
|
|
384
|
-
|
|
461
|
+
CBrowser runs headless by default. For GUI mode:
|
|
385
462
|
|
|
386
463
|
```bash
|
|
387
|
-
|
|
388
|
-
cbrowser session save "my-session" --url "https://example.com"
|
|
389
|
-
|
|
390
|
-
# Load must also be on example.com
|
|
391
|
-
cbrowser session load "my-session"
|
|
392
|
-
# This navigates to the saved URL automatically
|
|
464
|
+
CBROWSER_HEADLESS=false npx cbrowser navigate "https://example.com"
|
|
393
465
|
```
|
|
394
466
|
|
|
395
|
-
###
|
|
467
|
+
### Self-Healing Not Working
|
|
396
468
|
|
|
397
|
-
|
|
469
|
+
```bash
|
|
470
|
+
# Check cache status
|
|
471
|
+
npx cbrowser heal-stats
|
|
398
472
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
473
|
+
# Clear if corrupted
|
|
474
|
+
npx cbrowser heal-clear
|
|
475
|
+
```
|
|
402
476
|
|
|
403
477
|
## Contributing
|
|
404
478
|
|
|
405
|
-
Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
406
|
-
|
|
407
479
|
```bash
|
|
408
|
-
|
|
409
|
-
git clone https://github.com/yourusername/cbrowser.git
|
|
480
|
+
git clone https://github.com/alexandriashai/cbrowser.git
|
|
410
481
|
cd cbrowser
|
|
411
|
-
|
|
412
|
-
# Install dependencies
|
|
413
482
|
bun install
|
|
414
|
-
|
|
415
|
-
# Run in development
|
|
416
483
|
bun run dev
|
|
417
|
-
|
|
418
|
-
# Run tests
|
|
419
|
-
bun test
|
|
420
484
|
```
|
|
421
485
|
|
|
486
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
487
|
+
|
|
422
488
|
## License
|
|
423
489
|
|
|
424
|
-
MIT - see [LICENSE](LICENSE)
|
|
490
|
+
MIT - see [LICENSE](LICENSE)
|
|
425
491
|
|
|
426
|
-
##
|
|
492
|
+
## Links
|
|
427
493
|
|
|
428
|
-
-
|
|
429
|
-
-
|
|
430
|
-
-
|
|
494
|
+
- [NPM Package](https://www.npmjs.com/package/cbrowser)
|
|
495
|
+
- [GitHub Repository](https://github.com/alexandriashai/cbrowser)
|
|
496
|
+
- [Issue Tracker](https://github.com/alexandriashai/cbrowser/issues)
|
|
497
|
+
- [Roadmap](ROADMAP.md)
|