Camoufox

repository·main·Indexed 42 days ago

https://github.com/cloverlabsai/camoufox

An 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.

Tokens
37.8K
Snippets
127
Records
171
Agent score
53%

What's inside Camoufox

  1. Overview of Camoufox

    main
    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.
  2. Camoufox Capabilities Overview

    main

    Camoufox 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.webdriver and 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 addons property (list of paths). Includes uBlock Origin with custom privacy filters.
  3. Understand the limitations of Per-Context Fingerprint Patches

    main

    Per-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() and toDataURL() 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.

  4. Understand the Per-Context Storage Architecture

    main

    Camoufox uses a thread-safe C++ key-value store called RoverfoxStorageManager to manage fingerprinting overrides. Storage is keyed by userContextId, 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:

    1. The userContextId is resolved from the window's BrowsingContext.
    2. The value is stored in a local nsTHashMap cache.
    3. The value is written to Firefox Preferences with a roverfox.s. prefix.
    4. In content processes, values are sent to the parent (browser) process via synchronous IPC.
    5. Fallback: Some patches (e.g., audio, canvas, navigator, timezone, webgl) also store values under ucid=0 as a global fallback for workers that cannot resolve a specific userContextId.

    Read Path (3-tier fallback)

    To ensure high performance and availability across processes, reads follow this hierarchy:

    1. Local cache: In-process nsTHashMap (fastest).
    2. Firefox Preferences: Reads from the shared preference store, which Firefox syncs across content processes.
    3. 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.
  5. Understand Playwright Patches in Camoufox

    main

    Camoufox 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 from 0-playwright.patch that might cause fingerprinting leaks or undesirable side effects.
  6. Use advanced features: Union types and Subtracting Domains

    main

    JSONvv 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]"
  7. Understand Fingerprint Source Priority in Python

    main

    The Camoufox Python library generates fingerprints through two main paths. The source of the fingerprint depends on which class you instantiate.

    PathDefault SourceOpt-in Alternative
    NewBrowser (launch_options())BrowserForge syntheticfingerprint_preset=True or a preset dict
    NewContext (generate_context_fingerprint())BrowserForge syntheticpreset=dict explicitly

    Property 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.db using OS-weighted probability. BrowserForge does not generate WebGL; both paths call sample_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.DateTimeFormat fallback.
    • WebRTC IP: Not set by default; must be set via window.setWebRTCIPv4().
  8. Define and reuse types with Type References (@)

    main

    You can define reusable type definitions using the @ symbol. This helps reduce duplication in complex validators.

    1. Define the type: "@typeName": "type_definition"
    2. Reference the type: "key": "@typeName"
    validator = {
        "@positiveInt": "int[>0]",
        "userId": "@positiveInt",
        "score": "@positiveInt"
    }
  9. Understand how Camoufox Build Tester validates profiles

    main

    The Build Tester runs 8 profiles in two distinct phases to ensure fingerprint integrity:

    1. 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.
    2. Global phase (2 profiles): Runs 1 macOS + 1 Linux profile using the CAMOU_CONFIG environment 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.

  10. How Camoufox handles fonts and fontconfig

    main

    Camoufox 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_PATH environment variable must be set to point to the correct OS-specific fontconfig directory (e.g., camoufox/fontconfig/macos/).

  11. How fingerprinting functions self-destruct

    main

    To prevent fingerprinting scripts from detecting that overrides have been applied, every window.setXxx() function employs a dual self-destruct mechanism:

    1. JS_DeleteProperty: Immediately removes the function from the current window object after it is called.
    2. 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.

  12. Understand the Camoufox Patch System

    main

    Camoufox 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.patch and 1-leak-fixes.patch.
    • Feature Patches: Specific capabilities like webrtc-ip-spoofing.patch or anti-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.patch files.

    Key Infrastructure

    • RoverfoxStorageManager.cpp/h: Provides thread-safe key-value storage for per-context data.
    • Manager Classes: Specialized classes like FontSpacingSeedManager and WebRTCIPManager that handle specific spoofing logic.
    • Window.webidl: Defines the JavaScript APIs exposed to Playwright for controlling spoofing parameters.