fix(browser): create CDP targets in background - #82482
Open
Ramadas108 wants to merge 1 commit into
Open
Conversation
When Hermes drives an already-running Chrome via CDP, Target.createTarget without background:true activates the new tab and raises the browser window, stealing desktop focus from the operator while agents work in the browser. Force background:true in the CDP supervisor initial-page creation and in the raw browser_cdp tool so target creation never raises the user's window, without changing the existing browser workflow. Includes regression tests for both the supervisor and the raw tool paths.
Collaborator
Related to #80335: this focused patch carries its browser-CDP background-target fix without that PR's unrelated compatibility changes. |
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.
Problem
Hermes can drive an already-running Chrome over CDP (an attached or residential-IP browser, e.g.
127.0.0.1:9222). In two paths the CDP layer creates a page target:CDPSupervisor._attach_initial_page()— when no page target exists yet, the supervisor creates one.browser_cdptool — an agent escape hatch that forwards arbitrary CDP methods.Target.createTargetwithoutbackground: trueactivates the new tab and raises the browser window, stealing desktop focus from the operator while agents work in the browser. For an attached everyday browser this is disruptive: the user's window pops to the foreground mid-task.Fix
tools/browser_cdp_tool.py:Target.createTargetparams are forced tobackground: true, so the escape hatch cannot forget it.tools/browser_supervisor.py: initial page creation passesbackground: true.No change to the existing browser workflow — tabs created this way simply never raise the window.
Tests
tests/tools/test_browser_background_tab.py— regression tests for both paths (supervisor_attach_initial_pageand the rawbrowser_cdptool), asserting the background flag is always present.Validation
Verified against a real attached Chrome over CDP (
127.0.0.1:9222):Target.createTargetsucceeds with the background flag, the window is not raised, and the created target closes cleanly.