fix(extension): activate tabs and focus window to fix background rendering failures#402
Open
ykswang wants to merge 1 commit intoalibaba:mainfrom
Open
fix(extension): activate tabs and focus window to fix background rendering failures#402ykswang wants to merge 1 commit intoalibaba:mainfrom
ykswang wants to merge 1 commit intoalibaba:mainfrom
Conversation
…ering failures When Chrome is not the focused OS window, elementFromPoint() returns null for background tabs, causing isTopElement() to incorrectly mark all elements as non-visible. The LLM then sees an empty page and enters a loop of opening new tabs. Three-layer fix: - switchToTab() now calls chrome.tabs.update(active: true) so the target tab gets full rendering priority instead of staying as a background tab - focusWindow() added and called at task start via chrome.windows.update to bring Chrome to the foreground when automation begins via MCP - isTopElement() now returns true when all elementFromPoint() calls yield null (background window fallback) instead of hiding every element Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
When Chrome is not the focused OS window,
elementFromPoint()returnsnullfor background tabs. This causesisTopElement()to incorrectly mark all elements as non-visible. The LLM then sees an empty page and enters a loop of opening new tabs instead of operating on the current page.Root cause:
switchToTab()only updated internal state (currentTabIdin storage) but never calledchrome.tabs.update(tabId, { active: true }). Combined with new tabs being created viachrome.tabs.create({ active: false }), the target tab always remained a background tab with throttled rendering.Three-layer fix:
switchToTab()now activates the tab viachrome.tabs.update(tabId, { active: true }), ensuring the target tab gets full rendering priority from ChromefocusWindow()added and called at task start viachrome.windows.update(windowId, { focused: true })to bring Chrome to the foreground when automation begins (especially important for MCP-driven workflows)isTopElement()graceful degradation — when allelementFromPoint()calls returnnull(indicating background window), optimistically assume elements are top-level instead of hiding them allFiles changed
packages/extension/src/agent/TabsController.ts—switchToTab()activates tab, newfocusWindow()method, updatedTabActiontypepackages/extension/src/agent/TabsController.background.ts— newactivate_tabandfocus_windowmessage handlerspackages/extension/src/agent/MultiPageAgent.ts— callfocusWindow()inonBeforeTaskpackages/page-controller/src/dom/dom_tree/index.js—isTopElement()fallback whenelementFromPointreturns all nullsTest plan
switchToTab()🤖 Generated with Claude Code