How frsorrentino/chrome-bridge works
1. System shape
- This repo implements a two-part browser automation bridge: a Node.js MCP server and a Chrome MV3 extension.
- Claude Code talks to the server over stdio; the server talks to the extension over a local WebSocket on port 8765 by default.
- The extension executes browser actions against the user’s real Chrome session and returns compact results for LLM consumption.
2. Primary runtime boundary
- server/ is the backend control plane: it exposes MCP tools, manages command routing, formats outputs, and maintains the WebSocket bridge.
- extension/ is the browser execution plane: it has permissions to inspect tabs, inject scripts, capture screenshots, read storage, and manipulate requests.
- This separation is the key architecture boundary: the server never drives Chrome directly; every browser operation is proxied through the extension.
3. Connection model and process roles
- The WebSocket server supports a primary instance plus relay clients.
- If the port is already occupied, extra MCP processes attach as loopback relay clients and forward commands through the primary server instead of starting a second bridge.
- The extension must identify itself quickly during handshake; unidentified connections are dropped after 5 seconds.
4. Security and trust boundaries
- The extension handshake is accepted only when the WebSocket Origin is a real chrome-extension://... origin.
- Relay clients are only accepted from loopback addresses.
- An optional shared token can be configured via CHROME_BRIDGE_TOKEN and the extension popup’s token field; this protects the bridge on shared or Crostini-hosted networks.
- The server binds broadly enough for ChromeOS/Crostini connectivity, which makes the token important in less-trusted environments.
5. Server subsystem
- server/index.js is the entry point that wires the MCP server to the WebSocket manager.
- server/tools.js defines the tool surface and schemas; server/protocol.js defines message types, versions, and timeouts.
- Supporting modules implement specific cross-cutting functions: ws-manager.js for transport/handshake, formatters.js for compact outputs, har.js for network export, link-checker.js for server-side URL validation, and security-headers.js for header analysis.
6. Tooling and output philosophy
- The repo exposes a large toolset, but the architecture is optimized for LLM context efficiency rather than verbose logs.
- Many outputs are compact line-oriented records instead of nested JSON.
- Some tools are batch-oriented or multi-step abstractions (fill_form, scroll until, dismiss_overlays, extract_table) to collapse interaction loops into one request.
- Screenshots are downscaled and page text is capped by default, which affects how the extension packages data back to the model.
7. Browser execution subsystem
- extension/service-worker.js is the main command dispatcher inside Chrome.
- It uses Chrome extension APIs to manage tabs, frames, storage, downloads, network rules, screenshots, geolocation, and clipboard access.
- Page-level work is done through injected scripts:
- page-instrumentation.js captures web vitals and event listeners.
- console-capture.js records console output, errors, and unhandled rejections from page start.
- The extension does not rely on chrome.debugger; that is an explicit compatibility choice, especially for ChromeOS.
8. Script execution and page instrumentation
- Page interaction happens in the MAIN world via chrome.scripting.executeScript.
- User-authored code for execute_js and function-based wait_for is routed through chrome.userScripts.execute(), which is why the extension requires the “Allow user scripts” setting for those tools.
- This means DOM inspection, waiting, and interaction can happen without CDP, while still running in the actual page context.
9. Data flows from page to model
- Browser state is collected in multiple channels: DOM queries, accessibility tree, console logs, network logs, screenshots, storage, and performance metrics.
- The extension transforms these into compact tool responses and sends them over WebSocket to the server, which then forwards them to Claude Code.
- Server-side helpers add non-browser data sources where needed, such as link verification over HTTP and HAR generation from recorded requests.
10. CLI as a second client
- server/cli.js exposes the same command surface as the MCP tools but as a shell-oriented client.
- The CLI acts as another relay client on the same WebSocket channel, which makes it useful for batch work, greppable output, and file-based artifacts like screenshots.
- This is architecturally important because it proves the bridge is not MCP-only; MCP is one client of the same transport.
11. Packaging, install, and operational flow
- install.sh installs dependencies and registers the MCP server with Claude Code.
- scripts/package-extension.sh supports packaging the extension for distribution.
- The docs/ tree contains store submission materials, privacy/support docs, and design/planning notes, which suggests the project is meant to ship as a Chrome extension product rather than just a dev tool.
12. Testing boundaries
- Unit tests under test/unit/ cover pure Node-side logic: protocol handling, WebSocket manager behavior, HAR/link/security helpers, and tool formatting.
- test/test-devtools.js is an end-to-end test that requires Chrome plus the extension, validating the full server-to-extension-to-page path.
- This split reflects the architecture boundary: most logic is testable without Chrome, but the real integration is only proven with the browser running.
13. Operational summary
- Overall, the repository is a bridge architecture: Claude Code sends MCP commands to a Node server, the server multiplexes those commands over a local WebSocket, and the extension executes them in the active Chrome profile.
- The main concerns are transport reliability, origin/token security, compact result formatting, and Chrome MV3-compatible execution without CDP.
Main entry points: service-worker.js Service worker · ws-manager.js WS manager · tools.js Tool surface · index.js Server entry
Components 17
Node server
MCP control plane, WebSocket bridge, and server-side helpers
- Server entry · Wires the MCP server to the WebSocket bridge
server/index.js - Tool surface · Defines exposed tools and argument schemas
server/tools.js - WS manager · Handles primary server, relay clients, handshake, and routing
server/ws-manager.js - Protocol · Defines message types, versions, and timeouts
server/protocol.js - Formatters · Converts results into LLM-friendly line-oriented responses
server/formatters.js - HAR export · Builds network artifacts from recorded requests
server/har.js - Link checker · Verifies URLs server-side over HTTP
server/link-checker.js - Header analysis · Analyzes security-related response headers
server/security-headers.js - CLI client · Shell-oriented client that uses the same bridge as MCP
server/cli.js
Chrome extension
MV3 execution plane inside the user’s browser
- Manifest · Declares extension permissions and entrypoints
extension/manifest.json - Service worker · Executes browser actions and coordinates extension APIs
extension/service-worker.js - Page hooks · Captures web vitals and event listeners in the page context
extension/page-instrumentation.js - Console capture · Records console output, errors, and unhandled rejections
extension/console-capture.js - Popup UI · Provides token and connection controls for the extension
extension/popup.js
Packaging
Install, distribution, and release support
Tests
Unit and end-to-end validation
- E2E test · Exercises the full server-to-extension-to-page path
test/test-devtools.js
Connections 22
- Server entry → Tool surface: registers · Entry point wires the tool surface into MCP
- Server entry → WS manager: starts · Entry point initializes the bridge transport
- Server entry → Protocol: uses · Bootstrapping relies on the shared protocol contract
- Tool surface → Formatters: formats · Tools use compact response formatting
- Tool surface → HAR export: exports · Some tools surface HAR artifacts
- Tool surface → Link checker: checks · Tools can validate links server-side
- Tool surface → Header analysis: analyzes · Tools can inspect security headers
- WS manager → Protocol: speaks · Transport enforces message versions and timeouts
- WS manager → Service worker: bridges to · Primary server relays browser commands to the extension
- WS manager → CLI client: serves · CLI attaches as another relay client
- CLI client → WS manager: connects · CLI uses the same WebSocket channel as MCP
- Service worker → Manifest: configured by · Service worker depends on MV3 permissions and entrypoints
- Service worker → Page hooks: injects · Runs page instrumentation in the MAIN world
- Service worker → Console capture: captures · Collects console and error streams from pages
- Service worker → Popup UI: configures · Popup supplies token and connection settings
- Service worker → WS manager: sends results · Extension returns compact browser outputs over the bridge
- Page hooks → Service worker: reports · Page metrics and listeners are returned to the worker
- Console capture → Service worker: reports · Console events flow back through the worker
- Installer → Server entry: registers · Installer wires the MCP server into Claude Code
- Packager → Manifest: packages · Release script assembles the extension bundle
- E2E test → WS manager: validates · E2E test exercises bridge transport behavior
- E2E test → Service worker: validates · E2E test exercises extension execution in Chrome