Skip to content

[Bug]: Extension token connections take over the user's active tab and focus their window #42343

Closed as not planned

Description

Version

  • @playwright/mcp 0.0.79, packages/extension 0.3.0 (manifest), extension sources at main @ 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.

  1. The token path adopts the connect page tab, and that tab lives in the user's window.

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 };
  1. Every connection then activates the tab and focuses its window, unconditionally.

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.

  1. Nothing afterwards is scoped to a workspace.
  • chrome.debugger.sendCommand is allow-listed and forwarded verbatim
    (relayConnection.ts#L41-L47),
    so a routine Page.bringToFront from Playwright (browser_tabs(select) issues one)
    re-activates the user's window mid-task.
  • chrome.tabs.create is allow-listed with no windowId, 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

  1. Open Chrome and start working in some tab.
  2. Start an MCP client with --extension and a pre-shared token, so the connect
    page approves itself without a tab pick.
  3. Have the client run any trivial task, for example browser_navigate followed
    by browser_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:

  1. 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.
  2. Give such a connection its own window rather than adopting the connect page
    tab, and pin chrome.tabs.create to that window.
  3. Suppress Page.bringToFront and Target.activateTarget for background
    connections, answering them as no-ops so browser_tabs(select) still works.
  4. Track extension-created tab IDs so disconnect removes exactly those and
    preserves anything the user touched or moved out.
  5. 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

  1. github-actions commented on Aug 20, 2026

    @github-actions
    Contributor

    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 (sha 1586a4d) and all three of your citations line up:

    • The token-bypass path adopts the connect page's own tab, which lives in the user's window — background.ts resolves message.tab ?? sender.tab! (background.ts#L76).
    • Every connection then unconditionally activates the tab and focuses its window (background.ts#L119-L122).
    • Nothing downstream is scoped to a workspace: chrome.debugger.sendCommand and chrome.tabs.create are allow-listed and forwarded verbatim (relayConnection.ts#L41-L47), so a Page.bringToFront re-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/src or 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/server spec 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, normal windows 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
    • Source at main sha 1586a4d (your report cites 6e8015a; the relevant lines are unchanged between the two).
    • background.ts — token-bypass tab adoption and the unconditional chrome.tabs.update({active}) / chrome.windows.update({focused}) block.
    • relayConnection.ts — ALLOWED_CHROME_COMMANDS includes chrome.debugger.sendCommand and chrome.tabs.create with no window scoping.
    • connectedTabGroup.ts — _onConnectionClose only ungroups, doesn't remove extension-created tabs.
    • Grepped packages/extension/src and the MCP extension path for any existing background/no-focus/unfocused option — none exists.
    • Did not run a live focus-steal repro: needs a real Chrome + macOS session for the CDP-input and window-routing behavior you measured.

    Triaged by the Playwright bot - agent run

  2. yury-s commented on Aug 26, 2026

    @yury-s
    Member

    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.

  3. rav4nn commented on Oct 2, 2026

    @rav4nn

    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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions