Labsco
bnomei logo

Chromewright

โ˜… 1

from bnomei

Browser automation via Chrome DevTools Protocol

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedFreeQuick setup

chromewright

Crates.io Version Build Status License

Chromewright is a local-first browser automation MCP server built on Chrome DevTools Protocol (CDP). It exposes a real Chrome or Chromium browser to MCP clients over stdio or loopback streamable HTTP, with high-level tools for navigation, page reading, tab management, screenshots, viewport emulation, and bounded interaction.

Use Chromewright when an agent needs browser state from a real browser without embedding a Node.js automation stack or writing raw CDP calls. Chromewright is not an end-to-end test runner; it is a browser control layer for AI agents and MCP clients.

When to use Chromewright

  • Attach an MCP client to an existing Chrome or Chromium profile on a DevTools endpoint.
  • Launch a dedicated local browser session for agent work.
  • Read pages through snapshots, markdown extraction, targeted inspection, and link inventory.
  • Drive bounded interactions such as click, input, select, hover, key press, scroll, and wait.
  • Capture managed PNG screenshots without letting callers choose arbitrary output paths.
  • Reuse revision-scoped cursor handles from snapshots instead of relying only on CSS selectors.

Browser modes

Chromewright has two browser modes:

ModeHow to startWhat it does
AttachRun chromewright or chromewright serve with no launch flags.Connects to http://127.0.0.1:9222 by default.
Attach to another endpointPass --ws-endpoint <URL>.Connects to a browser WebSocket URL or a DevTools HTTP origin such as http://127.0.0.1:9333.
LaunchPass any launch flag such as --user-data-dir, --headless, --executable-path, or --debug-port.Starts a local browser session. Launch mode is headed unless you pass --headless.

Examples:

Copy & paste โ€” that's it
# Default: attach to http://127.0.0.1:9222 and serve MCP over stdio.
chromewright

# Serve streamable HTTP on the default loopback endpoint.
chromewright serve

# Serve streamable HTTP on a custom port and path.
chromewright serve --port 3333 --http-path /browser

# Attach to a different DevTools endpoint.
chromewright --ws-endpoint http://127.0.0.1:9333

# Launch a visible browser with a dedicated profile.
chromewright --user-data-dir /tmp/chromewright-profile

# Launch a headless browser and serve streamable HTTP.
chromewright --headless --user-data-dir /tmp/chromewright-profile serve

CLI reference

Option or commandDefaultDescription
chromewrightstdio transportStarts the MCP server over stdio.
chromewright serve127.0.0.1:3000/mcpStarts the MCP server over loopback streamable HTTP.
serve --port <PORT>, serve -p <PORT>3000Sets the HTTP port.
serve --http-path <PATH>/mcpSets the HTTP endpoint path.
--ws-endpoint <URL>http://127.0.0.1:9222 when no launch flags are presentConnects to an existing browser WebSocket URL or DevTools HTTP origin. This conflicts with launch flags.
--headlessfalseLaunches a new browser in headless mode.
--executable-path <PATH>auto-detected by the browser backendUses a specific browser executable in launch mode.
--user-data-dir <DIR>backend defaultUses a persistent browser profile directory in launch mode.
--debug-port <PORT>auto-selectedUses a specific DevTools port for a locally launched browser.

Source: src/bin/mcp_server.rs.

Tool workflow

A typical agent workflow is:

  1. Call tab_list or new_tab to establish an active tab.
  2. Call snapshot to read the current page and collect actionable nodes.
  3. Prefer a fresh cursor from snapshot or inspect_node when targeting follow-up actions.
  4. Use inspect_node, get_markdown, extract, or read_links for more focused reads.
  5. Use click, input, select, hover, press_key, scroll, wait, or tab tools for bounded interaction.
  6. Call snapshot again after navigation, DOM-changing actions, viewport changes, or ambiguous target recovery.

snapshot supports these modes:

