Browser Hub for Agents (MCP)
Drives VS Code's integrated browser from Claude Code (or any MCP client) and adds the tooling that Playwright MCP and Chrome DevTools MCP users expect: console/network capture, emulation, performance, audits, visual diffs and reusable flows.
It works by calling VS Code's own browser tools (vscode.lm.invokeTool) from an extension and exposing them, plus ours, as an MCP server on 127.0.0.1 (bearer token). A zero-dependency stdio bridge finds the right VS Code window by workspace folder, so the agent does not need to run in a VS Code terminal.
Install
- Install Browser Hub for Agents (MCP) from the Marketplace (
code --install-extension ceafive.browser-hub-mcp).
- On first start it offers Connect agents. Accept, or run Browser Hub: Connect Agents (Claude Code, Antigravity) any time. It registers the bridge with every agent CLI it finds (
claude, agy), on any OS; if none is found it copies the command instead.
- If VS Code's browser tools are off, it asks to Turn on and reload (this sets
workbench.browser.enableChatTools).
- Start a new agent session. An agent that was started before VS Code is told when the hub comes up, so it does not need a manual refresh.
Manual setup, if you prefer: claude mcp add -s user vscode-browser-hub -- node "<globalStorage>/ceafive.browser-hub-mcp/stdio-bridge.mjs" (the command is on the clipboard via Browser Hub: Copy claude mcp add Command).
Requires VS Code 1.110+ (picking up shared tabs needs a version that has the list_browser_pages tool; verified on 1.145).
From source: pnpm install && pnpm build && pnpm package && pnpm install:ext, then reload the window.
Using a tab you already have open
Click Share with Agent in the integrated browser tab's toolbar. That is all: Browser Hub asks VS Code for its list of shared tabs before every tool call (and every 20s in the background), so the tab shows up in list_pages, becomes the active page, and the agent is told it was shared. share_pages {wait:true} blocks until you click; share_pages {url, wait:true} first opens the URL as your tab (your browser profile and logins). Tabs you have not shared stay invisible; the hub only reports how many there are.
pageId is optional everywhere and also accepts a fragment of a tab's title or URL ("localhost:7003").
Memory
- Form memory (
form_memory): what is typed into forms is stored per site in ~/.browser-hub/form-memory.json (owner-only; password, OTP, card and token fields are never stored). It covers what the agent types and what you type in a shared tab. It is used to (1) put a form back with form_memory {action:"restore"}, (2) offer earlier values as suggestions when a text field gets focus, and (3) refill the form when a lost tab is reopened. Manage it with the command Browser Hub: Manage Form Memory.
- Sessions (
session_state): tabs opened by agents live in a browser session VS Code wipes on quit, so a login is gone after a restart. session_state {action:"save", name} stores cookies + localStorage + sessionStorage in ~/.browser-hub/sessions (owner-only); open_browser_page {url, session:name} starts logged in.
- Tab recovery: if VS Code drops a tab, the next tool call reopens its URL and restores sessionStorage, the form's values and the scroll position, and says what it restored.
| Area |
Tools |
| VS Code's own |
open_browser_page (+session), read_page, screenshot_page, navigate_page, click_element, type_in_page, hover_element, drag_element, handle_dialog, run_playwright_code. Pass snapshot:false to drop the page snapshot from the result. |
| Pages / tabs |
list_pages, switch_page, close_page, share_pages |
| The user |
user_activity (what the user clicked/typed), record_flow (turn what the user does into a flow), pick_element (user points at an element) |
| Memory |
form_memory, session_state |
| Inspect |
query, inspect_element, screenshot_marks, evaluate, run_code, ax_tree, read_console, read_network, network_detail, read_websockets, save_network_log (HAR), cookies, storage |
| Act |
fill_form, interact, wait_for, mock_route |
| Emulate |
emulate (devices, 3G/4G/offline, CPU throttle, dark mode, geolocation, timezone, UA, touch...), set_viewport |
| Performance |
perf_metrics (Web Vitals), perf_trace, cpu_profile, js_coverage, memory, audit_page (Lighthouse-style scores) |
| QA |
expect (assertions), check_links, responsive_check, save_page_screenshot, screenshot_diff |
| Automation |
run_sequence, save_flow, run_flow, list_flows, delete_flow |
| Diagnostics |
hub_diagnose, hub_selftest |
After every action the result ends with a short [Browser Hub] Since this action: note when something happened: new console errors, failed requests, a URL change (setting browserHub.actionDigest).
{{secret:NAME}} in any tool argument is resolved on the extension side from HUB_SECRET_NAME / ARGENT_SECRET_NAME env vars or .argent/secrets.env, .browser-hub/secrets.env (workspace or ~). Values never enter the model's context and are redacted from later output. record_flow writes these placeholders for sensitive fields.
Output (screenshots, traces, baselines, flows) goes to ~/.browser-hub/<workspace>/ (setting browserHub.outputDir). Form memory and sessions are shared by all workspaces, in ~/.browser-hub/.
Things worth knowing
- Hot reload: tools live in
dist/impl.js, re-loaded whenever it changes. pnpm build takes effect without reloading the window. Only changes to src/extension.ts / src/server.ts need a reload.
- How shared tabs are found: VS Code has an internal tool
list_browser_pages (not listed in vscode.lm.tools, but invokable) that returns every shared tab with its page ID. A tab's ID is also on its CDP target as vscodeBrowserViewId.
- User vs agent: the in-page recorder logs clicks, field edits and navigations; events that happen while a tool is acting on the page are marked
agent, the rest user.
- Hidden tabs: a browser tab that is not on screen has a 0x0 layout. Browser Hub wakes it automatically (CDP focus + active lifecycle). The background sync never does this.
- Viewport: plain
setViewportSize is ignored by this browser. emulate / set_viewport use CDP, correct for tab zoom, and fall back to mobile mode for widths that desktop mode cannot hit exactly (e.g. 768 at 80% zoom).
- Not Lighthouse:
audit_page approximates it from live data.
- Not available in this browser:
Page.printToPDF, page.request.*, context.cookies().
Develop
code --extensionDevelopmentPath="$PWD" "$PWD" opens a dev host. Drive tools from a shell with node scripts/hubrun.mjs open_browser_page '{"url":"http://localhost:7001"}' hub_selftest '{}'.
| |