@phi-code-admin/camofox-browser 1.0.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.
Files changed (56) hide show
  1. package/AGENTS.md +571 -0
  2. package/Dockerfile +86 -0
  3. package/LICENSE +21 -0
  4. package/README.md +691 -0
  5. package/camofox.config.json +10 -0
  6. package/dist/plugin.js +616 -0
  7. package/lib/auth.js +134 -0
  8. package/lib/camoufox-executable.js +189 -0
  9. package/lib/config.js +153 -0
  10. package/lib/cookies.js +119 -0
  11. package/lib/downloads.js +168 -0
  12. package/lib/extract.js +74 -0
  13. package/lib/fly.js +54 -0
  14. package/lib/images.js +88 -0
  15. package/lib/inflight.js +16 -0
  16. package/lib/launcher.js +47 -0
  17. package/lib/macros.js +31 -0
  18. package/lib/metrics.js +184 -0
  19. package/lib/openapi.js +105 -0
  20. package/lib/persistence.js +89 -0
  21. package/lib/plugins.js +175 -0
  22. package/lib/proxy.js +277 -0
  23. package/lib/reporter.js +1102 -0
  24. package/lib/request-utils.js +59 -0
  25. package/lib/resources.js +76 -0
  26. package/lib/snapshot.js +41 -0
  27. package/lib/tmp-cleanup.js +108 -0
  28. package/lib/tracing.js +137 -0
  29. package/openclaw.plugin.json +268 -0
  30. package/package.json +148 -0
  31. package/plugin.js +616 -0
  32. package/plugin.ts +758 -0
  33. package/plugins/persistence/AGENTS.md +37 -0
  34. package/plugins/persistence/README.md +48 -0
  35. package/plugins/persistence/index.js +124 -0
  36. package/plugins/vnc/AGENTS.md +42 -0
  37. package/plugins/vnc/README.md +165 -0
  38. package/plugins/vnc/apt.txt +7 -0
  39. package/plugins/vnc/index.js +142 -0
  40. package/plugins/vnc/spawn.js +8 -0
  41. package/plugins/vnc/vnc-launcher.js +64 -0
  42. package/plugins/vnc/vnc-watcher.sh +82 -0
  43. package/plugins/youtube/AGENTS.md +25 -0
  44. package/plugins/youtube/apt.txt +1 -0
  45. package/plugins/youtube/index.js +206 -0
  46. package/plugins/youtube/post-install.sh +5 -0
  47. package/plugins/youtube/youtube.js +301 -0
  48. package/run.sh +37 -0
  49. package/scripts/exec.js +8 -0
  50. package/scripts/generate-openapi.js +24 -0
  51. package/scripts/install-plugin-deps.sh +63 -0
  52. package/scripts/plugin.js +342 -0
  53. package/scripts/postinstall.js +20 -0
  54. package/scripts/sync-version.js +25 -0
  55. package/server.js +6059 -0
  56. package/tsconfig.json +12 -0