ModeUse it when
viewportYou want the default local reread of the current visible scope.
deltaYou want the changed local surface when a compatible prior snapshot base exists.
fullYou need an exhaustive page-wide read.

DOM-targeted tools accept a public target object:

Copy & paste โ€” that's it
{
  "target": {
    "kind": "selector",
    "selector": "h1"
  }
}

or:

Copy & paste โ€” that's it
{
  "target": {
    "kind": "cursor",
    "cursor": "<cursor from snapshot or inspect_node>"
  }
}

Selector strings are still accepted for compatibility by tools that use the public target type, but the object form is the canonical contract.

Production MCP tool surface

Production MCP sessions register the default high-level tools plus the guarded operator tool evaluate.

CategoryTools
Navigationnavigate, go_back, go_forward, wait
Interaction and viewportclick, input, select, hover, press_key, scroll, set_viewport
Tabs and lifecyclenew_tab, tab_list, switch_tab, close_tab, close
Reading and inspectionsnapshot, inspect_node, get_markdown, extract, read_links
Managed artifactsscreenshot
Operator diagnosticsevaluate

evaluate executes JavaScript in the active page and requires confirm_unsafe = true on each call. It is available for diagnostics and escape-hatch inspection when bounded tools cannot answer a page-specific question.

Source: src/tools/core/mod.rs and src/browser/session.rs.

Screenshots and viewport emulation

Use screenshot when a caller needs a managed PNG artifact. The tool accepts:

  • mode: viewport, full_page, element, or region
  • scale: device or css
  • optional tab_id
  • optional target for element captures
  • optional region for region captures

Successful calls return managed artifact metadata, including artifact_uri, artifact_path, mime_type, byte_count, image dimensions, CSS dimensions, device pixel ratio, pixel scale, revealed_from_offscreen, and optional clip data. Callers do not provide output paths.

Use set_viewport to emulate responsive breakpoints through CDP. Successful calls return viewport_metrics_after; later snapshot calls expose the live metrics under scope.viewport.

Safety boundaries

  • Attach mode can see the tabs, cookies, and authenticated state in the browser profile you connect to.
  • Use a dedicated browser profile for agent work when you do not want automation attached to a personal browser session.
  • evaluate requires confirm_unsafe = true because it runs arbitrary JavaScript in the active page.
  • navigate and new_tab reject unsafe schemes such as data: and file: unless that request passes allow_unsafe = true.
  • go_back and go_forward apply the same unsafe-scheme gate and revert rejected history moves.
  • close_tab requires confirm_destructive = true before closing an unmanaged active tab in a connected session.
  • close requires confirm_destructive = true before expanding connected-session cleanup from managed tabs to all tabs.
  • cursor and node_ref targets are revision-scoped. After navigation or DOM-changing actions, refresh with snapshot.

Operation metrics

Finished tool results include operation_metrics metadata when a tool records non-zero metrics. operation_metrics.output_bytes is optional; it appears only when a tool path measures the exact serialized output size.

Measured paths may include:

  • browser evaluation count
  • poll iterations
  • DOM extraction count and extraction time
  • last DOM node count
  • snapshot render time
  • handoff rebuild count and time
  • exact serialized output size when measured

Run the focused operation metrics tests:

Copy & paste โ€” that's it
cargo test --locked --all-features operation_metrics

Local development

Build from source:

Copy & paste โ€” that's it
cargo build

Run the normal test suite:

Copy & paste โ€” that's it
cargo test

Run the browser smoke suite from the repository root:

Copy & paste โ€” that's it
scripts/browser-smoke.sh

The smoke script runs:

Copy & paste โ€” that's it
cargo test --test browser_smoke -- --nocapture

Browser smoke checks launch a local browser and are intended for maintainer workstations. CI covers formatting, clippy, MSRV, cargo check, tests, and packaging without requiring a live browser attach target.

Source anchors

License

MIT