# frsorrentino/chrome-bridge architecture

> Architecture diagram of the GitHub repository frsorrentino/chrome-bridge, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/frsorrentino/chrome-bridge
- Repository: https://github.com/frsorrentino/chrome-bridge

## Overview

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: [`extension/service-worker.js`](https://github.com/frsorrentino/chrome-bridge/blob/main/extension/service-worker.js) (Service worker), [`server/ws-manager.js`](https://github.com/frsorrentino/chrome-bridge/blob/main/server/ws-manager.js) (WS manager), [`server/tools.js`](https://github.com/frsorrentino/chrome-bridge/blob/main/server/tools.js) (Tool surface), [`server/index.js`](https://github.com/frsorrentino/chrome-bridge/blob/main/server/index.js) (Server entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_server["Node server"]
  node_server_index["Server entry<br/>mcp bootstrap<br/>[index.js]"]
  node_server_tools["Tool surface<br/>mcp schemas<br/>[tools.js]"]
  node_server_ws[("WS manager<br/>bridge transport<br/>[ws-manager.js]")]
  node_server_protocol["Protocol<br/>message contract<br/>[protocol.js]"]
  node_server_formatters["Formatters<br/>compact output<br/>[formatters.js]"]
  node_server_har["HAR export<br/>network capture<br/>[har.js]"]
  node_server_link["Link checker<br/>http validation<br/>[link-checker.js]"]
  node_server_security["Header analysis<br/>security helper"]
  node_server_cli["CLI client<br/>relay client<br/>[cli.js]"]
end

subgraph group_extension["Chrome extension"]
  node_ext_manifest["Manifest<br/>mv3 config<br/>[manifest.json]"]
  node_ext_worker["Service worker<br/>command dispatcher<br/>[service-worker.js]"]
  node_ext_page["Page hooks<br/>page instrumentation"]
  node_ext_console["Console capture<br/>page logging<br/>[console-capture.js]"]
  node_ext_popup["Popup UI<br/>bridge config<br/>[popup.js]"]
end

subgraph group_ops["Packaging"]
  node_install_sh["Installer<br/>setup script<br/>[install.sh]"]
  node_package_ext["Packager<br/>release script"]
end

subgraph group_tests["Tests"]
  node_devtools_test["E2E test<br/>browser integration<br/>[test-devtools.js]"]
end

node_server_index -->|"registers"| node_server_tools
node_server_index -->|"starts"| node_server_ws
node_server_index -->|"uses"| node_server_protocol
node_server_tools -->|"formats"| node_server_formatters
node_server_tools -->|"exports"| node_server_har
node_server_tools -->|"checks"| node_server_link
node_server_tools -->|"analyzes"| node_server_security
node_server_ws -->|"speaks"| node_server_protocol
node_server_ws -->|"bridges to"| node_ext_worker
node_server_ws -->|"serves"| node_server_cli
node_server_cli -->|"connects"| node_server_ws
node_ext_worker -->|"configured by"| node_ext_manifest
node_ext_worker -->|"injects"| node_ext_page
node_ext_worker -->|"captures"| node_ext_console
node_ext_worker -->|"configures"| node_ext_popup
node_ext_worker -->|"sends results"| node_server_ws
node_ext_page -->|"reports"| node_ext_worker
node_ext_console -->|"reports"| node_ext_worker
node_install_sh -->|"registers"| node_server_index
node_package_ext -->|"packages"| node_ext_manifest
node_devtools_test -->|"validates"| node_server_ws
node_devtools_test -->|"validates"| node_ext_worker

click node_server_index "https://github.com/frsorrentino/chrome-bridge/blob/main/server/index.js"
click node_server_tools "https://github.com/frsorrentino/chrome-bridge/blob/main/server/tools.js"
click node_server_ws "https://github.com/frsorrentino/chrome-bridge/blob/main/server/ws-manager.js"
click node_server_protocol "https://github.com/frsorrentino/chrome-bridge/blob/main/server/protocol.js"
click node_server_formatters "https://github.com/frsorrentino/chrome-bridge/blob/main/server/formatters.js"
click node_server_har "https://github.com/frsorrentino/chrome-bridge/blob/main/server/har.js"
click node_server_link "https://github.com/frsorrentino/chrome-bridge/blob/main/server/link-checker.js"
click node_server_security "https://github.com/frsorrentino/chrome-bridge/blob/main/server/security-headers.js"
click node_server_cli "https://github.com/frsorrentino/chrome-bridge/blob/main/server/cli.js"
click node_ext_manifest "https://github.com/frsorrentino/chrome-bridge/blob/main/extension/manifest.json"
click node_ext_worker "https://github.com/frsorrentino/chrome-bridge/blob/main/extension/service-worker.js"
click node_ext_page "https://github.com/frsorrentino/chrome-bridge/blob/main/extension/page-instrumentation.js"
click node_ext_console "https://github.com/frsorrentino/chrome-bridge/blob/main/extension/console-capture.js"
click node_ext_popup "https://github.com/frsorrentino/chrome-bridge/blob/main/extension/popup.js"
click node_install_sh "https://github.com/frsorrentino/chrome-bridge/blob/main/install.sh"
click node_package_ext "https://github.com/frsorrentino/chrome-bridge/blob/main/scripts/package-extension.sh"
click node_devtools_test "https://github.com/frsorrentino/chrome-bridge/blob/main/test/test-devtools.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_server_index,node_server_tools,node_server_ws,node_server_protocol,node_server_formatters,node_server_har,node_server_link,node_server_security,node_server_cli toneBlue
class node_ext_manifest,node_ext_worker,node_ext_page,node_ext_console,node_ext_popup toneAmber
class node_install_sh,node_package_ext toneMint
class node_devtools_test toneRose
```

## Components

### Node server

MCP control plane, WebSocket bridge, and server-side helpers

- [Server entry](https://github.com/frsorrentino/chrome-bridge/blob/main/server/index.js): mcp bootstrap · Wires the MCP server to the WebSocket bridge · `server/index.js`
- [Tool surface](https://github.com/frsorrentino/chrome-bridge/blob/main/server/tools.js): mcp schemas · Defines exposed tools and argument schemas · `server/tools.js`
- [WS manager](https://github.com/frsorrentino/chrome-bridge/blob/main/server/ws-manager.js): bridge transport · Handles primary server, relay clients, handshake, and routing · `server/ws-manager.js`
- [Protocol](https://github.com/frsorrentino/chrome-bridge/blob/main/server/protocol.js): message contract · Defines message types, versions, and timeouts · `server/protocol.js`
- [Formatters](https://github.com/frsorrentino/chrome-bridge/blob/main/server/formatters.js): compact output · Converts results into LLM-friendly line-oriented responses · `server/formatters.js`
- [HAR export](https://github.com/frsorrentino/chrome-bridge/blob/main/server/har.js): network capture · Builds network artifacts from recorded requests · `server/har.js`
- [Link checker](https://github.com/frsorrentino/chrome-bridge/blob/main/server/link-checker.js): http validation · Verifies URLs server-side over HTTP · `server/link-checker.js`
- [Header analysis](https://github.com/frsorrentino/chrome-bridge/blob/main/server/security-headers.js): security helper · Analyzes security-related response headers · `server/security-headers.js`
- [CLI client](https://github.com/frsorrentino/chrome-bridge/blob/main/server/cli.js): relay 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](https://github.com/frsorrentino/chrome-bridge/blob/main/extension/manifest.json): mv3 config · Declares extension permissions and entrypoints · `extension/manifest.json`
- [Service worker](https://github.com/frsorrentino/chrome-bridge/blob/main/extension/service-worker.js): command dispatcher · Executes browser actions and coordinates extension APIs · `extension/service-worker.js`
- [Page hooks](https://github.com/frsorrentino/chrome-bridge/blob/main/extension/page-instrumentation.js): page instrumentation · Captures web vitals and event listeners in the page context · `extension/page-instrumentation.js`
- [Console capture](https://github.com/frsorrentino/chrome-bridge/blob/main/extension/console-capture.js): page logging · Records console output, errors, and unhandled rejections · `extension/console-capture.js`
- [Popup UI](https://github.com/frsorrentino/chrome-bridge/blob/main/extension/popup.js): bridge config · Provides token and connection controls for the extension · `extension/popup.js`

### Packaging

Install, distribution, and release support

- [Installer](https://github.com/frsorrentino/chrome-bridge/blob/main/install.sh): setup script · Installs dependencies and registers the MCP server · `install.sh`
- [Packager](https://github.com/frsorrentino/chrome-bridge/blob/main/scripts/package-extension.sh): release script · Builds the extension for distribution · `scripts/package-extension.sh`

### Tests

Unit and end-to-end validation

- [E2E test](https://github.com/frsorrentino/chrome-bridge/blob/main/test/test-devtools.js): browser integration · Exercises the full server-to-extension-to-page path · `test/test-devtools.js`

## Connections

- 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
