Skip to content

fix(mcp): open extension client tabs in the background and emulate focus - #43658

Closed
Ari Mendelow (arimendelow) wants to merge 1 commit into
microsoft:mainfrom
ourostack:user/arimendelow/no-focus-1-background-tabs
Closed

Ari Mendelow (arimendelow) wants to merge 1 commit into
microsoft:mainfrom
ourostack:user/arimendelow/no-focus-1-background-tabs

Conversation

@arimendelow

@arimendelow Ari Mendelow (arimendelow) commented Oct 27, 2026 •

Copy link
Copy Markdown

Part of #43657.

In extension mode, the client works in the user's own browser, so its tabs are usually hidden behind the tab the user is working in. Chrome gives a hidden tab no animation frames and drops key and mouse input. browser_click then times out on the "stable" check, and browser_type with slowly loses keys without an error. Playwright's own launcher emulates focus in every page, but extension mode connects with noDefaults, which skips it.

This change makes two edits in BrowserModel:

  • createTarget opens new client tabs with active: false.
  • _attachTab sends Emulation.setFocusEmulationEnabled to every tab it attaches. The emulation ends with the debugger session.

Attaching the same tab twice at once, which can happen during the connect handshake, now reuses the pending attach instead of failing with "Another debugger is already attached".

This works with the extension that has already shipped, with one limit: a tab that a hidden client tab opens (a target=_blank link or window.open) is not handed to the client, because Chrome reports the user's active tab as its opener and the shipped extension forwards a new tab only when its opener is attached. The same happens today when the user switches away from the client's tab. #43660 fixes it in the extension.

Note: while a client is connected, focus emulation also applies to tabs the user picked or dragged into the client's group. Those pages report themselves as focused and visible.

Tests (tests/extension/background-tabs.spec.ts):

  • browser_tabs new leaves the user's tab active.
  • A client clicks and types (slowly) in its hidden tab while the user's tab is active. This test starts the browser with the new launch('unmanaged') fixture mode: the browser runs as a plain process and the test connects with noDefaults, so only the relay's emulation is in play. Without this change the click times out.

Both tests fail on upstream main (CI run).

In extension mode the client works in the user's own browser. New client
tabs now open without being activated, and every tab the relay attaches
gets Emulation.setFocusEmulationEnabled, so a hidden tab keeps rendering,
takes clicks and key presses, and can be screenshotted. Playwright's own
launcher does the same, but extension mode connects with noDefaults,
which skips it.

Attaching the same tab twice at once (for example during the connect
handshake) now waits for the first attach instead of failing.
@arimendelow

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree company="Microsoft"

@github-actions

Copy link
Copy Markdown
Contributor

Test results for "MCP"

5189 passed, 614 skipped


Merge workflow run.

@dgozman

Copy link
Copy Markdown
Collaborator

I'll close this until we arrive to a product decision on the issue.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants