# Custom Chrome Dev MCP A **local-only** MCP (Model Context Protocol) server that lets an MCP client - Claude Code, or anything else that speaks MCP - drive **your real Chrome browser** the way a person would. No telemetry, no third-party services, no cloud: everything runs on your machine behind a shared token. It exposes **60 tools** across navigation, tabs, perception, interaction, trusted input, observability, capture, and storage. --- ## Where this came from This project is **inspired by Chrome's official browser MCP** - the [**Chrome DevTools MCP**](https://github.com/ChromeDevTools/chrome-devtools-mcp) server published by the Chrome DevTools team, which first made the case that an AI agent should drive a browser through the DevTools Protocol rather than through scraped HTML. **We are replicating and imitating that idea, not shipping it.** What we borrowed: - **The premise** - expose the browser to an agent as a set of MCP tools. - **Accessibility-first perception** - hand the model a compact a11y outline with stable element refs instead of a wall of raw HTML. - **The Chrome DevTools Protocol as the input layer** - real, trusted events instead of synthetic ones a page can spot and ignore. Where this project **deliberately diverges**: | | Chrome DevTools MCP | Custom Chrome Dev MCP | | --- | --- | --- | | Browser | **By default** launches its own Chrome with a dedicated user-data-dir; can also attach to a running instance via `--browser-url` | **Only ever** drives the Chrome you already have open | | Attachment | Connects to the browser over the DevTools Protocol endpoint | A **Chrome extension living inside the browser**, pointed at whatever tab you choose | | Primary goal | Debugging, inspecting, and profiling a page | **Behaving like a human using that page** | That last row is the whole point of this repo. Chrome DevTools MCP is a debugging tool that happens to drive a browser; this is an imitation-of-a-person tool that happens to be useful for debugging. > ⚠️ Not affiliated with, endorsed by, or supported by Google or the Chrome team. > This is an independent reimplementation built to learn from and imitate their > design. Use the official server if you want the supported thing. --- ## It deliberately keeps the styling of a human Most browser automation is trivially detectable: synthetic events with `isTrusted=false`, focus that never really moves, text that appears in a field all at once, a pristine automation profile with no history. Every one of those is a signal. This project tries to remove those signals: - **Your real profile.** Actions run in the Chrome you already use - your cookies, logins, extensions, and history. Nothing to fingerprint as "fresh automation". - **Trusted input.** `realClick`, `realType`, `press`, `hover`, and `drag` dispatch through the DevTools Protocol, so the page receives events with `isTrusted=true` - the same flag a physical mouse and keyboard produce. - **Genuine focus.** Clicking to focus a field really moves focus, in order, rather than assigning `.value` behind the page's back. - **Real keystrokes.** `press` emits proper `rawKeyDown` / `char` / `keyUp` sequences with correct key codes and modifiers, not a single synthetic `input` event. - **Read-back verification.** `fill` confirms the field actually holds the text, so the agent notices when a page silently rejected the input - as a person would. The goal: a page should behave for the agent exactly as it behaves for someone sitting at the keyboard. Fast synthetic tools (`click`, `type`) are still there - they're quicker and work on most sites. When a page ignores them, reach for the trusted equivalents. --- ## How it works One transport. The MCP client talks to the server over stdio; the server relays to a Chrome extension over a local WebSocket owned by a small long-lived **hub** process. ``` MCP client 1 (Claude) <-stdio-> bin/custom-chrome-dev-mcp.js ─┐ MCP client 2 (Claude) <-stdio-> bin/custom-chrome-dev-mcp.js ─┼─ src/hub.js (127.0.0.1:9876) MCP client N (Claude) <-stdio-> bin/custom-chrome-dev-mcp.js ─┘ │ │ WebSocket ▼ Chrome extension -> active tab ``` **Why a separate hub process.** Only one process can own port `9876`, but you may have several Claude sessions open and all of them may want the browser. So the socket lives in `src/hub.js` rather than inside any one session. Each session connects to the hub as `role:"mcp"`, the extension connects as `role:"extension"`, and the hub multiplexes between them. The first session to start spawns the hub **detached**, so it outlives that session; later sessions find it already listening. Inside the extension there are three layers: 1. **Walker** (`page/walker.js`) - injected into the page's ISOLATED world. Owns element resolution, the stable `eN` ref map, and the fast synthetic DOM ops. 2. **CDP** (`cdp/`) - `chrome.debugger` for trusted input, page-context `evaluate`, full-page screenshots, and the console/network buffers. 3. **Recording** (`recording/`) - CDP screencast frames encoded to `.webm` by a `MediaRecorder` in an offscreen document. > 🔒 The extension authenticates to the hub with a shared token (`AUTH_TOKEN`, > identical in `src/config.js` and `extension/src/config.js`). The hub drops any peer > that presents a different value. --- ## Prerequisites | | Requirement | Check | | --- | --- | --- | | **Node.js** | 18 or newer (developed on 22) | `node --version` | | **Chrome** | Google Chrome or Chromium, any recent version | `chrome://version` | | **An MCP client** | Claude Code, or anything else that speaks MCP over stdio | `claude --version` | No global installs, no build step, no service to sign up for. Two runtime dependencies (`@modelcontextprotocol/sdk` and `ws`) and everything stays on `127.0.0.1`. --- ## Local setup Four steps, then a verification pass. Budget five minutes. ### 1. Clone and install ```sh git clone custom-chrome-dev-mcp cd custom-chrome-dev-mcp npm install ``` Confirm the tree is healthy before wiring anything to Chrome - the offline lane needs no browser and takes under a second: ```sh npm test ``` You want `22 passed`. If that fails, fix it before continuing; nothing downstream will work. ### 2. Load the extension into Chrome 1. Open `chrome://extensions`. 2. Turn on **Developer mode** (top-right toggle). 3. Click **Load unpacked** and select the **`extension/`** folder - the folder itself, not `manifest.json` inside it. 4. **Custom-chrome-dev-mcp** appears in the list. > ⚠️ **Load it into the Chrome profile you actually browse in.** Chrome keeps > extensions per profile, so an extension loaded into "Profile 4" is invisible to the > window running under "Default". If tools later report no tabs, or the hub never logs > `extension connected`, this is the first thing to check. `chrome://version` shows the > active **Profile Path**. The extension ID is pinned by the public `key` in `extension/manifest.json`, so it is identical on every machine - nothing to copy between setups. ### 3. Register the MCP server with your client **Use the CLI** - substitute the absolute path where you cloned the repo (`pwd` in the project root prints it): ```sh claude mcp add -s user custom-chrome-dev-mcp -- node /ABSOLUTE/PATH/TO/custom-chrome-dev-mcp/bin/custom-chrome-dev-mcp.js ``` - `-s user` registers it for **all** your projects; `-s local` limits it to this one. - Register **`bin/custom-chrome-dev-mcp.js`** - that file is the entry point. Pointing at `src/server.js` will not work. - The path must be **absolute**. A relative path resolves against whatever directory the client happened to launch from. - Confirm with `claude mcp list` - you want a `✔ Connected` next to it. > ⚠️ **Do not hand-edit `~/.claude.json`.** It is large, and one misplaced comma breaks > Claude Code entirely. The command above edits it safely.
Alternative - manual JSON (only if you can't use the CLI) Add the server under `mcpServers`: ```json { "mcpServers": { "custom-chrome-dev-mcp": { "command": "node", "args": ["/ABSOLUTE/PATH/TO/custom-chrome-dev-mcp/bin/custom-chrome-dev-mcp.js"] } } } ```
### 4. Restart the MCP client MCP clients enumerate tools once, at startup - a server registered mid-session is invisible until you restart. Restart Claude, and the 60 tools appear. On restart the client launches the server, which spawns `src/hub.js` if nothing is already listening on `127.0.0.1:9876`. ### 5. Verify all three links in the chain The stack is *client → server → hub → extension → tab*. Check it end to end rather than guessing which link is down. ```sh # The hub is up, and the extension found it: tail -f "$TMPDIR/custom-chrome-dev-mcp-hub.log" # [hub] listening on 127.0.0.1:9876 # [hub] extension connected <- this line is the handshake succeeding # Who owns the port (should be src/hub.js from THIS repo): lsof -nP -iTCP:9876 -sTCP:LISTEN ``` Then ask your client for **`listTabs`**. A JSON array of your open tabs means every link works. Follow it with **`screenshot`** - a full-res PNG lands in `~/Downloads` *and* a downscaled JPEG comes back inline. For the extension's own console: `chrome://extensions` → **Custom-chrome-dev-mcp** → **service worker** → **Inspect**. That is where extension-side errors surface; they never reach the MCP client. ### 6. Change the shared token before real use `AUTH_TOKEN` ships with a default value, defined identically in **`src/config.js`** and **`extension/src/config.js`**. It is the only thing stopping another process on your machine from driving your logged-in browser. Pick your own value, change it in **both** files (an offline test asserts they match), and reload the extension. --- ## After you change code The two halves reload differently, and getting this wrong wastes more time than anything else in the project: | You edited | To pick it up | | --- | --- | | Anything under **`extension/`** | Click **reload ↻** on the extension in `chrome://extensions`. Chrome keeps running the previously loaded build until you do. | | Anything under **`src/`** | Restart the MCP client. The server process is long-lived and holds the old tool schemas. | | **`src/hub.js`** | `pkill -f src/hub.js` - the next tool call respawns it. | --- ## Troubleshooting | Symptom | Cause | Fix | | --- | --- | --- | | `claude mcp list` shows `✘ Failed to connect` | Wrong path, or not the `bin/` entry point | Re-register with the absolute path to `bin/custom-chrome-dev-mcp.js` | | Tools missing from the client entirely | Registered mid-session | Restart the MCP client | | Hub log never says `extension connected` | Extension not loaded, loaded in a different Chrome profile, or `AUTH_TOKEN` differs between the two `config.js` files | Check `chrome://version` → Profile Path; confirm both tokens match | | A tool call hangs, then times out | The service worker died, or an extension-side exception | Open the service worker console; click **reload ↻** | | Port `9876` owned by an unexpected process | A hub from another clone of this project is squatting the port | `lsof -nP -iTCP:9876 -sTCP:LISTEN`, then kill that PID | | An edit to `extension/` "did nothing" | Chrome is still running the old build | Click **reload ↻** | | `URL is banlisted` | `BANLIST` in `extension/src/config.js` blocks that host | Edit the list - it ships with placeholder entries | | `refusing to act: … does not contain expectUrl` | The `expectUrl` guard fired, correctly | Drop the guard, or point it at the real URL | | Screenshot path rejected | Writes are confined to the capture directory | Use a filename or a path **inside** it | | A tool targets the wrong tab | A background tab stole focus | Pin the working tab with `useTab` | --- ## Configuration Both are optional environment variables read at startup by `src/config.js`. | Variable | Default | What it does | | --- | --- | --- | | `CUSTOM_CHROME_DEV_MCP_CAPTURE_DIR` | `~/Downloads` | The **only** directory screenshots and recordings may be written to. | | `CUSTOM_CHROME_DEV_MCP_WS_PORT` | `9876` | Hub port. Change it in `extension/src/config.js` too, or they won't find each other. | Also worth changing for real use: **`AUTH_TOKEN`**, defined identically in `src/config.js` and `extension/src/config.js`. Pick your own value - it is what stops another local process from driving your browser. --- ## Available tools (60) Elements are targeted three ways: **`selector`** (CSS), **`ref`** (a stable `eN` id from `snapshotA11y`), or **`name`** (accessible name, e.g. a button's label). "target" below means any one of those three. **Universal params**, accepted by every tool: - **`tabId`** - act on a specific tab instead of the ambient active one. - **`frameId`** (from `listFrames`) - act inside a specific frame, including cross-origin iframes the top document cannot script. - **`expectUrl`** - a guard: refuse the action unless the tab's URL contains this substring. Pin a working tab for the whole session with **`useTab`** so a background tab (an autoplaying video, a notification popup) can't steal focus and misdirect an action. ### Navigation | Tool | Args | Description | | --- | --- | --- | | `navigate` | `url` | Point the tab at a URL (replaces the page). | | `newtab` | `url` | Open a URL in a **new** foreground tab, leaving the current page intact. | | `back` / `forward` | - | History back / forward. | | `reload` | `hard?` | Reload, optionally bypassing the cache. | | `getUrl` / `getTitle` | - | The tab's URL / title (works on internal pages too). | | `waitForLoad` | `timeout?` | Block until the tab finishes loading. | ### Tabs & frames | Tool | Args | Description | | --- | --- | --- | | `listTabs` | - | Every open tab across all windows (`id`, `title`, `url`, `active`, `pinned`). | | `activateTab` | `tabId` | Focus a tab and its window. | | `closeTab` | `tabId` | Close a tab by id. | | `useTab` | `tabId?` | **Pin** the working tab so every later tool targets it regardless of OS focus. Omit `tabId` to pin the current one. | | `unpinTab` | - | Release the pin; tools revert to the active tab. | | `listFrames` | - | Every frame incl. cross-origin as `{frameId, parentFrameId, url, origin}`. | ### Perception | Tool | Args | Description | | --- | --- | --- | | `snapshotA11y` | - | Compact accessibility outline of visible interactive elements as `role "name" ref=eN`. **Prefer this over `snapshot`.** Refs expire on navigation or re-snapshot. | | `snapshot` | - | Raw `outerHTML` of ``, truncated to 50k. Use when you need exact markup. | | `getText` | target | `innerText` of one element, trimmed. | | `getAttribute` | target, `attr` | An attribute, falling back to the live DOM property (`value`, `checked`, `href`). | | `queryAll` | `selector`, `limit?` | text/href/value/visible for **every** match at once. | | `viewport` | - | `devicePixelRatio`, CSS viewport, scroll offset - how you map screenshot px → CSS px. | | `getComputedStyle` | target, `properties?` | Computed CSS - a curated default set (box model, typography, color), or just the properties you name. | | `getBoxModel` | target | Margin/border/padding/content rectangles (CSS px) - DevTools' Elements panel box model view. | ### Interaction - synthetic, fast Untrusted events dispatched by the walker. Quick, and enough for most sites. | Tool | Args | Description | | --- | --- | --- | | `click` | target | Bubbling `MouseEvent` click; also **focuses** the element; `.click()` fallback. Returns `{focused}`. | | `type` | target, `text` | Set a field's value via the native setter (handles ``, `