C antidetect & antidetect-browser repository by @daijro. AI agent rules & system prompts with 14k stars.
# AGENTS.md
Instructions for any coding agent working in this repository or writing code
against Camoufox: Claude Code, Codex, Cursor, Copilot, Gemini or anything else.
`CLAUDE.md` and `GEMINI.md` only import this file, and `.aider.conf.yml` reads
it, so there is one set of rules. Edit them here.
---
## Before you touch anything
1. **This repository is public.** The professionalism rules below govern every
line, commit message, PR title and comment you write.
2. **Read [`ci/tribal-rules.yml`](ci/tribal-rules.yml).** It lists the decisions
this repo has already made, each with its evidence. Many are checked by
`browser/tests/native/test_tribal_rules.py`. Do not reopen one without new
evidence. When a new decision is argued and settled, add it there with its
citation.
3. **Branch off `main`. Never commit or push to `main`.** Every change is a pull
request tied to a GitHub issue ([`CONTRIBUTING.md`](CONTRIBUTING.md)).
## Before you write a function
Search for an existing implementation first: `ci/`, `browser/scripts/` and
`browser/additions/`, and for launcher code the drivers in
[CamouBrowser/camoucore](https://github.com/CamouBrowser/camoucore). Launcher changes
(Python and TypeScript, fingerprints, the CLI, the MCP server) are made there,
never here: this repository holds the browser patches, the build and the
release wrapper. If something close
exists, extend it rather than forking it. Duplicated logic is a serious defect
here, because the copies drift and a fingerprint built from two drifting copies
is detectable.
## Professionalism
A public repository is a finished product. People judge the project by what
is in it, and they will not ask what a file was for.
- **No garbage.** No scratch files, diagnostic scripts, saved test output,
logs, debug logging, commented-out code, dead code, placeholder text, stub
docs, or `TODO`s left as notes to self.
- **Nothing private reaches this repo.** That includes proprietary results,
private repo names, and per-vector stealth detail. `ci/run_sundial.py` reports
a grade and a count; the vectors never leave that module.
- Write commits and PR titles for a stranger reading them in a year.
- **Documentation is never stale.** Update the README, `docs/` and the package
READMEs in the same pull request as the code that changed them, never
"later". Every snippet must run as written.
## Code
- **Less code.** More code is a cost, not an achievement. Make minimal, general
changes, and delete dead code when you find it.
- **No band-aids.** Fix the main flow. A hard-coded value or a special case at
the call site is a bug relocated, not fixed.
- **Fallbacks are a last resort.** They turn a loud failure into a silent wrong
answer, and in an anti-detect browser a silent wrong answer is a fingerprint.
Fail loudly instead.
- **Check real data before inventing a value.** Every spoofed value must be
something a real device reports. Take it from the recorded distributions
(fpgen, the driver's data files in camoucore), not from memory.
- **Read the provider's docs** before writing against a third-party API or a
Firefox internal. Never infer an endpoint, pref or field from memory.
- **Comments say why, in a sentence or two.** Simple code needs none. A longer
explanation is a decision: put it in `ci/tribal-rules.yml` or `docs/`.
## Tests
- **Run the failing test, not the whole suite.** CI runs the full pipeline on
every pull request.
- **Write test output to a log file and grep the file.** Piping a run straight
into `grep` throws away output you will need. Delete the log afterwards.
- **Every bug gets a regression test, in this order:** reproduce it with a test
and confirm the test fails, fix the bug, confirm the test passes, then land
both.
- **No flakes.** An intermittent failure means something is non-deterministic.
Fix that behaviour. Never retry, loosen a threshold or skip the test to get
green. A timing check measures what the browser did, never the driver's
sleep: the browser sees a `wait_for_timeout(n)` as n ms plus the driver's
and its own latency, which is unbounded on a loaded runner. Bound such a
quantity on one side (at least what n ms allows), and check order with
event order (nothing after the keyup), not with counts. A guard that waits
for something to be freed or settle polls to a deadline instead of
sleeping a fixed time. A guard that fails only on a loaded runner may be
showing a real difference from Firefox under load (driven key repeats
burst where Firefox skips them): compare stock Firefox under the same load
before deciding the check is wrong. Before trusting a fix, run the guard
many times on the CI runners, and break the code it guards to see it fail.
- **A missing prerequisite fails in CI; it never passes as a skip.** A skip
reads as green, so a job that forgot to install something passes having
tested nothing.
- **When local and CI disagree, name the mechanism and fix it in the repo.**
Typical causes are git-ignored inputs, skipped prerequisites and cold-cache
races. A fresh clone is a sanity check, not a fix.
- **Never write a test just to pass, or code just to pass a test.**
## Security
- **Never commit a credential.** That covers code, config, fixtures, logs and
commit messages. CI secrets live in GitHub Actions secrets.
- **Least privilege** for workflows and tokens. Grant `permissions:` per job,
and only what that job needs.
- **Adding a dependency is a decision.** Say why in the pull request, and commit
the lockfile.
## Working with the maintainers
- Say when a direction is wrong, before starting, and give the reason.
- Review your own diff the way a strict senior reviewer would. You are biased
toward what you just wrote.
- Explain plainly and briefly.
## Parallel work
- **Separate pull requests:** one agent per task, each in its own git worktree,
running at the same time.
- **One pull request with independent slow parts:** use subagents in worktrees.
Merge each part into your branch as it finishes, then delete the worktrees.
- **Shared files or an ordering requirement:** use one agent.
---
# Repository
## What this is
Camoufox is an anti-detect Firefox for web scraping and automation. This repo
is **not the Firefox source**. It is a build system that fetches upstream
Firefox, applies `browser/patches/` and copies in `browser/additions/`, and
produces the browser. Fingerprint spoofing happens in C++ and in Juggler, not in
injected JavaScript, so a page cannot see it.
`browser/upstream.sh` pins `version` and `release`. `browser/Makefile` sources
and exports it, so every script sees them. Run `make` from `browser/`. The
Firefox tree lives in `browser/camoufox-<version>-<release>/`. It is generated:
persist a change there as a patch, never as an edit to that tree.
| Path | What it is |
|---|---|
| `browser/` | The browser build: `Makefile`, `upstream.sh`, `multibuild.py`, `Dockerfile`, and the directories below. |
| `browser/patches/` | Diffs applied to Firefox: one per behaviour at the top level, plus `playwright/`, `librewolf/` and `ghostery/`. Browser behaviour changes here. |
| `browser/additions/camoucfg/` | The C++ config layer. `MaskConfig.hpp` reads `CAMOU_CONFIG`, which the patches consult. |
| `browser/additions/juggler/` | Camoufox's Juggler, Playwright's Firefox protocol. The page agent runs in an isolated world. `input/` holds `MouseDispatch.js` (every synthesized mouse event) and `HumanDelay.js`; the browser adds no humanization of its own ([`docs/humanize.md`](docs/humanize.md)). |
| `browser/settings/` | `camoufox.cfg` (prefs), `properties.json` (every config key and its type; a key the browser stops reading is marked `removed`, never deleted). |
| `browser/scripts/` | `patch.py` applies patches and writes the mozconfig; `copy-additions.sh`, `package.py`, `install-deps.sh`, font tooling. |
| `browser/assets/` | Mozconfigs, README images. |
| `browser/bundle/` | The per-OS `fontconfig/` files and `FONTS-README.txt`. The fonts are a release asset (`make fonts-extract`), pinned by `browser/scripts/data/font-bundle.json`. |
| `browser/tests/` | Browser test suites (below): `build-tester/`, `native/`, `service/`, `playwright/`. |
| `browser/INTERFACE` | The launch interface this build speaks. A driver accepts a range of it ([`ci/README.md`](ci/README.md#the-driver)). |
| `pyproject.toml`, `camoufox/`, `camoufox_pin/`, `npm/` | The `camoufox` release wrapper on PyPI and npm: camoucore's launcher (`camoucore.camoufox`) under the `camoufox` name, one alias stub per module, an exact `camoucore` pin, and the browser pin that `release.yml` stamps. MIT (`camoufox/LICENSE`, `npm/LICENSE`). No launcher code: `ci/check_no_driver.py` fails a PR that adds any, and `ci/check_wrapper.py` checks an install against camoucore ([`ci/README.md`](ci/README.md#the-driver)). |
| `ci/` | The test pipeline (below). `ci/tribal-rules.yml` holds the settled decisions. |
| `docs/` | Design notes and maintenance guides. |
## Building
The build runs on **Linux**. Windows and macOS binaries are cross-compiled from
it. `mach` needs Python 3.11 or newer.
```bash
cd browser
make dir # fetch Firefox, copy additions, apply every patch
make bootstrap # one time: scripts/install-deps.sh + mach bootstrap
make build # ./mach build
make run # run the build (wipes ~/.camoufox)
make package-linux arch=x86_64 # or package-macos / package-windows
python3 multibuild.py --target linux windows macos --arch x86_64 arm64
python3 multibuild.py --target windows macos --arch x86_64 --preflight # compile what the patches touch, in minutes
```
A pull request builds Linux x86_64 only. CI preflights the other release
targets, and `--preflight` does the same locally for a patch with code for
another OS or CPU.
Every build, a local one included, is optimized as stock is
([`builds-are-optimized-like-stock`](ci/tribal-rules.yml)): with the PGO
profile Mozilla trained for the same Firefox, cross-language LTO (full on
x86_64 Linux and Windows, thin elsewhere) and Rust SIMD, from
`browser/assets/base.mozconfig`. `make dir` installs the Rust release Mozilla
builds the tree with and fetches the profile pinned in
`browser/scripts/data/pgo-profiles.json`; after bumping `upstream.sh`, run
`python3 scripts/pgo.py pin` and `python3 scripts/remote_settings.py pin` (the
page-visible lists, bundled so the browser never polls for them). Install `ccache`. It caches compiles but not the
LTO link, so an incremental build still relinks libxul across C++ and Rust.
## Changing a patch
Never hand-edit a `.patch` file. Edit the tree, then write the diff, from
`browser/`:
```bash
make dir && make first-checkpoint # a new patch: checkpoint, edit, then
make diff > patches/my-change.patch # (git add -N new files first)
make dir && make workspace ./patches/x.patch # an existing patch: edit, then
make diff > patches/x.patch
```
`make patch` and `make unpatch` apply or reverse one patch. `make revert` resets
the tree to unpatched Firefox. Every make target is described in
[`docs/patch-upgrading-guide.md`](docs/patch-upgrading-guide.md#the-source-tree-and-its-make-targets),
which also covers porting patches to a new Firefox and porting Playwright. Keep
the `Makefile` diff minimal: host dependencies belong in
`browser/scripts/install-deps.sh`.
## Testing
`ci/` is the whole pipeline. It runs the same way locally and on a pull request
([`ci/README.md`](ci/README.md), which lists every runner). Branch protection
requires one check, **`All tests passed`**. Run the suite that covers your
change while you work:
| You changed | Run |
|---|---|
| Patches, C++, Juggler | `python3 -m ci.run_build_tester --binary <camoufox-bin>` (the anti-detect suite) and `python3 -m ci.run_patch_guards --binary <camoufox-bin>` (one guard per shipped behaviour, in three groups: `--group spoofing|automation|parity`) |
| Automation behaviour | `make -C browser tests`, the upstream Playwright suite with `ci/skiplist.yml` applied |
| `ci/` itself | `python3 -m pytest ci/tests -q` |
- **`browser/tests/playwright/` is not a fork of Playwright's tests.** It holds
only `patches/` and `camoufox/`. A deliberate difference from upstream goes
in `ci/skiplist.yml`, with its reason.
- **Tests against an unpackaged build** need `make -C browser stage-fonts` first.
Without it the browser has no content fonts.
- **The stealth grade** (`ci/run_sundial.py`) reports a letter and a count, never
the individual vectors.
---
# Using Camoufox
The drivers are the `camoufox` packages on PyPI and npm (`pip install
"camoufox[geoip]"`, `npm i camoufox`), the launcher in the `camoucore`
package under the `camoufox` name. Its source, issues and docs, the
full reference for every launch option, the CLI and examples, are in
[CamouBrowser/camoucore](https://github.com/CamouBrowser/camoucore). Every
config key and its type is in
[`browser/settings/properties.json`](browser/settings/properties.json). Keep
this section in step with the launcher options.
## Public API
| Python | TypeScript | Returns |
|---|---|---|
| `camoufox.sync_api.Camoufox(**opts)` (context manager) | `Camoufox(opts)` | `Browser`, or `BrowserContext` with `persistent_context` |
| `camoufox.async_api.AsyncCamoufox(**opts)` (async context manager) | `AsyncCamoufox(opts)` (alias of `Camoufox`) | same |
| `camoufox.sync_api.NewBrowser(playwright, **opts)` | `NewBrowser(firefox, opts)` | same, on your own Playwright instance |
| `camoufox.async_api.AsyncNewBrowser(playwright, **opts)` | `AsyncNewBrowser` (alias) | same |
| `camoufox.sync_api.NewContext(browser, **kw)` | `NewContext(browser, opts)` | `BrowserContext` with its own identity |
| `camoufox.async_api.AsyncNewContext(browser, **kw)` | `AsyncNewContext` (alias) | same |
| `camoufox.launch_options(**opts)` | `launchOptions(opts)` | kwargs for `firefox.launch()` (TS: camelCase keys) |
| `camoufox.server.launch_server(**opts)` | `launchServer(opts)` | Python blocks and prints the ws endpoint; TS returns a `BrowserServer` |
| `camoufox.DefaultAddons.UBO` | `"UBO"` | default addon id for `exclude_addons` |
| `camoufox.fingerprints.Screen(max_width=, max_height=, min_width=, min_height=)` | `Screen({ maxWidth, ... })` or a plain object | bound for `screen` |
## Pitfalls
- **Do not set identity values by hand.** Do not pass Playwright's `user_agent`, or `navigator.*`, `headers.User-Agent`, `screen.*`, `window.*`, `timezone` or `geolocation:*` in `config`. The identity is drawn as a whole; overriding one value leaves the rest describing a different machine. Use `os`, `screen`, `window`, `locale` and `geoip` instead. Manual config keys print a `LeakWarning`. The coherence checks never replace a key the caller set: one that contradicts the rest of the identity (a Mac at colorDepth 24, a macOS devicePixelRatio of 1.5) is kept, with a second `LeakWarning` that `i_know_what_im_doing` does not silence. Drawn values are repaired; every macOS identity reports colorDepth 30.
- **Use `geoip=True` with a proxy.** Without it the timezone and locale are the identity's, not the proxy's, and a warning is printed.
- **`page.evaluate` is isolated.** It cannot read globals the page defined. Use `main_world_eval=True` and prefix the script with `mw:`. Without the option, a `mw:` evaluate fails with "Main world evaluation is disabled". `mw:` cannot return a handle (`evaluate_handle`).
- **Leave the viewport alone.** When the window size is spoofed, new pages default to `no_viewport=True`; forcing a `viewport` asks the window to resize to something the identity does not claim.
- **The OS counts clicks and repeats keys.** A press's `detail` follows the identity's OS, not `click_count`: presses count up only when quick and in place (`dblclick` is). A key held with `keyboard.down` repeats until `keyboard.up`, with that OS's delay and interval ([docs/input-dispatch.md](docs/input-dispatch.md#click-count)).
- **`is_mobile` is ignored** (with a warning). Camoufox has desktop identities only.
- **Persistent contexts** need `persistent_context=True` and `user_data_dir`, and cannot be served by `launch_server`.
- **`headless="virtual"`** needs Linux, `Xvfb` and `setpriv` from util-linux (`CannotFindXvfb`, `VirtualDisplayNotSupported` otherwise). Xvfb has no GPU, so canvas and WebGL render in software and the identity reports `llvmpipe`.
- **`headless="virtual-gpu"`** renders on one GPU, named by `gpu=` or `CAMOUFOX_GPU` (a PCI address is the stable choice); several GPUs and no selector raise `AmbiguousGpuSelection`. Without root it needs Xorg.wrap allowed to start Xorg as root for any user, and the card's config in `/etc/X11`; `python -m camoufox gpu-setup <gpu> | sudo sh` does both, and every failure that setup would fix ends with that command. A browser that does not render on the card raises `GpuSoftwareFallback` (`require_gpu=False` warns). Every error is a `VirtualDisplayError`. `gpu` and `require_gpu` are not `launch_options()` arguments.
- **`os` values are lowercase** `windows`, `macos`, `linux`; anything else raises `InvalidOS`.
- **`geoip` in Python needs the extra**: `pip install "camoufox[geoip]"`, else `NotInstalledGeoIPExtra`.
- **`InvalidIP`** is raised when the public-IP or proxy exit-IP lookup fails, or when `webrtc_ip` is not a valid IPv4/IPv6 address. Pass `webrtc_ip`, `timezone_id`, `locale` and `geolocation` to `NewContext` to skip the lookup.
- **`InvalidProxy`** means the proxy `server` string could not be parsed.
- **`UnknownIPLocation`**: the IP is not in the GeoIP database; pass `locale` and set coordinates another way.
- **Version ceilings:** Playwright below 1.63; Node.js 22.15 or newer.
- **Each package release is paired with one browser build.** `camoufox set` overrides it (with a warning at launch), the `browser` option overrides it for one launch, and `camoufox set --release` restores it.
- **`browser` and `executable_path` are exclusive**: passing `browser` with `executable_path`, or while `CAMOUFOX_EXECUTABLE_PATH` is set, raises `ValueError`.
- **Canvas is not noised on the host's OS**: the identity claims the host's GPU or software renderer (`llvmpipe` on Linux), and the canvas hash is stable per machine. An identity on another OS, or claiming a GPU that is not the host's (`webgl_config`, a preset's GPU, or a host GPU fpgen never recorded), gets `privacy.resistFingerprinting`'s random canvas readback (as in LibreWolf), with a `LeakWarning`; `canvas_noise=True`/`False` forces it. It is per browser: contexts of a browser without it claim the host's OS and GPU, and `NewContext` raises for another OS or GPU.
- **A Windows launch on another host is Windows for every context.** The Windows CRT math, the Windows keyboard (GTK only: on a macOS host just the editor caret style), the behaviour prefs and the scrollbars (docs/HOST-PARITY.md) are prefs and launch config, so they belong to the browser, not the context. A `macos` or `linux` context on that browser has them too; a Windows context on a browser launched as macOS or Linux has the host's. `NewContext` does not refuse either, because a launch without `os` draws its OS, and the refusal would depend on that draw. To mix OSes, pass `os` at launch for the one whose behaviour matters, or use one browser per OS.