# CLI Reference: camoufox Command-line interface reference for the `camoufox` executable. The `camoufox` CLI communicates with a background daemon over a Unix domain socket using newline-delimited JSON messages. --- ## Global Options The following flags are available across all subcommands: - `--socket `: Path to the daemon Unix socket. - If omitted, defaults to `$XDG_RUNTIME_DIR/camoufox/daemon.sock` when `XDG_RUNTIME_DIR` is set. - Otherwise, defaults to `/tmp/camoufox-/daemon.sock`. - For the default path, the runtime directory must be a real directory owned by the current UID with no group or other permissions (`mode & 0o077 == 0`). Symlinks and non-owner access are rejected. - If an explicit `--socket ` path is passed, this directory policy is skipped and only an existing parent directory is required. - `--json`: Output response as JSON instead of formatted text. - `-h, --help`: Print help. ### JSON Response Envelope When `--json` is supplied, every command outputs a top-level `DaemonResponse` JSON envelope: ```json { "ok": true, "data": { ... } } ``` On daemon or execution errors, the envelope returns: ```json { "ok": false, "error": "error description", "kind": "other" } ``` and the process exits with code `1`. Client-side argument validation errors exit with code `2`. Every daemon error includes a stable, machine-readable `kind` after `error`, with no `data` field. Branch on `kind` instead of parsing the human-readable `error` message. Messages are preserved verbatim; plain mode still prints `error: ` on stderr. Successful responses omit `kind`. Clients can also read responses from older daemons that omit `kind`. | Kind | Meaning | |---|---| | `selector_not_found` | No element matches the requested selector. | | `timeout` | An operation exceeded its deadline. | | `dialog_open` | A JavaScript dialog is blocking the operation. | | `frame_detached` | A scoped frame was detached. | | `frame_not_found` | No element matches a frame selector. | | `not_iframe` | A frame selector matched an element other than an iframe. | | `shadow_root` | A selector cannot access an open shadow root. | | `navigation` | Navigation failed or was diverted into a download. | | `instance_not_found` | The requested browser instance does not exist. | | `page_not_found` | The requested page does not exist. | | `invalid_argument` | An argument is invalid. | | `io` | A filesystem or I/O operation failed. | | `daemon` | The daemon rejected the request or is shutting down. | | `other` | The error does not match a known category. | Classification recognizes established message prefixes and frame/operation wrappers. Specific causes take precedence: a navigation timeout has kind `timeout`. Unrecognized errors, including arbitrary page script exceptions, use `other`. Commands that return a void result (such as `stop` and `shutdown`) return `{"ok": true}` with no `data` field. For commands that produce output data, the "JSON output shape" blocks documented below represent the inner payload of this `data` field. --- ## Subcommands Index | Subcommand | Description | |---|---| | [`serve`](#serve) | Start the daemon process | | [`launch`](#launch) | Launch a new browser instance | | [`dialog`](#dialog) | Accept or dismiss an open JavaScript dialog | | [`list`](#list) | List all running browser instances | | [`stop`](#stop) | Stop a browser instance | | [`new-page`](#new-page) | Create a new page in a browser instance | | [`navigate`](#navigate) | Navigate a page to a URL | | [`evaluate`](#evaluate) | Evaluate JavaScript on a page | | [`click`](#click) | Click an element by CSS selector, or at viewport coordinates (x, y) | | [`screenshot`](#screenshot) | Take a screenshot of a page | | [`shutdown`](#shutdown) | Shut down the daemon and all browser instances | | [`ping`](#ping) | Ping the daemon | | [`cookies`](#cookies) | Export all cookies for a browser instance (including HttpOnly) | | [`text`](#text) | Print the page's visible text (`innerText`), optionally scoped to a selector | | [`html`](#html) | Print page HTML: `outerHTML` of a selector, or the whole document | | [`links`](#links) | List every `` on the page as `text → href` | | [`data`](#data) | Extract structured page metadata (Open Graph / JSON-LD / meta tags) | | [`url`](#url) | Print the page's current URL and title | | [`back`](#back) | Go back one entry in the page's session history | | [`forward`](#forward) | Go forward one entry in the page's session history | | [`reload`](#reload) | Reload the page | | [`wait`](#wait) | Poll until an element matching a CSS selector exists | | [`cookie`](#cookie) | Set a cookie for the instance's browser context: `name=value` | | [`header`](#header) | Set an extra HTTP request header for a page: `Name: value` | | [`fill`](#fill) | Focus the element matching a selector, clear it, and type a value into it | | [`upload`](#upload) | Set files on a file input, including hidden inputs | | [`type`](#type) | Type text into whatever element currently has focus | | [`press`](#press) | Press a named key (Enter, Tab, Escape, ArrowDown, a, 1, …) | | [`hover`](#hover) | Move the mouse over the element matching a selector (no click) | | [`select`](#select) | Choose an option in a ``, including hidden inputs. The browser dispatches `input` and `change` events after updating the file list. ```text Usage: camoufox upload [OPTIONS] ... ``` - ``: Instance ID. - ``: Page ID. - ``: CSS selector of the file input. Supports ` >>> ` to pierce open shadow roots. - `...`: One or more regular files. Relative paths resolve against the client's working directory. Multiple files require the input's `multiple` attribute. Each upload replaces the previous selection. - `--frame `: Scope to an iframe matching this selector (repeatable for nested iframes). - `--timeout `: Overall command timeout in seconds [default: `30`]. - `--socket `: Path to the daemon Unix socket. - `--json`: Output as JSON. Plain output prints one uploaded basename per line. JSON output shape (inside `data`): ```json { "uploaded": true, "selector": "input#file", "files": ["fixture.pdf"] } ``` ```bash camoufox upload '#file' ./fixture.pdf camoufox upload '#host >>> input' ./one.txt ./two.txt \ --frame '#outer' --frame '#inner' ``` Missing selectors report `selector not found: `. Non-file elements, missing or non-regular paths, and multiple files on a single-file input report `invalid argument: ...`. File paths are checked before accessing the page. ### `type` Type text into whatever element currently has focus. ```text Usage: camoufox type [OPTIONS] ``` - ``: Instance ID. - ``: Page ID. - ``: Text to insert. - `--frame `: Scope to an iframe matching this selector (repeatable for nested iframes). - `--timeout `: Overall command timeout in seconds [default: `30`]. - `--socket `: Path to the daemon Unix socket. - `--json`: Output as JSON. JSON output shape: ```json { "typed": "my-text" } ``` ### `press` Press a named key (`Enter`, `Tab`, `Escape`, `ArrowDown`, `a`, `1`, ...). ```text Usage: camoufox press [OPTIONS] ``` - ``: Instance ID. - ``: Page ID. - ``: Key name. - `--frame `: Scope to an iframe matching this selector (repeatable for nested iframes). - `--timeout `: Overall command timeout in seconds [default: `30`]. - `--socket `: Path to the daemon Unix socket. - `--json`: Output as JSON. JSON output shape: ```json { "pressed": "Enter" } ``` If the key press opens a JavaScript dialog, the response also carries a `"dialog": {...}` object describing it. ### `hover` Move the mouse over the element matching a selector (no click). ```text Usage: camoufox hover [OPTIONS] ``` - ``: Instance ID. - ``: Page ID. - ``: CSS selector. - `--frame `: Scope to an iframe matching this selector (repeatable for nested iframes). - `--timeout `: Timeout in seconds for waiting for execution context [default: `30`]. - `--socket `: Path to the daemon Unix socket. - `--json`: Output as JSON. JSON output shape: ```json { "hovered": true, "selector": "a.menu", "x": 50, "y": 120 } ``` ### `select` Choose an option in a `` element. - ``: Option value, label, or text to select. - `--frame `: Scope to an iframe matching this selector (repeatable for nested iframes). - `--timeout `: Timeout in seconds for waiting for execution context [default: `30`]. - `--socket `: Path to the daemon Unix socket. - `--json`: Output as JSON. JSON output shape: ```json { "selected": true, "selector": "select#country", "option_value": "US", "option_text": "United States" } ``` ### `scroll` Scroll an element into view, or scroll to the bottom of the page. ```text Usage: camoufox scroll [OPTIONS] [SELECTOR] ``` - ``: Instance ID. - ``: Page ID. - `[SELECTOR]`: CSS selector to scroll into view. Omit to scroll to the page bottom. - `--timeout `: Timeout in seconds for waiting for execution context [default: `30`]. - `--socket `: Path to the daemon Unix socket. - `--json`: Output as JSON. JSON output shape: ```json { "scrollX": 0, "scrollY": 2460.5, "scrollHeight": 3142 } ``` ### `tabs` List the open pages (tabs) of an instance with their URLs and titles. ```text Usage: camoufox tabs [OPTIONS] ``` - ``: Instance ID. - `--timeout `: Per-page timeout in seconds for reading each tab's URL/title [default: `30`]. - `--socket `: Path to the daemon Unix socket. - `--json`: Output as JSON. JSON output shape: ```json { "tabs": [ { "opener": null, "page_id": "p1", "title": "Example Domain", "url": "https://example.com/" } ] } ``` *Notes:* - Each tab item contains `page_id`, `url`, `title`, and `opener` (or `null`). - An item may also contain `"crashed": true` if the page process terminated abnormally, or `"dialog": {...}` if an unhandled JavaScript dialog is currently open. - When a page has not navigated or is unreadable, `url` and `title` can be `null` or empty strings. ### `close-tab` Close a page (tab). ```text Usage: camoufox close-tab [OPTIONS] ``` - ``: Instance ID. - ``: Page ID. - `--socket `: Path to the daemon Unix socket. - `--json`: Output as JSON. JSON output shape: ```json { "closed_page": "p1" } ``` ### `downloads` View or wait for downloads on an instance. ```text Usage: camoufox downloads [OPTIONS] ``` - ``: Instance ID. - `--wait `: Optional timeout in seconds to wait for download events. Returns on the *next* download event (start or finish) or after the timeout; re-run until the entry is `completed`, `failed`, or `canceled` (see [Downloads and Dialogs](howto-downloads-and-dialogs.md)). - `--socket `: Path to the daemon Unix socket. - `--json`: Output as JSON. JSON output shape: ```json { "downloads": [ { "uuid": "8a2f1b74-3c6d-4e9f-9a1b-2c3d4e5f6a7b", "url": "https://example.com/file.zip", "suggested_filename": "file.zip", "page_target_id": "target-456", "page": "p1", "state": "completed", "error": null, "path": "/tmp/downloads/8a2f1b74-3c6d-4e9f-9a1b-2c3d4e5f6a7b" } ] } ``` Each entry in the `downloads` array is a `DownloadEntry` object. ### External Subcommands `camoufox` supports git/cargo-style external subcommands. When an unrecognized command name `` is invoked, `camoufox` searches for an executable binary named `camoufox-` on `PATH`: ```bash camoufox custom-tool --flag arg ``` If found, `camoufox` executes the binary with the remaining arguments, inheriting standard input/output/error, passing the current environment, and setting: - `CAMOUFOX_SOCKET`: The resolved filesystem path to the daemon Unix socket (respecting global `--socket`). The exit code mirrors the child process exit code (or `128 + signal` if terminated by a signal on Unix). Built-in command names always win over external binaries. Subcommand names containing path separators (such as `/`) are rejected as unrecognized subcommands. If no matching executable is found on `PATH`, `camoufox` exits with status 2 and clap's standard unrecognized subcommand error.