package/README.md ADDED
@@ -0,0 +1,691 @@
1
+ <div align="center">
2
+ <img src="fox.png" alt="camofox-browser" width="200" />
3
+ <h1>camofox-browser</h1>
4
+ <p><strong>Anti-detection browser server for AI agents, powered by Camoufox</strong></p>
5
+ <p>
6
+ <a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT" /></a>
7
+ <a href="https://github.com/jo-inc/camofox-browser/stargazers"><img src="https://img.shields.io/github/stars/jo-inc/camofox-browser" alt="GitHub stars" /></a>
8
+ <a href="https://www.npmjs.com/package/camofox-browser"><img src="https://img.shields.io/npm/v/camofox-browser" alt="npm version" /></a>
9
+ <a href="https://github.com/jo-inc/camofox-browser/commits"><img src="https://img.shields.io/github/last-commit/jo-inc/camofox-browser" alt="GitHub last commit" /></a>
10
+ </p>
11
+ <p>
12
+ Standing on the mighty shoulders of <a href="https://camoufox.com">Camoufox</a> - a Firefox fork with fingerprint spoofing at the C++ level.
13
+ </p>
14
+ </div>
15
+
16
+ <br/>
17
+
18
+ > <a href="https://askjo.ai?ref=camofox"><img src="jo-logo.png" alt="Jo" width="80" height="80" align="left" /></a>
19
+ >
20
+ > Built by the team behind <a href="https://askjo.ai?ref=camofox"><strong>jo, a personal AI agent</strong></a> that runs half on your Mac, half on a dedicated cloud machine just for you -- with zero maintenance needed. Available on macOS, Telegram, WhatsApp, and email. <a href="https://askjo.ai?ref=camofox">Try the beta free -></a>
21
+
22
+ <br/>
23
+
24
+ ```bash
25
+ git clone https://github.com/jo-inc/camofox-browser && cd camofox-browser
26
+ npm install && npm start
27
+ # -> http://localhost:9377
28
+ ```
29
+
30
+ ---
31
+
32
+ ## Why
33
+
34
+ AI agents need to browse the real web. Playwright gets blocked. Headless Chrome gets fingerprinted. Stealth plugins become the fingerprint.
35
+
36
+ Camoufox patches Firefox at the **C++ implementation level** - `navigator.hardwareConcurrency`, WebGL renderers, AudioContext, screen geometry, WebRTC - all spoofed before JavaScript ever sees them. No shims, no wrappers, no tells.
37
+
38
+ This project wraps that engine in a REST API built for agents: accessibility snapshots instead of bloated HTML, stable element refs for clicking, and search macros for common sites.
39
+
40
+ ## Features
41
+
42
+ - **C++ Anti-Detection** - bypasses Google, Cloudflare, and most bot detection
43
+ - **Element Refs** - stable `e1`, `e2`, `e3` identifiers for reliable interaction
44
+ - **Token-Efficient** - accessibility snapshots are ~90% smaller than raw HTML
45
+ - **Runs on Anything** - lazy browser launch + idle shutdown keeps memory at ~40MB when idle. Designed to share a box with the rest of your stack -- Raspberry Pi, $5 VPS, shared infra.
46
+ - **Session Isolation** - separate cookies/storage per user
47
+ - **Cookie Import** - inject Netscape-format cookie files for authenticated browsing
48
+ - **Proxy + GeoIP** - route traffic through residential proxies with automatic locale/timezone
49
+ - **Structured Logging** - JSON log lines with request IDs for production observability
50
+ - **YouTube Transcripts** - extract captions from any YouTube video via yt-dlp, no API key needed
51
+ - **Search Macros** - `@google_search`, `@youtube_search`, `@amazon_search`, `@reddit_subreddit`, and 10 more
52
+ - **Snapshot Screenshots** - include a base64 PNG screenshot alongside the accessibility snapshot
53
+ - **Large Page Handling** - automatic snapshot truncation with offset-based pagination
54
+ - **Download Capture** - capture browser downloads and fetch them via API (optional inline base64)
55
+ - **DOM Image Extraction** - list `<img>` src/alt and optionally return inline data URLs
56
+ - **Deploy Anywhere** - Docker, Fly.io, Railway
57
+ - **VNC Interactive Login** - log into sites visually via noVNC, export storage state for agent reuse
58
+ - **OpenAPI Docs** - auto-generated spec at [`/openapi.json`](http://localhost:9377/openapi.json) and interactive docs at [`/docs`](http://localhost:9377/docs)
59
+ - **Structured Extract** - `POST /tabs/:tabId/extract` with a JSON Schema that maps properties to snapshot refs via `x-ref`
60
+ - **Session Tracing** - opt-in per-session Playwright trace capture (screenshots + DOM snapshots + network) with API endpoints to list, fetch, and delete trace zips
61
+ - **Telemetry** - automatic [anonymized crash/hang telemetry](lib/reporter.js#L28-L290) via GitHub Issues. Identifies which sites cause failures and common failure patterns. Private domains are HMAC-hashed, paths/params stripped, tokens/IPs redacted. Opt-out with `CAMOFOX_CRASH_REPORT_ENABLED=false`.
62
+
63
+ ## Optional Dependencies
64
+
65
+ | Dependency | Purpose | Install |
66
+ |-----------|---------|---------|
67
+ | [yt-dlp](https://github.com/yt-dlp/yt-dlp) | YouTube transcript extraction (fast path) | `pip install yt-dlp` or `brew install yt-dlp` |
68
+
69
+ The Docker image includes yt-dlp. For local dev, install it for the `/youtube/transcript` endpoint. Without it, the endpoint falls back to a slower browser-based method.
70
+
71
+ ## Quick Start
72
+
73
+ ### OpenClaw Plugin
74
+
75
+ ```bash
76
+ openclaw plugins install @askjo/camofox-browser
77
+ ```
78
+
79
+ **Tools:** `camofox_create_tab` | `camofox_snapshot` | `camofox_click` | `camofox_type` | `camofox_navigate` | `camofox_scroll` | `camofox_screenshot` | `camofox_close_tab` | `camofox_list_tabs` | `camofox_import_cookies`
80
+
81
+ ### Standalone
82
+
83
+ ```bash
84
+ git clone https://github.com/jo-inc/camofox-browser
85
+ cd camofox-browser
86
+ npm install
87
+ npm start # downloads Camoufox on first run (~300MB)
88
+ ```
89
+
90
+ Default port is `9377`. See [Environment Variables](#environment-variables) for all options.
91
+
92
+ > **Note:** the postinstall script unsets `PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD` for itself before fetching the Camoufox binary. Without that override, an exported `PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1` (common when Playwright is configured to use system Chrome) would silently skip the binary download and crash the server at runtime.
93
+ >
94
+ > **External Camoufox executable:** set `CAMOUFOX_EXECUTABLE=/path/to/camoufox-bin` before `npm install` and when starting the server to skip the bundled download and launch that executable. Compatibility aliases are `CAMOUFOX_EXECUTABLE_PATH` and `CAMOFOX_EXECUTABLE_PATH`. This is useful for NixOS paths such as `/nix/store/.../camoufox-bin`; the executable must come from a Camoufox bundle that includes `properties.json`, `version.json`, and `fontconfig/`.
95
+ >
96
+ > **Air-gapped or custom binary management:** prefer `CAMOUFOX_EXECUTABLE` when you already have a Camoufox bundle. Otherwise disable the auto-fetch with `npm install --ignore-scripts` (skips lifecycle scripts for *every* dependency -- bluntest option) or, more surgically, `npm install --omit=optional` plus a manual `npx camoufox-js fetch` step against your mirror. Note that `PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm install` no longer skips the Camoufox download (the postinstall sanitizes the env locally); use `--ignore-scripts` or `CAMOUFOX_EXECUTABLE` for that.
97
+
98
+ ### Docker
99
+
100
+ The included `Makefile` auto-detects your CPU architecture and pre-downloads Camoufox + yt-dlp binaries outside the Docker build, so rebuilds are fast (~30s vs ~3min).
101
+
102
+ ```bash
103
+ # Build and start (auto-detects arch: aarch64 on M1/M2, x86_64 on Intel)
104
+ make up
105
+
106
+ # Stop and remove the container
107
+ make down
108
+
109
+ # Force a clean rebuild (e.g. after upgrading VERSION/RELEASE)
110
+ make reset
111
+
112
+ # Just download binaries (without building)
113
+ make fetch
114
+
115
+ # Override arch or version explicitly
116
+ make up ARCH=x86_64
117
+ make up VERSION=135.0.1 RELEASE=beta.24
118
+ ```
119
+
120
+ > **WARNING: Do not run `docker build` directly.** The Dockerfile uses bind mounts to pull pre-downloaded binaries from `dist/`. Always use `make up` (or `make fetch` then `make build`) -- it downloads the binaries first.
121
+
122
+ ### Fly.io
123
+
124
+ For Fly.io or other remote CI, you'll need a Dockerfile that downloads binaries at build time instead of using bind mounts.
125
+
126
+ ### Railway
127
+
128
+ A `railway.toml` is included. It uses `Dockerfile.ci` (which downloads binaries at build time) and maps Railway's `PORT` env var to `CAMOFOX_PORT` automatically.
129
+
130
+ ```bash
131
+ # Install Railway CLI, then:
132
+ railway link
133
+ railway up
134
+ ```
135
+
136
+ Set secrets via the Railway dashboard or CLI:
137
+ ```bash
138
+ railway variables set CAMOFOX_API_KEY="your-generated-key"
139
+ ```
140
+
141
+ ## Usage
142
+
143
+ ### Cookie Import
144
+
145
+ Import cookies from your browser into Camoufox to skip interactive login on sites like LinkedIn, Amazon, etc.
146
+
147
+ #### Setup
148
+
149
+ **1. Generate a secret key:**
150
+
151
+ ```bash
152
+ # macOS / Linux
153
+ openssl rand -hex 32
154
+ ```
155
+
156
+ **2. Set the environment variable before starting OpenClaw:**
157
+
158
+ ```bash
159
+ export CAMOFOX_API_KEY="your-generated-key"
160
+ openclaw start
161
+ ```
162
+
163
+ The same key is used by both the plugin (to authenticate requests) and the server (to verify them). Both run from the same environment -- set it once.
164
+
165
+ > **Why an env var?** The key is a secret. Plugin config in `openclaw.json` is stored in plaintext, so secrets don't belong there. Set `CAMOFOX_API_KEY` in your shell profile, systemd unit, Docker env, or Fly.io secrets.
166
+
167
+ > **Cookie import is disabled by default.** If `CAMOFOX_API_KEY` is not set, the server rejects all cookie requests with 403.
168
+
169
+ **3. Export cookies from your browser:**
170
+
171
+ Install a browser extension that exports Netscape-format cookie files (e.g., "cookies.txt" for Chrome/Firefox). Export the cookies for the site you want to authenticate.
172
+
173
+ **4. Place the cookie file:**
174
+
175
+ ```bash
176
+ mkdir -p ~/.camofox/cookies
177
+ cp ~/Downloads/linkedin_cookies.txt ~/.camofox/cookies/linkedin.txt
178
+ ```
179
+
180
+ The default directory is `~/.camofox/cookies/`. Override with `CAMOFOX_COOKIES_DIR`.
181
+
182
+ **5. Ask your agent to import them:**
183
+
184
+ > Import my LinkedIn cookies from linkedin.txt
185
+
186
+ The agent calls `camofox_import_cookies` -> reads the file -> POSTs to the server with the Bearer token -> cookies are injected into the browser session. Subsequent `camofox_create_tab` calls to linkedin.com will be authenticated.
187
+
188
+ #### How it works
189
+
190
+ ```
191
+ ~/.camofox/cookies/linkedin.txt (Netscape format, on disk)
192
+ |
193
+ v
194
+ camofox_import_cookies tool (parses file, filters by domain)
195
+ |
196
+ v POST /sessions/:userId/cookies
197
+ | Authorization: Bearer <CAMOFOX_API_KEY>
198
+ | Body: { cookies: [Playwright cookie objects] }
199
+ v
200
+ camofox server (validates, sanitizes, injects)
201
+ |
202
+ v context.addCookies(...)
203
+ |
204
+ Camoufox browser session (authenticated browsing)
205
+ ```
206
+
207
+ - `cookiesPath` is resolved relative to the cookies directory -- path traversal outside it is blocked
208
+ - Max 500 cookies per request, 5MB file size limit
209
+ - Cookie objects are sanitized to an allowlist of Playwright fields
210
+
211
+ ### Session Persistence
212
+
213
+ By default, camofox persists each user's cookies and localStorage to `~/.camofox/profiles/`. Sessions survive browser restarts -- log in once (via cookies or VNC), and subsequent sessions restore the authenticated state automatically.
214
+
215
+ ```
216
+ ~/.camofox/
217
+ |-- cookies/ # Bootstrap cookie files (Netscape format)
218
+ \-- profiles/ # Persisted session state (auto-managed)
219
+ \-- <hashed-userId>/
220
+ \-- storage_state.json
221
+ ```
222
+
223
+ Override the directory with `CAMOFOX_PROFILE_DIR` or set `"profileDir"` in the persistence plugin config. To disable persistence, set `"persistence": { "enabled": false }` in `camofox.config.json`.
224
+
225
+ ### Session Tracing
226
+
227
+ Capture a Playwright trace of every action in a session: page screenshots, DOM snapshots, network requests, and console output. Output is a single `.zip` file you can open in Playwright's built-in Trace Viewer.
228
+
229
+ Opt-in per session by passing `trace: true` when opening the first tab:
230
+
231
+ ```bash
232
+ curl -X POST http://localhost:9377/tabs \
233
+ -H 'Content-Type: application/json' \
234
+ -d '{"userId":"agent1","sessionKey":"task1","url":"https://example.com","trace":true}'
235
+ ```
236
+
237
+ The trace is written when the session closes. Close the session to flush it, then list, fetch, and view:
238
+
239
+ ```bash
240
+ # Close the session to flush the trace
241
+ curl -X DELETE http://localhost:9377/sessions/agent1
242
+
243
+ # List trace files
244
+ curl http://localhost:9377/sessions/agent1/traces
245
+ # {"traces":[{"filename":"trace-2026-04-18T04-05-00-...zip","sizeBytes":42810,"createdAt":...}]}
246
+
247
+ # Download (Content-Type: application/zip)
248
+ curl http://localhost:9377/sessions/agent1/traces/trace-2026-04-18T04-05-00-abc.zip > session.zip
249
+
250
+ # View it in Playwright's Trace Viewer
251
+ npx playwright show-trace session.zip
252
+
253
+ # Delete
254
+ curl -X DELETE http://localhost:9377/sessions/agent1/traces/trace-2026-04-18T04-05-00-abc.zip
255
+ ```
256
+
257
+ Why traces instead of video: Camoufox is Firefox-based, and Playwright's `recordVideo` is Chromium-only. Traces work on Firefox and give you more than video (network + DOM + console + screenshots).
258
+
259
+ Tracing cannot be toggled on an existing session. `DELETE /sessions/:userId` first if you need to change the flag.
260
+
261
+ Storage defaults to `~/.camofox/traces/<hashed-userId>/` and is swept on server startup:
262
+
263
+ - `CAMOFOX_TRACES_DIR` - base directory (default: `~/.camofox/traces`)
264
+ - `CAMOFOX_TRACES_MAX_BYTES` - max size per trace, removed at next startup if exceeded (default: 50MB)
265
+ - `CAMOFOX_TRACES_TTL_HOURS` - traces older than this are removed at next startup (default: 24)
266
+
267
+ #### Standalone server usage
268
+
269
+ ```bash
270
+ curl -X POST http://localhost:9377/sessions/agent1/cookies \
271
+ -H 'Content-Type: application/json' \
272
+ -H 'Authorization: Bearer YOUR_CAMOFOX_API_KEY' \
273
+ -d '{"cookies":[{"name":"foo","value":"bar","domain":"example.com","path":"/","expires":-1,"httpOnly":false,"secure":false}]}'
274
+ ```
275
+
276
+ #### Docker / Fly.io / Railway
277
+
278
+ ```bash
279
+ docker run -p 9377:9377 \
280
+ -e CAMOFOX_API_KEY="your-generated-key" \
281
+ -v ~/.camofox/cookies:/home/node/.camofox/cookies:ro \
282
+ camofox-browser
283
+ ```
284
+
285
+ For Fly.io:
286
+ ```bash
287
+ fly secrets set CAMOFOX_API_KEY="your-generated-key"
288
+ ```
289
+
290
+ For Railway:
291
+ ```bash
292
+ railway variables set CAMOFOX_API_KEY="your-generated-key"
293
+ ```
294
+
295
+ ### Proxy + GeoIP
296
+
297
+ Route all browser traffic through a proxy with automatic locale, timezone, and geolocation derived from the proxy's IP address via Camoufox's built-in GeoIP.
298
+
299
+ **Simple proxy (single endpoint):**
300
+
301
+ ```bash
302
+ export PROXY_HOST=166.88.179.132
303
+ export PROXY_PORT=46040
304
+ export PROXY_USERNAME=myuser
305
+ export PROXY_PASSWORD=mypass
306
+ npm start
307
+ ```
308
+
309
+ **Backconnect proxy (rotating sticky sessions):**
310
+
311
+ For providers like Decodo, Bright Data, or Oxylabs that offer a single gateway endpoint with session-based sticky IPs:
312
+
313
+ ```bash
314
+ export PROXY_STRATEGY=backconnect
315
+ export PROXY_BACKCONNECT_HOST=gate.provider.com
316
+ export PROXY_BACKCONNECT_PORT=7000
317
+ export PROXY_USERNAME=myuser
318
+ export PROXY_PASSWORD=mypass
319
+ npm start
320
+ ```
321
+
322
+ Each browser context gets a unique sticky session, so different users get different IP addresses. Sessions rotate automatically on proxy errors or Google blocks.
323
+
324
+ Or in Docker:
325
+
326
+ ```bash
327
+ docker run -p 9377:9377 \
328
+ -e PROXY_HOST=166.88.179.132 \
329
+ -e PROXY_PORT=46040 \
330
+ -e PROXY_USERNAME=myuser \
331
+ -e PROXY_PASSWORD=mypass \
332
+ camofox-browser
333
+ ```
334
+
335
+ When a proxy is configured:
336
+ - All traffic routes through the proxy
337
+ - Camoufox's GeoIP automatically sets `locale`, `timezone`, and `geolocation` to match the proxy's exit IP
338
+ - Browser fingerprint (language, timezone, coordinates) is consistent with the proxy location
339
+ - Without a proxy, defaults to `en-US`, `America/Los_Angeles`, San Francisco coordinates
340
+
341
+ ### Telemetry
342
+
343
+ Browser automation fails in ways that are hard to predict -- Cloudflare challenges, site redesigns breaking selectors, redirect loops, dialog storms, renderer crashes. The scope is wide and the failure modes are diverse. Without telemetry, the only signal is "it didn't work."
344
+
345
+ Telemetry gives us structured data on *which sites fail*, *how they fail*, and *how often*, so we can prioritize fixes for the patterns that actually affect users. It files GitHub Issues automatically when:
346
+
347
+ - **Uncaught exceptions** crash the process
348
+ - **Event loop stalls** exceed 5 seconds (watchdog detection)
349
+ - **Frustration patterns** -- 3+ consecutive failures (timeout, dead context, navigation abort) on the same tab
350
+
351
+ Each report includes the failure type, stack trace, tab health counters (HTTP status histogram, console errors, request failures, redirect depth), and the target URL -- all anonymized.
352
+
353
+ #### How it works
354
+
355
+ Telemetry is sent to a lightweight Cloudflare Worker endpoint at [`https://camofox-telemetry.askjo.workers.dev`](https://camofox-telemetry.askjo.workers.dev/health). The endpoint holds the GitHub App credentials as environment secrets -- **no secrets are shipped in this package**.
356
+
357
+ ```
358
+ lib/reporter.js (client, no secrets)
359
+ | anonymize -> POST https://camofox-telemetry.askjo.workers.dev/report
360
+ v
361
+ Cloudflare Worker (holds GitHub App key)
362
+ | validate -> rate-limit -> dedup -> create GitHub Issue
363
+ v
364
+ GitHub Issue created
365
+ ```
366
+
367
+ The endpoint source code is in this repo at [`workers/crash-reporter/index.ts`](workers/crash-reporter/index.ts).
368
+
369
+ #### Verification
370
+
371
+ You don't have to trust us -- verify what the live endpoint is running:
372
+
373
+ ```bash
374
+ # 1. Ask the endpoint what code it's running
375
+ curl https://camofox-telemetry.askjo.workers.dev/source
376
+ # -> { "commit": "abc1234", "sha256": "e3b0c44...", "source": "https://github.com/..." }
377
+
378
+ # 2. Compare the sha256 against the source in this repo
379
+ sha256sum workers/crash-reporter/index.ts
380
+
381
+ # 3. Check the commit matches what CI deployed
382
+ # https://github.com/jo-inc/camofox-browser/actions/workflows/telemetry-deploy.yml
383
+ git log --oneline workers/crash-reporter/index.ts | head -1
384
+ ```
385
+
386
+ If the hashes don't match, the endpoint is running different code than what's in the repo. The deploy workflow ([`.github/workflows/telemetry-deploy.yml`](.github/workflows/telemetry-deploy.yml)) injects the commit and source hash at deploy time -- every deploy is auditable in [GitHub Actions](https://github.com/jo-inc/camofox-browser/actions/workflows/telemetry-deploy.yml).
387
+
388
+ Or skip verification entirely: `CAMOFOX_CRASH_REPORT_ENABLED=false` disables all telemetry, or point to [your own endpoint](#self-hosted-telemetry-endpoint) with `CAMOFOX_CRASH_REPORT_URL`.
389
+
390
+ #### Privacy
391
+
392
+ All reported data goes through paranoid anonymization ([`lib/reporter.js` L28-290](lib/reporter.js#L28-L290)) before leaving the process:
393
+
394
+ - **URLs** -- well-known public domains (Google, Amazon, Reddit, Cloudflare, etc.) are shown verbatim so we can identify which sites cause problems. Private/unknown domains are replaced with a stable HMAC hash (`site-a1b2c3d4`) -- same hash across reports for correlation, but not reversible to the original domain. Path segments become `*/*/*` (depth only). Query params become `?[3]` (count only). No keys, values, or path content is ever included.
395
+ - **File paths** -> stripped to filename only (`<path>/server.js`)
396
+ - **Tokens, secrets, API keys** -> `<token>`
397
+ - **IPs, emails, env vars** -> redacted
398
+ - **Docker/Fly machine IDs** -> `<id>`
399
+ - **Tab health** -- pure counters (crash count, error count, status code histogram). No page content, no URLs, no user data.
400
+
401
+ Duplicate issues are detected by stack signature and get a `+1` comment instead of a new issue.
402
+
403
+ ```bash
404
+ # Disable telemetry
405
+ export CAMOFOX_CRASH_REPORT_ENABLED=false
406
+
407
+ # Point to your own endpoint (see below)
408
+ export CAMOFOX_CRASH_REPORT_URL=https://your-endpoint.example.com/report
409
+
410
+ # Adjust rate limit (default: 10 per hour)
411
+ export CAMOFOX_CRASH_REPORT_RATE_LIMIT=5
412
+ ```
413
+
414
+ #### Self-hosted telemetry endpoint
415
+
416
+ To file telemetry reports in your own GitHub repo instead of `jo-inc/camofox-browser`:
417
+
418
+ 1. **Create a GitHub App** -- [Settings -> Developer settings -> GitHub Apps -> New](https://github.com/settings/apps/new)
419
+ - Permissions: **Repository -> Issues -> Read & Write**
420
+ - Uncheck **Webhook -> Active** (not needed)
421
+ - Click **Generate a key** -- downloads a `.pem` file
422
+ - Install the app on your target repo (Install App -> select repo)
423
+ - Note your **App ID** (number on the app's General page) and **Installation ID** (from the URL after installing: `github.com/settings/installations/{id}`)
424
+
425
+ 2. **Deploy the endpoint** -- clone this repo and deploy the worker:
426
+ ```bash
427
+ cd workers/crash-reporter
428
+ # Edit wrangler.toml: set account_id to your Cloudflare account ID
429
+ npx wrangler deploy
430
+ ```
431
+ The worker is a single TypeScript file with zero npm dependencies. It also runs on Deno, Bun, or any runtime with the Web Crypto API.
432
+
433
+ 3. **Set worker secrets:**
434
+ ```bash
435
+ cd workers/crash-reporter
436
+ echo "YOUR_APP_ID" | npx wrangler secret put GH_APP_ID
437
+ echo "YOUR_INSTALL_ID" | npx wrangler secret put GH_INSTALL_ID
438
+ # Key must be PKCS#8 DER base64 (not raw PEM)
439
+ openssl pkcs8 -topk8 -inform PEM -outform DER -nocrypt -in your-app.pem | \
440
+ base64 | tr -d '\n' | npx wrangler secret put GH_PRIVATE_KEY
441
+ # File issues in your repo
442
+ echo "your-org/your-repo" | npx wrangler secret put GH_REPO
443
+ ```
444
+
445
+ 4. **Point camofox-browser to your endpoint:**
446
+ ```bash
447
+ export CAMOFOX_CRASH_REPORT_URL=https://your-worker.your-subdomain.workers.dev/report
448
+ ```
449
+
450
+ 5. **Verify:**
451
+ ```bash
452
+ curl https://your-worker.your-subdomain.workers.dev/health
453
+ # -> {"status":"ok"}
454
+ ```
455
+
456
+ ### Structured Logging
457
+
458
+ All log output is JSON (one object per line) for easy parsing by log aggregators:
459
+
460
+ ```json
461
+ {"ts":"2026-02-11T23:45:01.234Z","level":"info","msg":"req","reqId":"a1b2c3d4","method":"POST","path":"/tabs","userId":"agent1"}
462
+ {"ts":"2026-02-11T23:45:01.567Z","level":"info","msg":"res","reqId":"a1b2c3d4","status":200,"ms":333}
463
+ ```
464
+
465
+ Health check requests (`/health`) are excluded from request logging to reduce noise.
466
+
467
+ ### Basic Browsing
468
+
469
+ ```bash
470
+ # Create a tab
471
+ curl -X POST http://localhost:9377/tabs \
472
+ -H 'Content-Type: application/json' \
473
+ -d '{"userId": "agent1", "sessionKey": "task1", "url": "https://example.com"}'
474
+
475
+ # Get accessibility snapshot with element refs
476
+ curl "http://localhost:9377/tabs/TAB_ID/snapshot?userId=agent1"
477
+ # -> { "snapshot": "[button e1] Submit [link e2] Learn more", ... }
478
+
479
+ # Click by ref
480
+ curl -X POST http://localhost:9377/tabs/TAB_ID/click \
481
+ -H 'Content-Type: application/json' \
482
+ -d '{"userId": "agent1", "ref": "e1"}'
483
+
484
+ # Type into an element
485
+ curl -X POST http://localhost:9377/tabs/TAB_ID/type \
486
+ -H 'Content-Type: application/json' \
487
+ -d '{"userId": "agent1", "ref": "e2", "text": "hello", "pressEnter": true}'
488
+
489
+ # Navigate with a search macro
490
+ curl -X POST http://localhost:9377/tabs/TAB_ID/navigate \
491
+ -H 'Content-Type: application/json' \
492
+ -d '{"userId": "agent1", "macro": "@google_search", "query": "best coffee beans"}'
493
+ ```
494
+
495
+ ## API
496
+
497
+ ### Tab Lifecycle
498
+
499
+ | Method | Endpoint | Description |
500
+ |--------|----------|-------------|
501
+ | `POST` | `/tabs` | Create tab with initial URL |
502
+ | `GET` | `/tabs?userId=X` | List open tabs |
503
+ | `GET` | `/tabs/:id/stats` | Tab stats (tool calls, visited URLs) |
504
+ | `DELETE` | `/tabs/:id` | Close tab |
505
+ | `DELETE` | `/tabs/group/:groupId` | Close all tabs in a group |
506
+ | `DELETE` | `/sessions/:userId` | Close all tabs for a user |
507
+
508
+ ### Page Interaction
509
+
510
+ | Method | Endpoint | Description |
511
+ |--------|----------|-------------|
512
+ | `GET` | `/tabs/:id/snapshot` | Accessibility snapshot with element refs. Query params: `includeScreenshot=true` (add base64 PNG), `offset=N` (paginate large snapshots) |
513
+ | `POST` | `/tabs/:id/click` | Click element by ref or CSS selector |
514
+ | `POST` | `/tabs/:id/type` | Type text into element |
515
+ | `POST` | `/tabs/:id/press` | Press a keyboard key |
516
+ | `POST` | `/tabs/:id/scroll` | Scroll page (up/down/left/right) |
517
+ | `POST` | `/tabs/:id/navigate` | Navigate to URL or search macro |
518
+ | `POST` | `/tabs/:id/wait` | Wait for selector or timeout |
519
+ | `GET` | `/tabs/:id/links` | Extract all links on page |
520
+ | `GET` | `/tabs/:id/images` | List `<img>` elements. Query params: `includeData=true` (return inline data URLs), `maxBytes=N`, `limit=N` |
521
+ | `GET` | `/tabs/:id/downloads` | List captured downloads. Query params: `includeData=true` (base64 file data), `consume=true` (clear after read), `maxBytes=N` |
522
+ | `GET` | `/tabs/:id/screenshot` | Take screenshot |
523
+ | `POST` | `/tabs/:id/back` | Go back |
524
+ | `POST` | `/tabs/:id/forward` | Go forward |
525
+ | `POST` | `/tabs/:id/refresh` | Refresh page |
526
+
527
+ ### YouTube Transcript
528
+
529
+ | Method | Endpoint | Description |
530
+ |--------|----------|-------------|
531
+ | `POST` | `/youtube/transcript` | Extract captions from a YouTube video |
532
+
533
+ ```bash
534
+ curl -X POST http://localhost:9377/youtube/transcript \
535
+ -H 'Content-Type: application/json' \
536
+ -d '{"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ", "languages": ["en"]}'
537
+ # -> { "status": "ok", "transcript": "[00:18] [music] We're no strangers to love [music]\n...", "video_title": "...", "total_words": 548 }
538
+ ```
539
+
540
+ Uses [yt-dlp](https://github.com/yt-dlp/yt-dlp) when available (fast, no browser needed). Falls back to a browser-based intercept method if yt-dlp is not installed -- this is slower and less reliable due to YouTube ad pre-rolls.
541
+
542
+ ### Server
543
+
544
+ | Method | Endpoint | Description |
545
+ |--------|----------|-------------|
546
+ | `GET` | `/health` | Health check |
547
+ | `POST` | `/start` | Start browser engine |
548
+ | `POST` | `/stop` | Stop browser engine |
549
+
550
+ ### Sessions
551
+
552
+ | Method | Endpoint | Description |
553
+ |--------|----------|-------------|
554
+ | `POST` | `/sessions/:userId/cookies` | Add cookies to a user session (Playwright cookie objects) |
555
+ | `GET` | `/sessions/:userId/storage_state` | Export cookies + localStorage ([VNC plugin](plugins/vnc/)) |
556
+
557
+ ## Search Macros
558
+
559
+ `@google_search` | `@youtube_search` | `@amazon_search` | `@reddit_search` | `@reddit_subreddit` | `@wikipedia_search` | `@twitter_search` | `@yelp_search` | `@spotify_search` | `@netflix_search` | `@linkedin_search` | `@instagram_search` | `@tiktok_search` | `@twitch_search`
560
+
561
+ Reddit macros return JSON directly (no HTML parsing needed):
562
+ - `@reddit_search` - search all of Reddit, returns JSON with 25 results
563
+ - `@reddit_subreddit` - browse a subreddit (e.g., query `"programming"` -> `/r/programming.json`)
564
+
565
+ ## Environment Variables
566
+
567
+ | Variable | Description | Default |
568
+ |----------|-------------|---------|
569
+ | `CAMOFOX_PORT` | Server port | `9377` |
570
+ | `PORT` | Server port (fallback, for platforms like Fly.io, Railway) | `9377` |
571
+ | `CAMOFOX_API_KEY` | Enable cookie import endpoint (disabled if unset) | - |
572
+ | `CAMOFOX_ADMIN_KEY` | Required for `POST /stop` | - |
573
+ | `CAMOFOX_ACCESS_KEY` | If set, all routes (except `/health`, cookie import, and `/stop`) require `Authorization: Bearer <key>`. Lets you safely expose the server beyond loopback. | - |
574
+ | `CAMOUFOX_EXECUTABLE` | External Camoufox executable to use instead of downloading/launching the bundled cache. Must point to a Camoufox bundle with sibling resources. | - |
575
+ | `CAMOUFOX_EXECUTABLE_PATH` | Compatibility alias for `CAMOUFOX_EXECUTABLE` | - |
576
+ | `CAMOFOX_EXECUTABLE_PATH` | Compatibility alias for `CAMOUFOX_EXECUTABLE` | - |
577
+ | `CAMOFOX_COOKIES_DIR` | Directory for cookie files | `~/.camofox/cookies` |
578
+ | `CAMOFOX_PROFILE_DIR` | Directory for persisted session profiles | `~/.camofox/profiles` |
579
+ | `CAMOFOX_TRACES_DIR` | Directory for session trace zips | `~/.camofox/traces` |
580
+ | `CAMOFOX_TRACES_MAX_BYTES` | Max size per trace, removed on next startup if exceeded | `52428800` (50MB) |
581
+ | `CAMOFOX_TRACES_TTL_HOURS` | Traces older than this are swept on startup | `24` |
582
+ | `MAX_SESSIONS` | Max concurrent browser sessions | `50` |
583
+ | `MAX_TABS_PER_SESSION` | Max tabs per session | `10` |
584
+ | `SESSION_TIMEOUT_MS` | Session inactivity timeout | `1800000` (30min) |
585
+ | `BROWSER_IDLE_TIMEOUT_MS` | Kill browser when idle (0 = never) | `300000` (5min) |
586
+ | `HANDLER_TIMEOUT_MS` | Max time for any handler | `30000` (30s) |
587
+ | `MAX_CONCURRENT_PER_USER` | Concurrent request cap per user | `3` |
588
+ | `MAX_OLD_SPACE_SIZE` | Node.js V8 heap limit (MB) | `128` |
589
+ | `PROXY_STRATEGY` | Proxy mode: `backconnect` (rotating sticky sessions) or blank (single endpoint) | - |
590
+ | `PROXY_PROVIDER` | Provider name for session format (e.g. `decodo`) | `decodo` |
591
+ | `PROXY_HOST` | Proxy hostname or IP (simple mode) | - |
592
+ | `PROXY_PORT` | Proxy port (simple mode) | - |
593
+ | `PROXY_USERNAME` | Proxy auth username | - |
594
+ | `PROXY_PASSWORD` | Proxy auth password | - |
595
+ | `PROXY_BACKCONNECT_HOST` | Backconnect gateway hostname | - |
596
+ | `PROXY_BACKCONNECT_PORT` | Backconnect gateway port | `7000` |
597
+ | `PROXY_COUNTRY` | Target country for proxy geo-targeting | - |
598
+ | `PROXY_STATE` | Target state/region for proxy geo-targeting | - |
599
+ | `TAB_INACTIVITY_MS` | Close tabs idle longer than this | `300000` (5min) |
600
+ | `CAMOFOX_CRASH_REPORT_ENABLED` | Enable anonymized crash/hang telemetry (`false` to disable) | `true` |
601
+ | `CAMOFOX_CRASH_REPORT_URL` | Telemetry endpoint ([self-hosted endpoint](#self-hosted-telemetry-endpoint)) | `https://camofox-telemetry.askjo.workers.dev/report` |
602
+ | `CAMOFOX_CRASH_REPORT_REPO` | GitHub repo for telemetry issues | `jo-inc/camofox-browser` |
603
+ | `CAMOFOX_CRASH_REPORT_RATE_LIMIT` | Max telemetry reports per hour | `10` |
604
+ | `ENABLE_VNC` | Enable VNC plugin for interactive browser access (`1`) | - |
605
+ | `VNC_PASSWORD` | Password for VNC access (recommended in production) | - |
606
+ | `NOVNC_PORT` | noVNC web UI port | `6080` |
607
+
608
+ ## Architecture
609
+
610
+ ```
611
+ Browser Instance (Camoufox)
612
+ \-- User Session (BrowserContext) - isolated cookies/storage
613
+ |-- Tab Group (sessionKey: "conv1")
614
+ | |-- Tab (google.com)
615
+ | \-- Tab (github.com)
616
+ \-- Tab Group (sessionKey: "conv2")
617
+ \-- Tab (amazon.com)
618
+ ```
619
+
620
+ Sessions auto-expire after 30 minutes of inactivity. The browser itself shuts down after 5 minutes with no active sessions, and relaunches on the next request.
621
+
622
+ When a session's tab limit is reached, the oldest/least-used tab is automatically recycled instead of returning an error -- so long-running agent sessions don't hit dead ends.
623
+
624
+ ## Security Model
625
+
626
+ This section documents the security boundaries of camofox-browser for users and automated security reviewers.
627
+
628
+ ### Code isolation
629
+
630
+ All `process.env` reads are centralized in `lib/config.js`. All `child_process` usage is in `lib/launcher.js` (server subprocess) and `plugins/youtube/youtube.js` (yt-dlp). The main `server.js` has route handlers but zero `process.env` reads and zero `child_process` imports. No single file combines environment/credential access with network sends.
631
+
632
+ ### No embedded secrets
633
+
634
+ Zero credentials, private keys, API tokens, or signing keys ship in this package. All secrets are provided at runtime via environment variables (`CAMOFOX_API_KEY`, `CAMOFOX_ACCESS_KEY`) or are Cloudflare Worker environment secrets (telemetry endpoint GitHub App key).
635
+
636
+ ### Cookie import is disabled by default
637
+
638
+ The cookie import endpoint (`POST /sessions/:userId/cookies`) is gated behind `CAMOFOX_API_KEY`. If this env var is not set, the server rejects all cookie import requests with HTTP 403. Cookie files are read from a sandboxed directory (`~/.camofox/cookies/`) with path traversal protection -- attempts to escape the directory are blocked. Max 500 cookies per request, 5MB file size limit.
639
+
640
+ ### Access control
641
+
642
+ `CAMOFOX_ACCESS_KEY` provides global bearer token authentication for all routes (except `/health`). When set, every request must include `Authorization: Bearer <key>`. Recommended for any deployment beyond localhost.
643
+
644
+ ### Binary download
645
+
646
+ The Camoufox browser engine (~300MB) is downloaded at `npm install` time by [`camoufox-js`](https://www.npmjs.com/package/camoufox-js), an npm package maintained by the [Camoufox project](https://camoufox.com). It downloads from [official GitHub releases](https://github.com/nicedayzhu/camoufox/releases) with integrity verification handled by `camoufox-js`. No custom download URLs, no URL shorteners, no raw IP addresses.
647
+
648
+ ### Telemetry
649
+
650
+ Anonymized crash/hang telemetry is sent to a Cloudflare Worker endpoint. The endpoint source is [in this repo](workers/crash-reporter/index.ts) and auditable. Verification: `GET /source` on the endpoint returns the deployed commit hash and sha256 so you can compare against the repo. The reporter ([`lib/reporter.js` L28-290](lib/reporter.js#L28-L290)) applies paranoid anonymization: private domains are HMAC-hashed (not reversible), paths are stripped, tokens/IPs/emails are redacted. No page content, cookies, or user data is ever sent. Disable with `CAMOFOX_CRASH_REPORT_ENABLED=false` or point to your own endpoint with `CAMOFOX_CRASH_REPORT_URL`.
651
+
652
+ ### Session persistence
653
+
654
+ The persistence plugin saves cookies and localStorage to `~/.camofox/profiles/<hashed-userId>/` so authenticated sessions survive browser restarts. UserIds are hashed for directory names. Disable via `camofox.config.json` by removing `persistence` from the plugins array.
655
+
656
+ ### Network access
657
+
658
+ Outbound connections are made to: (1) URLs the agent navigates to (core functionality), (2) the telemetry endpoint (anonymized, opt-out available). Inbound: the REST API on localhost:9377 (default), optionally protected by `CAMOFOX_ACCESS_KEY`.
659
+
660
+ ### Subprocess usage
661
+
662
+ Two subprocesses may be spawned: (1) the Camoufox browser engine (core functionality, `lib/launcher.js`), (2) yt-dlp for YouTube transcript extraction (optional, `plugins/youtube/youtube.js`). Both are isolated in dedicated files separate from route handlers.
663
+
664
+ ## Testing
665
+
666
+ ```bash
667
+ npm test # all tests
668
+ npm run test:e2e # e2e tests only
669
+ npm run test:live # live site tests (Google, macros)
670
+ npm run test:debug # with server output
671
+ ```
672
+
673
+ ## npm
674
+
675
+ ```bash
676
+ npm install @askjo/camofox-browser
677
+ ```
678
+
679
+ ## Credits
680
+
681
+ - [Camoufox](https://camoufox.com) - Firefox-based browser with C++ anti-detection
682
+ - [Donate to Camoufox's original creator daijro](https://camoufox.com/about/)
683
+ - [OpenClaw](https://openclaw.ai) - Open-source AI agent framework
684
+
685
+ ## Crypto Scam Warning
686
+
687
+ Sketchy people are doing sketchy things with crypto tokens named "Camofox" now that this project is getting attention. **Camofox is not a crypto project and will never be one.** Any token, coin, or NFT using the Camofox name has nothing to do with us.
688
+
689
+ ## License
690
+
691
+ MIT