Repository navigation
Description
Version
@playwright/mcp0.0.79,packages/extension0.3.0 (manifest), extension sources atmain@ 6e8015a- Chrome 151.0.7922.170, macOS 26.5.2, arm64
Summary
On the token-bypass connect path (--extension with a pre-shared token, so no
human clicks "Allow" or picks a tab), the extension attaches to a tab in the
user's current window, activates that tab, and focuses that window. For an
interactive connection that is correct. For an unattended client it means every
agent connection interrupts whatever the person is doing.
There is currently no way for a client to say "connect, but stay out of my way".
Current behavior
Three separate places combine into the problem.
- The token path adopts the connect page tab, and that tab lives in the user's window.
playwright/packages/extension/src/background.ts
Lines 71 to 81 in 6e8015a
| case 'connectToTab': { | |
| // Token-bypass (no specific pick) falls back to the connect page itself | |
| // so `ConnectedTabGroup` always has a concrete tab to start from. Both | |
| // sender.tab and UI-supplied tabs come from chrome.tabs.query / runtime | |
| // message sender, where `id` is always defined. | |
| const selectedTab = (message.tab ?? sender.tab!) as chrome.tabs.Tab & { id: number }; | |
| this._connectTab(sender.tab!.id!, selectedTab, message.clientName).then( | |
| () => sendResponse({ success: true }), | |
| (error: any) => sendResponse({ success: false, error: error.message })); | |
| return true; // Return true to indicate that the response will be sent asynchronously | |
| } |
// Token-bypass (no specific pick) falls back to the connect page itself
// so `ConnectedTabGroup` always has a concrete tab to start from.
const selectedTab = (message.tab ?? sender.tab!) as chrome.tabs.Tab & { id: number };- Every connection then activates the tab and focuses its window, unconditionally.
playwright/packages/extension/src/background.ts
Lines 119 to 122 in 6e8015a
| await Promise.all([ | |
| chrome.tabs.update(tab.id, { active: true }), | |
| chrome.windows.update(tab.windowId, { focused: true }), | |
| ]).catch(() => {}); |
await Promise.all([
chrome.tabs.update(tab.id, { active: true }),
chrome.windows.update(tab.windowId, { focused: true }),
]).catch(() => {});On macOS this also activates the Chrome application and can switch the active
Space, so the interruption isn't limited to the browser.
- Nothing afterwards is scoped to a workspace.
chrome.debugger.sendCommandis allow-listed and forwarded verbatim
(relayConnection.ts#L41-L47),
so a routinePage.bringToFrontfrom Playwright (browser_tabs(select)issues one)
re-activates the user's window mid-task.chrome.tabs.createis allow-listed with nowindowId, so MCP-created tabs
open in whichever window the adopted tab happens to live in, which is the user's.- On close, cleanup only ungroups
(connectedTabGroup.ts#L173-L181).
Tabs the client created stay behind in the user's window.
Steps to reproduce
- Open Chrome and start working in some tab.
- Start an MCP client with
--extensionand a pre-shared token, so the connect
page approves itself without a tab pick. - Have the client run any trivial task, for example
browser_navigatefollowed
bybrowser_tabs(select).
Observed: Chrome comes to the front, the active tab changes to the agent's page,
and on macOS the Space may change. New tabs the client opens remain in the user's
window after the client disconnects.
Expected: an unattended client can drive a page without the browser taking
foreground, and leaves no tabs behind when it disconnects.
Why this matters
The token path exists for clients that connect without a human at the keyboard.
Those are exactly the connections that must not take focus. As it stands this
makes the extension route unusable for background agent work on a machine someone
is actively using, which pushes people toward a separate browser or a copied
profile, and that loses the logged-in session the extension exists to provide.
Multiple concurrent clients landed in v1.63 (#41838), which makes this sharper,
since several clients can now interrupt the same person in turn.
Design constraints I measured (macOS 26.5.2, Chrome 151)
I built and ran a local fork of the extension against these cases. Writing them
down because most of the obvious designs turn out to be dead ends, and the
failures aren't obvious from the outside.
A minimized window cannot be driven at all. document.visibilityState goes
hidden, requestAnimationFrame stops firing, and trusted CDP mouse and keyboard
input is not delivered. Playwright then hangs at its actionability check instead
of failing, so it looks like a random hang rather than an error. This rules out
putting the agent tab in a minimized window, which is what I tried first.
A normal-type window is a link target. Chrome routes links opened from other
applications into a normal window, so an agent window of that type intermittently
receives the user's own links. A popup-type window is excluded from that
routing.
A fully covered window gets throttled unless Chrome is started with
--disable-backgrounding-occluded-windows. Without that switch, an agent window
sitting behind a maximized app degrades the same way a minimized one does.
Creating a window activates Chrome, even with focused: false. I couldn't find
any way around this. So a design that provisions a window per connection can't be
non-disruptive on macOS; the window has to already exist.
Popup windows are single-tab containers. chrome.tabs.create aimed at one gets
re-homed elsewhere by Chrome, tabs can't be moved in or out (normal to popup moves
are rejected outright), and window.open from the page materializes as a separate
window.
Putting that together, the only arrangement I found that is both non-disruptive
and actually drivable is a pre-existing popup-type, normal-state, unfocused
window, with focus-activation commands suppressed at the extension boundary.
Proposed direction
Rough sketch, happy to shape it to whatever the team prefers:
- Let a connection be marked background (token path by default, or an explicit
opt-in from the client), and skip the activate/focus block for it. - Give such a connection its own window rather than adopting the connect page
tab, and pinchrome.tabs.createto that window. - Suppress
Page.bringToFrontandTarget.activateTargetfor background
connections, answering them as no-ops sobrowser_tabs(select)still works. - Track extension-created tab IDs so disconnect removes exactly those and
preserves anything the user touched or moved out. - Treat the user focusing the agent window as a reclaim, and stop driving it.
The window-creation constraint is the one real design question here. Creating on
demand always costs an activation. Reusing a small pool of windows avoids that,
but it's more state than the extension currently keeps, and I don't know whether
the team wants that in the extension or considers it out of scope.
On the closed PR
I sent #42279 before opening an issue, which was the wrong order, and I've closed
it. It was also the wrong fix. It minimized the workspace window, and the
measurement above shows a minimized window can't receive trusted input at all. The
test in that PR asserted the window was minimized and unfocused, so it passed
while the actual capability was broken. That would have shipped a connection that
silently hangs on the first click.
Happy to send a corrected PR if the direction above looks reasonable, or to leave
it alone if the team would rather design this differently.
Activity
github-actions commentedon Aug 20, 2026
Hi, I'm the Playwright bot and I took a first look.
This is a valid design issue, not a bug in the usual sense — the behavior you describe is exactly what the code does today, on tip-of-tree. I read through the extension source at current
main(sha1586a4d) and all three of your citations line up:background.tsresolvesmessage.tab ?? sender.tab!(background.ts#L76).chrome.debugger.sendCommandandchrome.tabs.createare allow-listed and forwarded verbatim (relayConnection.ts#L41-L47), so aPage.bringToFrontre-activates the window, created tabs inherit the adopted tab's window, and close only ungroups (connectedTabGroup.ts#L173-L181).I also confirmed there's no existing knob for "connect but stay out of my way" — nothing in
packages/extension/srcor the MCP extension-connect path distinguishes a background/unattended connection from an interactive one. So the token path and the human-clicks-Allow path get identical activate/focus treatment, which is the crux of your report.This is a Chrome-extension + CDP + macOS window-management interaction, so there's no
page/serverspec that reproduces it the way we'd condense a normal bug — I verified it by reading the source rather than by scripting the focus-steal, and the constraints you measured (minimized windows can't receive trusted input,normalwindows are link targets, window creation activates Chrome) are the kind of thing that has to be checked against a real Chrome on real macOS, which I can't do here. Thanks for writing them down in that much detail — that's the useful part of this issue.The real question is the design one you already isolated: whether a connection can be marked background (with focus-activation suppressed at the extension boundary and created tabs tracked for cleanup), and where the window-provisioning state should live. That's a maintainer call on scope, so I'll leave the direction to them rather than bless an approach.
What I checked
mainsha1586a4d(your report cites6e8015a; the relevant lines are unchanged between the two).background.ts— token-bypass tab adoption and the unconditionalchrome.tabs.update({active})/chrome.windows.update({focused})block.relayConnection.ts—ALLOWED_CHROME_COMMANDSincludeschrome.debugger.sendCommandandchrome.tabs.createwith no window scoping.connectedTabGroup.ts—_onConnectionCloseonly ungroups, doesn't remove extension-created tabs.packages/extension/srcand the MCP extension path for any existing background/no-focus/unfocused option — none exists.Triaged by the Playwright bot - agent run
yury-s commentedon Aug 26, 2026
The connect page is opened by passing its URL to the running browser on the command line, and Chrome always focuses a tab opened that way — there is no flag to open it in the background. Avoiding the focus steal is not feasible with the current connection approach; we can reconsider if the connection mechanism changes in the future.
rav4nn commentedon Oct 2, 2026
Not a fix for the extension, but a way around it if your client is Claude Code or another MCP client. I hit the same thing with several agents running: every connect pulled Chrome to the front and my typing landed in a tab. The command-line connect page is part of it. On macOS the debug port WebSocket also activates Chrome.app on its own. Chrome on --remote-debugging-pipe doesn't, but only the launching process can hold the pipe, so I wrote a small proxy that holds it and lets any number of sessions connect over localhost. It uses a copy of your signed-in profile instead of the extension. I built it: https://github.com/rav4nn/agent-chrome (MIT, macOS only).