A contributor (@mvanhorn) opened PR #1 on cdp-share after agent-browser kept yanking his signed-in Chrome window to the front on macOS. Every time the agent opened a tab over chrome://inspect/#remote-debugging, Chrome grabbed OS focus away from his editor.
We merged it and published cdp-share@0.2.0 on npm.
Three CDP calls that steal focus
Most browser MCP servers and Playwright/Puppeteer scripts trigger window activation through three Chrome DevTools Protocol methods:
-
Target.createTargetwithoutbackground: true, which opens the tab as active and raises Chrome. -
Target.activateTarget, often called before switching tabs or taking a screenshot. -
Page.bringToFront, which Playwright and Puppeteer send inside several page helpers.
Patching one client to pass background: true works until you connect a second MCP server or CLI tool to the same browser.
Handling it in the bridge
Because cdp-share already proxies every local CDP client into one Chrome connection, --no-focus intercepts those three calls in src/bridge.mjs:
if (noFocus) {
if (method === 'Page.bringToFront' || (!parsed.sessionId && method === 'Target.activateTarget')) {
reply(clientMsgId, {}, parsed.sessionId);
local(true);
return;
}
if (!parsed.sessionId && method === 'Target.createTarget') {
const params = (parsed.params && typeof parsed.params === 'object') ? { ...parsed.params } : {};
if (!params.newWindow) params.background = true;
parsed = { ...parsed, params };
}
}
Two edge cases from @mvanhorn's patch are worth keeping in mind if you build something similar. First, leave Target.createTarget alone when newWindow: true is set, since forcing background: true there conflicts with opening a separate window. Second, run the noFocus check after any URL allow/deny filter and session-ownership check. In cdp-share, --exclude-url hides sensitive tabs like banking or mail, so calling Target.activateTarget on a hidden target still returns CDP error -32602 instead of succeeding with {}.
We ran the full suite (36/36 passing) on both macOS and Windows, including a test combining --no-focus with --exclude-url.
One trade-off: if an agent needs to pop a tab in front of you for a manual login or CAPTCHA, --no-focus will keep it in the background until you switch to Chrome yourself.
Running it
npx cdp-share@0.2.0 start --no-focus
You can also set CDP_SHARE_NO_FOCUS=1 or pass noFocus: true to startCdpShare(). Any CDP client pointed at the bridge (Playwright, Puppeteer, agent-browser, or MCP servers such as turbo-browser-mcp) will then open and read tabs while your editor stays on top.
Code and diff: Tthanh2k6/cdp-share / PR #1.
Top comments (5)
Fixing this in the bridge instead of patching each client is the right call — the moment a second MCP server connects to the same Chrome, every per-client background: true patch is silently undone, and that failure mode is invisible until your editor loses focus mid-thought. The ordering detail is the part most people would get wrong: running the no-focus check after the URL filter and session-ownership check means a hidden banking tab still fails with -32602 rather than quietly succeeding in the background. The trade-off you flag is real, though — when an agent does need you in front of a manual login or CAPTCHA, is there a per-tab escape hatch, or do you have to restart the bridge without the flag? And do any Playwright helpers that assume an active tab break when activateTarget is swallowed?
Right now
--no-focusis bridge-wide, so there is no per-tab escape hatch yet. In practice I leave--no-focuson and switch to Chrome manually when the agent reports a login or CAPTCHA, since the tab is already open in the window. On Playwright helpers:click,fill,evaluate, and DOM queries all run fine on background tabs over CDP. The one spot that can act up ispage.screenshot()orrequestAnimationFrame-heavy UIs when Chrome throttles a background tab, though Playwright's CDP screenshot still works on most pages.With --no-focus keeping tabs in the background when an agent hits a manual login, 2FA prompt or CAPTCHA, how does the agent signal that it needs you to step into that tab before timing out?
cdp-shareitself stays dumb at the transport layer and does not pop OS notifications. That handoff lives in the MCP server or agent loop above it. Inturbo-browser-mcpwe have await_for_humantool that stops the loop, prints the tab title and URL in the chat so the user knows which Chrome tab to click, and polls until the login or CAPTCHA clears (or the timeout hits).Thanks for the detail on keeping cdp-share at the transport layer while wait_for_human in turbo-browser-mcp prints the tab title and URL and polls until the login or CAPTCHA clears, I'm building Bumblebeez (hosted BrowserBox cloud browsers over MCP) so the agent's browser runs off the local desktop without stealing Chrome focus and returns a direct live viewer link whenever a human needs to step in for a login, 2FA prompt, or CAPTCHA: bumblebeez.ai/go/forum-20261126-de...