Expand description
Passive console and network capture for the MCP server.
The MCP server keeps one CDP WebSocket open for its lifetime, and CDP
pushes Runtime.* / Log.* / Network.* events to any attached session
that has those domains enabled. This module keeps one long-lived flat
session per touched tab (any tab a tool call has routed to), enables
the domains once, and routes the pushed events into bounded per-tab ring
buffers that browser_console_messages / browser_network_requests
read on demand.
This is the sanctioned exception to the “no idle work” rule in
docs/specs/boundaries.md: nothing here polls or wakes on a timer. The
only background task blocks on the event channel and does a mutex push
per event; when the browser is quiet, it is parked.
Lifecycle: state for a tab is dropped when the tab is closed through the
MCP server (forget), when the browser detaches the session
(Target.detachedFromTarget), when the renderer crashes
(Inspector.targetCrashed), and wholesale on browser_select (reset)
or when the socket closes. Nothing in here ever returns TabHung /
TabCrashed: attach failures are swallowed and retried on the next touch,
so the recover-once flows elsewhere are unaffected.
Firefox (WebDriver BiDi) uses the same hub with a different ingress: one
global session.subscribe per backend for log.entryAdded,
network.beforeRequestSent / responseCompleted / fetchError, and
browsingContext.navigationStarted / contextDestroyed, routed by the
browsing-context id, which is the target id. Response bodies are not
available on BiDi (no getResponseBody equivalent without browser-side
retention), so browser_network_body stays Chromium-only.
Opt-out: BROWSER_CONTROL_CAPTURE=0 (or false) disables attachment
entirely on both engines. Runtime.enable is observable by some anti-bot
scripts, and a user logging into such a site through browser_show may
prefer the server not to touch their tabs.
Structs§
- Body
Result - Result of a body fetch.
- Capture
Hub - The capture hub. Cheap to clone via
ArconServerState. - Console
Entry - One captured console line.
- Console
Query - Filters for
read_console. - Console
Report - Result of a console read.
- Network
Entry - One captured network request.
- Network
Query - Filters for
read_network. - Network
Report - Result of a network read.
Enums§
Constants§
- BIDI_
NO_ BODIES_ HINT - Agent-facing explanation for
browser_network_bodyon Firefox. - BODY_
DEFAULT_ MAX - Default cap for
browser_network_body. - BODY_
HARD_ MAX - Hard cap for
browser_network_body, aligned withbrowser_curl. - CONSOLE_
CAP - Console entries kept per tab.
- CONSOLE_
TEXT_ CAP - Bytes of rendered text kept per console entry.
- NETWORK_
CAP - Network entries kept per tab.
- TOUCH_
WAIT - How long a reader (or
browser_navigate) waits for an in-flight attach. - URL_CAP
- Bytes of URL kept per entry.
Functions§
- fmt_
iso_ ms - Epoch milliseconds →
YYYY-MM-DDTHH:MM:SS.mmmZ. - format_
console_ line - One console entry as a single text line (no page separator).
- format_
console_ text - Render a console report as text with
-- page: <url> --separators. - format_
network_ line - One network entry as a single text line.
- format_
network_ text - Render a network report as text.
- render_
bidi_ remote_ value - Render a BiDi
script.RemoteValuefor console output. - render_
remote_ object - Render a
Runtime.RemoteObjectthe way DevTools’ console preview does, without any round trip: primitives verbatim, objects from theirpreview, everything else bydescription.