cbrowser 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,237 @@
1
+ # CBrowser Installation Guide
2
+
3
+ ## Quick Install
4
+
5
+ ```bash
6
+ # npm
7
+ npm install cbrowser
8
+
9
+ # yarn
10
+ yarn add cbrowser
11
+
12
+ # bun
13
+ bun add cbrowser
14
+
15
+ # pnpm
16
+ pnpm add cbrowser
17
+ ```
18
+
19
+ ## Browser Setup
20
+
21
+ CBrowser uses Playwright for browser automation. After installing, you need to install the browser binaries:
22
+
23
+ ```bash
24
+ npx playwright install chromium
25
+ ```
26
+
27
+ This downloads Chromium (~150MB). For full browser support:
28
+
29
+ ```bash
30
+ npx playwright install # Installs Chromium, Firefox, and WebKit
31
+ ```
32
+
33
+ ## Verify Installation
34
+
35
+ ```bash
36
+ npx cbrowser help
37
+ ```
38
+
39
+ You should see the help text with all available commands.
40
+
41
+ ## Configuration
42
+
43
+ ### Data Directory
44
+
45
+ By default, CBrowser stores data in `~/.cbrowser/`. To change this:
46
+
47
+ ```bash
48
+ # Set environment variable
49
+ export CBROWSER_DATA_DIR="/path/to/custom/dir"
50
+
51
+ # Or per-command
52
+ CBROWSER_DATA_DIR="./data" npx cbrowser navigate "https://example.com"
53
+ ```
54
+
55
+ ### Environment Variables
56
+
57
+ | Variable | Default | Description |
58
+ |----------|---------|-------------|
59
+ | `CBROWSER_DATA_DIR` | `~/.cbrowser` | Data storage directory |
60
+ | `CBROWSER_HEADLESS` | `false` | Run headless by default |
61
+ | `CBROWSER_TIMEOUT` | `30000` | Default timeout (ms) |
62
+ | `CBROWSER_VIEWPORT_WIDTH` | `1280` | Default viewport width |
63
+ | `CBROWSER_VIEWPORT_HEIGHT` | `800` | Default viewport height |
64
+ | `CBROWSER_VERBOSE` | `false` | Enable verbose logging |
65
+
66
+ ### Persistent Configuration
67
+
68
+ Create a `.cbrowserrc` file in your project or home directory:
69
+
70
+ ```json
71
+ {
72
+ "headless": true,
73
+ "timeout": 60000,
74
+ "viewportWidth": 1920,
75
+ "viewportHeight": 1080
76
+ }
77
+ ```
78
+
79
+ ## Platform-Specific Notes
80
+
81
+ ### Linux
82
+
83
+ If running on a headless server, you may need additional dependencies:
84
+
85
+ ```bash
86
+ # Ubuntu/Debian
87
+ sudo apt-get install libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm1 libpango-1.0-0 libcairo2 libasound2
88
+
89
+ # Or use Playwright's helper
90
+ npx playwright install-deps chromium
91
+ ```
92
+
93
+ ### macOS
94
+
95
+ No additional setup required. Works out of the box.
96
+
97
+ ### Windows
98
+
99
+ No additional setup required. Works out of the box.
100
+
101
+ ### Docker
102
+
103
+ ```dockerfile
104
+ FROM node:20-slim
105
+
106
+ # Install Playwright dependencies
107
+ RUN apt-get update && apt-get install -y \
108
+ libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 \
109
+ libxkbcommon0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 \
110
+ libgbm1 libpango-1.0-0 libcairo2 libasound2 \
111
+ && rm -rf /var/lib/apt/lists/*
112
+
113
+ WORKDIR /app
114
+ COPY package*.json ./
115
+ RUN npm install
116
+
117
+ # Install browser
118
+ RUN npx playwright install chromium
119
+
120
+ COPY . .
121
+
122
+ # Run in headless mode
123
+ ENV CBROWSER_HEADLESS=true
124
+
125
+ CMD ["npx", "cbrowser", "help"]
126
+ ```
127
+
128
+ ## CI/CD Integration
129
+
130
+ ### GitHub Actions
131
+
132
+ ```yaml
133
+ name: Browser Tests
134
+
135
+ on: [push, pull_request]
136
+
137
+ jobs:
138
+ test:
139
+ runs-on: ubuntu-latest
140
+ steps:
141
+ - uses: actions/checkout@v4
142
+ - uses: actions/setup-node@v4
143
+ with:
144
+ node-version: '20'
145
+
146
+ - run: npm install
147
+ - run: npx playwright install chromium
148
+
149
+ - name: Run CBrowser tests
150
+ run: npm test
151
+ env:
152
+ CBROWSER_HEADLESS: true
153
+ ```
154
+
155
+ ### GitLab CI
156
+
157
+ ```yaml
158
+ test:
159
+ image: mcr.microsoft.com/playwright:v1.40.0
160
+ script:
161
+ - npm install
162
+ - npm test
163
+ variables:
164
+ CBROWSER_HEADLESS: "true"
165
+ ```
166
+
167
+ ## Troubleshooting
168
+
169
+ ### "Browser not found" Error
170
+
171
+ ```bash
172
+ # Reinstall browser
173
+ npx playwright install chromium --force
174
+ ```
175
+
176
+ ### Permission Denied on Linux
177
+
178
+ ```bash
179
+ # Make data directory writable
180
+ sudo chown -R $USER:$USER ~/.cbrowser
181
+ chmod -R 755 ~/.cbrowser
182
+ ```
183
+
184
+ ### Timeout Errors
185
+
186
+ Increase the default timeout:
187
+
188
+ ```bash
189
+ CBROWSER_TIMEOUT=60000 npx cbrowser navigate "https://slow-site.com"
190
+ ```
191
+
192
+ ### Display Issues (Linux Server)
193
+
194
+ Use headless mode:
195
+
196
+ ```bash
197
+ CBROWSER_HEADLESS=true npx cbrowser navigate "https://example.com"
198
+ ```
199
+
200
+ Or set up a virtual display:
201
+
202
+ ```bash
203
+ # Install Xvfb
204
+ sudo apt-get install xvfb
205
+
206
+ # Run with virtual display
207
+ xvfb-run npx cbrowser navigate "https://example.com"
208
+ ```
209
+
210
+ ## Upgrading
211
+
212
+ ```bash
213
+ # npm
214
+ npm update cbrowser
215
+
216
+ # Check version
217
+ npx cbrowser --version
218
+ ```
219
+
220
+ ## Uninstalling
221
+
222
+ ```bash
223
+ # Remove package
224
+ npm uninstall cbrowser
225
+
226
+ # Remove data directory (optional)
227
+ rm -rf ~/.cbrowser
228
+
229
+ # Remove Playwright browsers (optional)
230
+ rm -rf ~/.cache/ms-playwright
231
+ ```
232
+
233
+ ## Getting Help
234
+
235
+ - Check [README.md](../README.md) for usage examples
236
+ - Open an issue on GitHub for bugs
237
+ - See [CONTRIBUTING.md](../CONTRIBUTING.md) for development setup
@@ -0,0 +1,96 @@
1
+ /**
2
+ * CBrowser Basic Usage Examples
3
+ *
4
+ * Run with: npx ts-node examples/basic-usage.ts
5
+ */
6
+
7
+ import { CBrowser } from "../src/index.js";
8
+
9
+ async function basicNavigation() {
10
+ console.log("=== Basic Navigation ===\n");
11
+
12
+ const browser = new CBrowser({ headless: true });
13
+
14
+ try {
15
+ // Navigate to a page
16
+ const result = await browser.navigate("https://example.com");
17
+ console.log(`Navigated to: ${result.url}`);
18
+ console.log(`Page title: ${result.title}`);
19
+ console.log(`Load time: ${result.loadTime}ms`);
20
+
21
+ // Extract headings
22
+ const headings = await browser.extract("headings");
23
+ console.log("\nHeadings found:", JSON.stringify(headings.data, null, 2));
24
+
25
+ // Take a screenshot
26
+ const screenshot = await browser.screenshot("./example-screenshot.png");
27
+ console.log(`\nScreenshot saved: ${screenshot}`);
28
+ } finally {
29
+ await browser.close();
30
+ }
31
+ }
32
+
33
+ async function sessionPersistence() {
34
+ console.log("\n=== Session Persistence ===\n");
35
+
36
+ const browser = new CBrowser({ headless: true });
37
+
38
+ try {
39
+ // Navigate and save session
40
+ await browser.navigate("https://example.com");
41
+ await browser.saveSession("example-session");
42
+ console.log("Session saved: example-session");
43
+
44
+ // List sessions
45
+ const sessions = browser.listSessions();
46
+ console.log("Available sessions:", sessions);
47
+ } finally {
48
+ await browser.close();
49
+ }
50
+
51
+ // New browser instance, load session
52
+ const browser2 = new CBrowser({ headless: true });
53
+
54
+ try {
55
+ const loaded = await browser2.loadSession("example-session");
56
+ console.log(`Session loaded: ${loaded}`);
57
+ } finally {
58
+ await browser2.close();
59
+ }
60
+ }
61
+
62
+ async function personaJourney() {
63
+ console.log("\n=== Persona Journey ===\n");
64
+
65
+ const browser = new CBrowser({ headless: true });
66
+
67
+ try {
68
+ const result = await browser.journey({
69
+ persona: "first-timer",
70
+ startUrl: "https://example.com",
71
+ goal: "Find more information",
72
+ maxSteps: 5,
73
+ });
74
+
75
+ console.log(`Journey completed: ${result.success}`);
76
+ console.log(`Steps taken: ${result.steps.length}`);
77
+ console.log(`Total time: ${result.totalTime}ms`);
78
+
79
+ if (result.frictionPoints.length > 0) {
80
+ console.log("\nFriction points found:");
81
+ for (const point of result.frictionPoints) {
82
+ console.log(` - ${point}`);
83
+ }
84
+ }
85
+ } finally {
86
+ await browser.close();
87
+ }
88
+ }
89
+
90
+ async function main() {
91
+ await basicNavigation();
92
+ await sessionPersistence();
93
+ await personaJourney();
94
+ }
95
+
96
+ main().catch(console.error);
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "checkout-flow",
3
+ "description": "Test the complete checkout process",
4
+ "persona": "first-timer",
5
+ "startUrl": "https://example-shop.com",
6
+ "goal": "Complete a purchase from product selection to confirmation",
7
+ "maxSteps": 30,
8
+ "expectedSteps": [
9
+ {
10
+ "description": "Find a product",
11
+ "successIndicators": ["product page", "add to cart button"]
12
+ },
13
+ {
14
+ "description": "Add to cart",
15
+ "successIndicators": ["cart updated", "item added"]
16
+ },
17
+ {
18
+ "description": "View cart",
19
+ "successIndicators": ["cart page", "checkout button"]
20
+ },
21
+ {
22
+ "description": "Begin checkout",
23
+ "successIndicators": ["checkout form", "shipping address"]
24
+ },
25
+ {
26
+ "description": "Complete purchase",
27
+ "successIndicators": ["confirmation", "order number", "thank you"]
28
+ }
29
+ ],
30
+ "frictionThresholds": {
31
+ "maxTimePerStep": 30000,
32
+ "maxErrorsPerStep": 2,
33
+ "maxBacktracks": 3
34
+ }
35
+ }
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "qa-tester",
3
+ "description": "QA tester systematically checking functionality",
4
+ "demographics": {
5
+ "age_range": "25-40",
6
+ "tech_level": "expert",
7
+ "device": "desktop"
8
+ },
9
+ "behaviors": {
10
+ "methodical": true,
11
+ "checks_edge_cases": true,
12
+ "documents_issues": true,
13
+ "follows_test_plans": true
14
+ },
15
+ "humanBehavior": {
16
+ "timing": {
17
+ "reactionTime": { "min": 200, "max": 500 },
18
+ "clickDelay": { "min": 100, "max": 300 },
19
+ "typeSpeed": { "min": 50, "max": 100 },
20
+ "readingSpeed": 300,
21
+ "scrollPauseTime": { "min": 200, "max": 500 }
22
+ },
23
+ "errors": {
24
+ "misClickRate": 0.03,
25
+ "doubleClickAccidental": 0.02,
26
+ "typoRate": 0.03,
27
+ "backtrackRate": 0.1
28
+ },
29
+ "mouse": {
30
+ "curvature": 0.3,
31
+ "jitter": 3,
32
+ "overshoot": 0.08,
33
+ "speed": "normal"
34
+ },
35
+ "attention": {
36
+ "pattern": "thorough",
37
+ "scrollBehavior": "chunked",
38
+ "focusAreas": ["cta", "text", "images"],
39
+ "distractionRate": 0.05
40
+ }
41
+ },
42
+ "context": {
43
+ "viewport": [1920, 1080]
44
+ }
45
+ }
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "cbrowser",
3
+ "version": "2.2.0",
4
+ "description": "AI-powered browser automation with constitutional safety, personas, session persistence, and autonomous journeys",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "bin": {
8
+ "cbrowser": "./dist/cli.js"
9
+ },
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "dev": "tsc --watch",
13
+ "start": "bun run src/cli.ts",
14
+ "test": "bun test",
15
+ "lint": "eslint src/",
16
+ "clean": "rm -rf dist/",
17
+ "prepublishOnly": "npm run build"
18
+ },
19
+ "keywords": [
20
+ "browser-automation",
21
+ "playwright",
22
+ "ai-testing",
23
+ "web-scraping",
24
+ "e2e-testing",
25
+ "persona-testing",
26
+ "session-management",
27
+ "constitutional-ai",
28
+ "autonomous-agent"
29
+ ],
30
+ "author": "Your Name",
31
+ "license": "MIT",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/yourusername/cbrowser.git"
35
+ },
36
+ "bugs": {
37
+ "url": "https://github.com/yourusername/cbrowser/issues"
38
+ },
39
+ "homepage": "https://github.com/yourusername/cbrowser#readme",
40
+ "engines": {
41
+ "node": ">=18.0.0"
42
+ },
43
+ "dependencies": {
44
+ "playwright": "^1.40.0"
45
+ },
46
+ "devDependencies": {
47
+ "@types/node": "^20.10.0",
48
+ "typescript": "^5.3.0",
49
+ "eslint": "^8.55.0",
50
+ "@typescript-eslint/eslint-plugin": "^6.13.0",
51
+ "@typescript-eslint/parser": "^6.13.0"
52
+ },
53
+ "files": [
54
+ "dist/",
55
+ "examples/",
56
+ "docs/",
57
+ "README.md",
58
+ "LICENSE"
59
+ ]
60
+ }