Files
camoufox-rs/docs/howto-cli-daemon.md
9prodhiandClaude Opus 5.5 02b2f8fe60 docs: Diataxis documentation suite, verified against the code
Adds docs/ guides by type and makes README the entry point:
- tutorial: docs/tutorial-getting-started.md
- how-to: CLI daemon, iframes and shadow DOM, downloads and dialogs,
  library usage
- reference: docs/reference-cli.md (all 33 subcommands, built from the
  release binary's --help, with JSON samples from real runs and the
  {"ok","data"} envelope) and docs/reference-library-api.md
- explanation: docs/explanation-architecture.md

Repairs stale claims in README.md, docs/UNDERSTANDING.md and
docs/PROTOCOL.md (pipe/fd setup, concurrency model, unsafe scope, frame
buffer cap, readiness sentinels, navigate/evaluate return types, trusted
vs synthetic input, downloads --wait semantics, socket security on
Linux vs other platforms). Adds TODOS.md with verified follow-ups.

Written by agy (gemini-3.8-flash-high) via the gstack document-generate
skill; audited twice against the source by Fable 5.2 (41 semantic
findings fixed) and by a docs-vs-code name check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YQU84X3UzxGaxqrADxbkoE
2026-11-21 17:03:19 -06:00

8.9 KiB

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:
    cargo build --release --features cli --bin camoufox
    
  2. Verify binary availability:
    ./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:

./target/release/camoufox serve

In another terminal, verify the daemon is responding:

./target/release/camoufox ping

Expected output:

pong (0 instances)

With --json:

./target/release/camoufox --json ping
{
  "ok": true,
  "data": {
    "instance_count": 0
  }
}

Socket resolution

By default, the daemon binds to:

  • $XDG_RUNTIME_DIR/camoufox/daemon.sock
  • Or /tmp/camoufox-<uid>/daemon.sock if XDG_RUNTIME_DIR is unset.

Override the socket location with --socket <path> on any command:

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

./target/release/camoufox launch

Output (stdout prints the instance ID; stderr reports browser version and pid):

00000001

To see the browser window, pass --headed:

./target/release/camoufox launch --headed

To configure downloads and dialogs at launch:

./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):

./target/release/camoufox list

Output:

00000001  pid=3511172  version=Firefox/158.0.1-beta.41  pages=[]

Open a new page (tab)

Create the first page on the instance:

./target/release/camoufox new-page 00000001

Output:

p1

List tabs and close tabs

List all open tabs with their URLs and titles:

./target/release/camoufox tabs 00000001

Output:

p1  about:blank  

Or after navigating p1:

p1  https://example.com/  Example Domain

Close a tab:

./target/release/camoufox close-tab 00000001 p1

3. Navigate with lifecycle synchronization

Navigate a page to a URL:

./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:

# 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):

./target/release/camoufox --json navigate 00000001 p1 https://example.com
{
  "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:

./target/release/camoufox text 00000001 p1
./target/release/camoufox text 00000001 p1 --selector "article"

HTML source

Extract outerHTML:

./target/release/camoufox html 00000001 p1 --selector "header"

Extract all <a href> elements, resolved to absolute URLs:

./target/release/camoufox links 00000001 p1

Structured metadata

Extract Open Graph, JSON-LD, or meta tags:

# 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:

./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):

./target/release/camoufox wait 00000001 p1 --selector "#results" --timeout 15

Click elements

Click an element by CSS selector (scrolls into view and clicks center):

./target/release/camoufox click 00000001 p1 "#search-button"

Or dispatch a trusted click at raw viewport coordinates (x, y):

./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):

./target/release/camoufox fill 00000001 p1 "input[name=q]" "camoufox"

Send a keyboard press (e.g., Enter, Tab, Escape, ArrowDown):

./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):

./target/release/camoufox type 00000001 p1 "search query"

Hover, Select, Scroll

Hover over an element without clicking:

./target/release/camoufox hover 00000001 p1 ".dropdown-trigger"

Select a dropdown option in <select> by value, label, or visible text:

./target/release/camoufox select 00000001 p1 "select#country" "Canada"

Scroll an element into view or scroll to the bottom of the page:

# Scroll specific element:
./target/release/camoufox scroll 00000001 p1 "#footer"

# Scroll to bottom of page:
./target/release/camoufox scroll 00000001 p1

6. JavaScript evaluation

Evaluate expressions in the page:

./target/release/camoufox evaluate 00000001 p1 "document.title"

By default, evaluate runs in an isolated world. To read page-defined globals (such as window.__INITIAL_STATE__), add --main-world:

./target/release/camoufox evaluate 00000001 p1 --main-world "window.__NEXT_DATA__.props"

If the site blocks inline scripts with Content-Security-Policy, relaunch the instance with --bypass-csp.


7. Cookies and HTTP headers

Export cookies

Export the instance cookie jar (including HttpOnly cookies):

./target/release/camoufox cookies 00000001
./target/release/camoufox --json cookies 00000001
./target/release/camoufox cookie 00000001 p1 "auth_token=secret123" --domain example.com --secure --http-only

Add custom HTTP headers

Headers accumulate across calls for the page session:

./target/release/camoufox header 00000001 p1 "Accept-Language: fr-FR"
./target/release/camoufox header 00000001 p1 "X-Custom-Header: test"

8. Capture screenshots

Capture full viewport:

./target/release/camoufox screenshot 00000001 p1 -o /tmp/page.png

Capture cropped to a CSS selector (element scrolled into view first):

./target/release/camoufox screenshot 00000001 p1 --selector "#main-card" -o /tmp/card.png

Capture an explicit rectangle x,y,width,height in CSS pixels:

./target/release/camoufox screenshot 00000001 p1 --clip 0,0,800,600 -o /tmp/clip.png

Supported formats are png (default) and jpeg (with optional --quality <0-100>).


9. Stop instances and shut down

Stop a single instance:

./target/release/camoufox stop 00000001

stop interrupts any in-flight commands and finishes in ~1s.

Shut down the daemon and all running instances:

./target/release/camoufox shutdown

shutdown stops browsers in parallel, removes the socket file, and exits. The <socket>.lock file is intentionally kept to prevent race conditions during daemon restart.