Since Chrome 144, turning on remote debugging in chrome://inspect comes with a prompt: every new DevTools Protocol connection to your normal Chrome profile asks "Allow remote debugging?". That is a reasonable default for a browser that holds all your logins. It is painful when an agent reconnects on every step, or when two MCP servers want the same browser.
There is an open issue on chrome-devtools-mcp asking to remember the approval (#825, 21 upvotes when I last looked). The maintainers' position is that there is no safe way to persist it, and their suggestion is to keep connections open longer. So I pulled the piece of turbo-browser-mcp that already did that into its own package: cdp-share.
npx -y cdp-share
It connects to Chrome once (you click Allow), then serves the same /json/version and WebSocket endpoints Chrome does on http://127.0.0.1:9333. chrome-devtools-mcp gets --browserUrl http://127.0.0.1:9333, Playwright gets connectOverCDP('http://127.0.0.1:9333'), Puppeteer gets browserURL. On my Chrome 157 I clicked Allow once and then connected Playwright three times, Puppeteer twice and chrome-devtools-mcp twice without another prompt.
Why a plain relay broke
The first version inside turbo was a plain WebSocket relay with one upstream socket. It worked with one client. The night I had two Claude Code sessions open, both running turbo against the same Chrome, the second one hung on its first call for over 100 seconds.
CDP with flattened sessions puts every attached page on one socket, tagged by sessionId. With two clients on one relay, both see the same session ids, and each client's Playwright assumes it owns them. The second client never got Runtime.executionContextCreated for the main world, so every evaluate waited forever, and creating a page failed with Page.setFontFamilies: Font families can only be set once because the first client had already set up that session.
cdp-share gives each client its own CDP sessions. When client B attaches to a tab, the daemon attaches a fresh upstream session for B, so B's Runtime.enable produces B's own context events, and its init scripts and emulation settings do not collide with A's. Target.setAutoAttach with waitForDebuggerOnStart is emulated per client: a new tab is held until each auto-attaching client has resumed it, with a timeout so one stuck client cannot freeze the tab.
A few other things a shared browser needs:
-
Browser.closefrom a client is swallowed. Most Playwright and Puppeteer scripts end withbrowser.close(), and without this the first script to finish closes your Chrome. - Browser contexts a client created are disposed when it disconnects. Tabs in your default profile stay.
- Commands that were still waiting for an answer when a client left are dropped. I only found that one with a soak test: three clients connecting, opening pages and leaving for 30 overlapping rounds left 576 entries in the pending table. After the fix the same run ends with 0 clients, 0 leftover contexts and sessions, and about 8 MB of memory growth.
Not making it worse
A browser with remote debugging on is fully controllable by anything that can reach the port. cdp-share does not fix that, but it should not widen it:
- it listens on 127.0.0.1 only,
- it rejects requests whose Host header is not localhost (DNS rebinding) and WebSocket upgrades that carry a web page Origin,
-
--token autorequires a token on every connection, -
--log audit.jsonlrecords which client sent which command to which tab, without command parameters, so typed text and passwords stay out of the log, -
--exclude-urlhides tabs you do not want agents to see, for example your bank.
Run it with --token auto. Without a token, any program on your machine that reaches the port gets the connection you already approved, and with it the cookies of every site you are signed in to, with no Allow prompt in the way. The token sits in a plain file under ~/.cdp-share/ that your user can read, so it keeps out other users and web pages, not programs running as you.
What is not done
The URL filter checks a tab's URL only, and a client already attached to a tab stays attached if the tab later navigates somewhere hidden. I have tested on Windows 11 only; CI runs the suite on Linux and macOS with headless Chromium, but not against a real Chrome profile there. During development the CLI crashed twice on Windows with exit code 0xC0000409. I changed every process.exit() so the daemon closes its sockets first and lets the event loop drain. The crash has not come back in 35 runs since, but I never reproduced it on demand, so I can't say it is gone.
If you run more than one agent against your own Chrome, I would like to hear what breaks: https://github.com/Tthanh2k6/cdp-share/issues
Top comments (0)