Repository navigation
fix(mcp): open extension client tabs in the background and emulate focus - #43658
Closed
Ari Mendelow (arimendelow) wants to merge 1 commit into
Closed
Ari Mendelow (arimendelow) wants to merge 1 commit into
Ari Mendelow (arimendelow) wants to merge 1 commit into
Conversation
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.
Author
|
@microsoft-github-policy-service agree company="Microsoft" |
Contributor
Test results for "MCP"5189 passed, 614 skipped Merge workflow run. |
Collaborator
|
I'll close this until we arrive to a product decision on the issue. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_clickthen times out on the "stable" check, andbrowser_typewithslowlyloses keys without an error. Playwright's own launcher emulates focus in every page, but extension mode connects withnoDefaults, which skips it.This change makes two edits in
BrowserModel:createTargetopens new client tabs withactive: false._attachTabsendsEmulation.setFocusEmulationEnabledto 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=_blanklink orwindow.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 newleaves the user's tab active.slowly) in its hidden tab while the user's tab is active. This test starts the browser with the newlaunch('unmanaged')fixture mode: the browser runs as a plain process and the test connects withnoDefaults, so only the relay's emulation is in play. Without this change the click times out.Both tests fail on upstream main (CI run).