# How to Automate Browsing with the Camoufox CLI Daemon This guide shows how to manage the Camoufox Unix socket daemon and run browsing, extraction, interaction, and scraping commands from the terminal or shell scripts. ## Prerequisites 1. Build the release CLI binary: ```bash cargo build --release --features cli --bin camoufox ``` 2. Verify binary availability: ```bash ./target/release/camoufox --help ``` --- ## 1. Start and verify the daemon The CLI connects to a background daemon over a Unix domain socket. Start the daemon in a dedicated terminal or service manager: ```bash ./target/release/camoufox serve ``` In another terminal, verify the daemon is responding: ```bash ./target/release/camoufox ping ``` Expected output: ```text pong (0 instances) ``` With `--json`: ```bash ./target/release/camoufox --json ping ``` ```json { "ok": true, "data": { "instance_count": 0 } } ``` ### Socket resolution By default, the daemon binds to: - `$XDG_RUNTIME_DIR/camoufox/daemon.sock` - Or `/tmp/camoufox-/daemon.sock` if `XDG_RUNTIME_DIR` is unset. Override the socket location with `--socket ` on any command: ```bash ./target/release/camoufox --socket /tmp/my-daemon.sock serve ./target/release/camoufox --socket /tmp/my-daemon.sock list ``` --- ## 2. Launch browser instances and manage tabs ### Launch an instance ```bash ./target/release/camoufox launch ``` Output (stdout prints the instance ID; stderr reports browser version and pid): ```text 00000001 ``` To see the browser window, pass `--headed`: ```bash ./target/release/camoufox launch --headed ``` To configure downloads and dialogs at launch: ```bash ./target/release/camoufox launch --downloads-dir /tmp/my-downloads --dialogs accept ``` ### List instances Listing instances shows all running processes and their open pages (a freshly launched instance has no pages): ```bash ./target/release/camoufox list ``` Output: ```text 00000001 pid=3511172 version=Firefox/158.0.1-beta.41 pages=[] ``` ### Open a new page (tab) Create the first page on the instance: ```bash ./target/release/camoufox new-page 00000001 ``` Output: ```text p1 ``` ### List tabs and close tabs List all open tabs with their URLs and titles: ```bash ./target/release/camoufox tabs 00000001 ``` Output: ```text p1 about:blank ``` Or after navigating `p1`: ```text p1 https://example.com/ Example Domain ``` Close a tab: ```bash ./target/release/camoufox close-tab 00000001 p1 ``` --- ## 3. Navigate with lifecycle synchronization Navigate a page to a URL: ```bash ./target/release/camoufox navigate 00000001 p1 https://example.com ``` ### Wait for page events By default, `navigate` returns after the Juggler `Page.navigate` protocol acknowledgement. To block until page resources are ready, pass `--wait-until`: ```bash # Block until full window load event fires (bounded by --timeout seconds): ./target/release/camoufox navigate 00000001 p1 https://example.com --wait-until load --timeout 30 # Or block until DOMContentLoaded: ./target/release/camoufox navigate 00000001 p1 https://example.com --wait-until domcontentloaded --timeout 15 ``` Supported `--wait-until` values are `load` and `domcontentloaded`. ### Inspect final HTTP status Navigate never fails on 4xx/5xx HTTP codes. Use `--json` to inspect `status_code` (which captures the final HTTP status after following all redirects): ```bash ./target/release/camoufox --json navigate 00000001 p1 https://example.com ``` ```json { "ok": true, "data": { "navigation_id": "nav-1", "status_code": 200 } } ``` --- ## 4. Extract content and metadata ### Visible text Extract `innerText` from the entire page or scoped to a CSS selector: ```bash ./target/release/camoufox text 00000001 p1 ./target/release/camoufox text 00000001 p1 --selector "article" ``` ### HTML source Extract `outerHTML`: ```bash ./target/release/camoufox html 00000001 p1 --selector "header" ``` ### Links Extract all `` elements, resolved to absolute URLs: ```bash ./target/release/camoufox links 00000001 p1 ``` ### Structured metadata Extract Open Graph, JSON-LD, or meta tags: ```bash # Extract all metadata: ./target/release/camoufox data 00000001 p1 # Scoped to Open Graph only: ./target/release/camoufox data 00000001 p1 --og # Scoped to JSON-LD only: ./target/release/camoufox data 00000001 p1 --jsonld ``` ### URL and Title Print current URL on stdout and title on stderr: ```bash ./target/release/camoufox url 00000001 p1 ``` --- ## 5. Interact with page elements Commands like `click`, `hover`, `press`, `type`, and the typing phase of `fill` dispatch trusted browser-level input events (`event.isTrusted === true`). In contrast, `select` uses synthetic JavaScript `change`/`input` events, `scroll` is executed via JavaScript `element.scrollIntoView()`, and `fill`'s clear step uses JavaScript (`isTrusted === false`). ### Wait for an element to appear Poll for a CSS selector with a timeout (default timeout is 10s): ```bash ./target/release/camoufox wait 00000001 p1 --selector "#results" --timeout 15 ``` ### Click elements Click an element by CSS selector (scrolls into view and clicks center): ```bash ./target/release/camoufox click 00000001 p1 "#search-button" ``` Or dispatch a trusted click at raw viewport coordinates `(x, y)`: ```bash ./target/release/camoufox click 00000001 p1 350 220 ``` Because coordinate clicks originate from the browser process (`event.isTrusted === true`), they can drive CAPTCHA or Turnstile widgets that reject synthetic JavaScript events. ### Form input: Fill, Type, Press Fill an input field (clears existing value via JavaScript and types new text with trusted events): ```bash ./target/release/camoufox fill 00000001 p1 "input[name=q]" "camoufox" ``` Send a keyboard press (e.g., Enter, Tab, Escape, ArrowDown): ```bash ./target/release/camoufox press 00000001 p1 Enter ``` Type text into whatever element currently has focus via `Page.insertText` (sent as a single batch string in Juggler, not per-key events): ```bash ./target/release/camoufox type 00000001 p1 "search query" ``` ### Hover, Select, Scroll Hover over an element without clicking: ```bash ./target/release/camoufox hover 00000001 p1 ".dropdown-trigger" ``` Select a dropdown option in `