Camoufox
repository·main·Indexed 42 days ago
https://github.com/cloverlabsai/camoufoxAn open-source, stealth-optimized Firefox fork designed for AI agents and LLM-driven automation. It focuses on being undetectable and efficient for web scraping and agentic workflows, featuring a Python package for browser management and a build tester to validate binaries against antibot-detection checks.
What's inside Camoufox
- Camoufox is an open-source Firefox fork specifically engineered for AI agents. It is designed to be lightweight, headless, and undetectable, making it optimized for LLM automation. Its core purpose is to provide a browser that mimics human behavior to bypass bot detection, prevent fingerprint leaks, and reduce token waste by providing cleaner DOM structures for AI parsing.
Camoufox Capabilities Overview
mainCamoufox provides several layers of stealth and optimization:
Fingerprint Spoofing
- Navigator & Hardware: Device, browser, locale, screen size, resolution, viewport, and battery API.
- Media: WebGL (parameters, extensions, context), AudioContext (sample rate, latency), device voices, and playback rates. Spoofs number of microphones, webcams, and speakers.
- Network & Location: WebRTC IP spoofing at the protocol level, Geolocation, timezone, and locale. Network headers (
Accept-Languages,User-Agent) match navigator properties.
Stealth Patches
- Isolation: Sandboxes Playwright's Page Agent JavaScript to prevent detection via
window.__playwright__binding__or frame execution context leaks. - Detection Evasion: Fixes
navigator.webdriverand Firefox headless detection. Uses human-like cursor movement.
Anti-Fingerprinting & Optimization
- Fonts: Automatically uses correct system fonts for the target User Agent and prevents font metrics fingerprinting by randomly offsetting letter spacing.
- Debloating: Stripped of many Mozilla services and telemetry (via LibreWolf/Ghostery patches). Removes CSS animations for speed and memory efficiency.
Addons
- Supports loading Firefox addons via the
addonsproperty (list of paths). Includes uBlock Origin with custom privacy filters.
Understand the limitations of Per-Context Fingerprint Patches
mainPer-context patches control what JavaScript APIs report, but they cannot change how the underlying OS renders content. Because certain detection vectors operate below the browser layer, they will leak the real OS identity.
Key detection vectors that cannot be spoofed include:
- Font rendering: Differences in subpixel hinting and glyph outlines between Core Text (macOS), DirectWrite (Windows), and FreeType (Linux) affect
canvas.measureText()andtoDataURL()hashes. - Canvas device class: GPU drivers produce OS-specific rasterization. A mismatch between the profile (e.g., "MacIntel") and the actual GPU output (e.g., Linux) is detectable.
- Scrollbar rendering: Differences in layout metrics (e.g.,
offsetWidth) and visual appearance between macOS overlay scrollbars and Windows/Linux scrollbars. - System color schemes: Differences in
prefers-color-scheme,AccentColor, and system colors. - WebGL shader precision:
getShaderPrecisionFormat()returns driver-specific values tied to the OS + GPU combination.
Best Practice: To avoid detection by advanced services (reCAPTCHA, hCaptcha, Kasada, etc.), always run Camoufox on the OS that matches the fingerprint profile. Use macOS fingerprints on macOS workers and Linux fingerprints on Linux workers. Per-context patches are intended to make each context look like a different person on the same OS, not to impersonate a different OS.
- Font rendering: Differences in subpixel hinting and glyph outlines between Core Text (macOS), DirectWrite (Windows), and FreeType (Linux) affect
Understand the Per-Context Storage Architecture
mainCamoufox uses a thread-safe C++ key-value store called
RoverfoxStorageManagerto manage fingerprinting overrides. Storage is keyed byuserContextId, which is derived from Firefox's container identity system. This ensures that fingerprinting values (like timezone or canvas noise) are isolated to specific Playwright contexts.Write Path
When
window.setXxx()is called on a page:- The
userContextIdis resolved from the window'sBrowsingContext. - The value is stored in a local
nsTHashMapcache. - The value is written to Firefox Preferences with a
roverfox.s.prefix. - In content processes, values are sent to the parent (browser) process via synchronous IPC.
- Fallback: Some patches (e.g.,
audio,canvas,navigator,timezone,webgl) also store values underucid=0as a global fallback for workers that cannot resolve a specificuserContextId.
Read Path (3-tier fallback)
To ensure high performance and availability across processes, reads follow this hierarchy:
- Local cache: In-process
nsTHashMap(fastest). - Firefox Preferences: Reads from the shared preference store, which Firefox syncs across content processes.
- Sync IPC to parent: If preferences are empty, a synchronous IPC call (
SendRoverfoxStorageGet) is made to the parent process. This only runs on the main thread.
- The
Understand Playwright Patches in Camoufox
mainCamoufox utilizes specific patch files to modify Playwright's behavior. These patches are applied to the Firefox engine to enable Camoufox's specialized fingerprinting and anti-detection capabilities.
0-playwright.patch: Contains the upstream patches from Playwright. This file is intended to stay synchronized with the official Playwright Firefox bootstrap patches. If the upstream version diverges significantly, Camoufox may branch off.0-leak-fixes.patch: This patch is applied after the upstream patches to undo specific modifications from0-playwright.patchthat might cause fingerprinting leaks or undesirable side effects.
Use advanced features: Union types and Subtracting Domains
mainJSONvv provides advanced logic for complex validation:
- Union Types (
|): Allows a value to match one of several types. Example:"str | nil"(optional string) or"@traveling | @other"(choice between two custom type definitions). - Subtracting Domains (
-): Excludes certain types or patterns from a definition. Example:"array[str] - str[/sudo/]`` (an array of strings that must not match the 'sudo' regex) or"str - str[Traveling]`
# Union type "theme": "str[light, dark] | nil" # Subtracting a pattern from an array of strings "allowed_commands": "array[str[/^//] - str[/sudo/]]" # Subtracting a type from a string "name": "str - str[Traveling]"- Union Types (
Understand Fingerprint Source Priority in Python
mainThe Camoufox Python library generates fingerprints through two main paths. The source of the fingerprint depends on which class you instantiate.
Path Default Source Opt-in Alternative NewBrowser ( launch_options())BrowserForge synthetic fingerprint_preset=Trueor a preset dictNewContext ( generate_context_fingerprint())BrowserForge synthetic preset=dictexplicitlyProperty Generation Details
- UA, platform, HWC, oscpu: Sourced from BrowserForge or presets; UA is patched to match the Camoufox Firefox version.
- Screen dims, colorDepth: Sourced from BrowserForge or presets; viewport is adjusted by -28px for browser chrome.
- WebGL vendor/renderer: Sampled from
webgl_data.dbusing OS-weighted probability. BrowserForge does not generate WebGL; both paths callsample_webgl()if values are missing. - Font list: Generated fresh per call via
_generate_random_font_subset()(30-78% of OS fonts, including essential/marker fonts). - Speech voices: Generated fresh per call via
_generate_random_voice_subset()(40-80% of OS voices; macOS includes ~184, Windows includes all, Linux is empty). - Timezone: From preset or
Intl.DateTimeFormatfallback. - WebRTC IP: Not set by default; must be set via
window.setWebRTCIPv4().
Define and reuse types with Type References (@)
mainYou can define reusable type definitions using the
@symbol. This helps reduce duplication in complex validators.- Define the type:
"@typeName": "type_definition" - Reference the type:
"key": "@typeName"
validator = { "@positiveInt": "int[>0]", "userId": "@positiveInt", "score": "@positiveInt" }- Define the type:
Understand how Camoufox Build Tester validates profiles
mainThe Build Tester runs 8 profiles in two distinct phases to ensure fingerprint integrity:
- Per-context phase (6 profiles): Runs 3 macOS + 3 Linux profiles simultaneously in a single browser instance. Each uses an isolated fingerprint injected via
addInitScript. This tests that fingerprints are unique and do not leak between contexts. - Global phase (2 profiles): Runs 1 macOS + 1 Linux profile using the
CAMOU_CONFIGenvironment variable for fingerprint configuration. This tests browser-level fingerprint injection.
Each profile is scored across several categories, including Automation Detection, JS Engine signals, Lie Detection (inconsistent property overrides), CSS/Canvas/WebGL/Audio fingerprinting, and WebRTC IP spoofing.
- Per-context phase (6 profiles): Runs 3 macOS + 3 Linux profiles simultaneously in a single browser instance. Each uses an isolated fingerprint injected via
How Camoufox handles fonts and fontconfig
mainCamoufox bundles OS-specific fontconfig configurations and font files to ensure consistent font rendering and detection across different host systems. This prevents host OS leakage (e.g., a Linux font appearing in a macOS profile).
Bundled Structure
- macOS: Uses
Helvetica,Menlo,PingFang, etc. - Linux: Uses
Arimo,Cousine,Tinos, etc. - Windows: Uses
Arial,Consolas,Segoe UI, etc.
Key Features
- Generic Family Mapping: Maps
sans-serif,serif,monospace, etc., to OS-appropriate defaults. - TTC Weight Aliasing: Rewrites queries for TrueType Collections so marker font detection (like CreepJS) works cross-platform.
- MONO Redirect: Redirects the Linux-only "MONO" font to the appropriate OS monospace font (e.g., Menlo on macOS).
- Runtime Path Rewriting: At launch,
createRuntimeFontconfig()rewrites font directory paths to absolute paths pointing to the correct OS-specific subdirectory.
Linux Requirement
When launching Camoufox on Linux, the
FONTCONFIG_PATHenvironment variable must be set to point to the correct OS-specific fontconfig directory (e.g.,camoufox/fontconfig/macos/).- macOS: Uses
How fingerprinting functions self-destruct
mainTo prevent fingerprinting scripts from detecting that overrides have been applied, every
window.setXxx()function employs a dual self-destruct mechanism:JS_DeleteProperty: Immediately removes the function from the current window object after it is called.DisableFunction: Marks the function as disabled in storage, ensuring it does not reappear on future pages within the same context.
This ensures that once a value is set, the setter function itself becomes invisible to the environment.
Understand the Camoufox Patch System
mainCamoufox uses a patch-based system to inject fingerprint spoofing and Playwright support into Firefox.
Patch Categories
All patches reside in the
patches/directory:- Core Patches: Fundamental changes like
0-playwright.patchand1-leak-fixes.patch. - Feature Patches: Specific capabilities like
webrtc-ip-spoofing.patchoranti-font-fingerprinting.patch.
Note: As of Firefox 146, per-user-context support is built directly into the base patches. There are no longer separate
.context.patchfiles.Key Infrastructure
- RoverfoxStorageManager.cpp/h: Provides thread-safe key-value storage for per-context data.
- Manager Classes: Specialized classes like
FontSpacingSeedManagerandWebRTCIPManagerthat handle specific spoofing logic. - Window.webidl: Defines the JavaScript APIs exposed to Playwright for controlling spoofing parameters.
- Core Patches: Fundamental changes like