fix(extension): 消除 macOS 自动化窗口的残留抢焦(#739 后续)#1868
Open
huanghe wants to merge 1 commit into
Open
Conversation
a8c262e to
18fa9c0
Compare
Contributor
Author
|
已修复 CI: 本地复跑 |
…ndow Follow-up to jackwener#739 (architectural causes fixed in v1.7.22). The residual the maintainer acknowledged — macOS ignoring focused:false on the initial windows.create() — is removed by minimizing the background automation window right after creation, and by activating new tabs only in foreground mode. - minimize owned background window via windows.update({state:'minimized'}) (state:'minimized' is rejected with width/height on create(), accepted on update()) - chrome.tabs.create active = (windowMode === 'foreground') instead of always true - add OPENCLI_IDLE_TIMEOUT_MS so polling pipelines keep the window alive and avoid re-creating it (the original focus-pop trigger) Avoids the chrome.windows.getAll() reuse approach raised in jackwener#739, which crashed the service worker and broke window isolation.
18fa9c0 to
9c3fc9d
Compare
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.
背景
#739(macOS 上自动化窗口抢焦)已在 v1.7.22 以「架构性原因已解决」关闭——单一共享 Adapter 窗口、窗口持久化、
focused: mode === 'foreground'。维护者在关闭时明确指出仍有一处残留:本 PR 就是消除这「每次 Chrome 重启发生一次」的残留抢焦(在 macOS 15.x / Sequoia 上仍可稳定复现)。
改动
ensureOwnedContainerWindowUnlocked在mode === 'background'时调用chrome.windows.update(windowId, { state: 'minimized', focused: false })。(
state: 'minimized'与width/height一起传给create()会被拒绝,但在update()上可接受——所以放在创建之后。)最小化的窗口不会夺取焦点,从而连「首次创建」那一次抢焦也消除。chrome.tabs.create({ ..., active: true })改为active: getWindowMode(leaseKey) === 'foreground',避免后台自动化标签把窗口拉到前台。OPENCLI_IDLE_TIMEOUT_MS:允许轮询型管线延长自动化窗口存活时间、复用窗口,避免反复windows.create()(即抢焦的原始触发点)。对应 Browser Bridge: new windows steal focus on macOS (should use tabs instead) #739 讨论中 @gucasbrg 提出的「idle timeout 可配置」诉求。为什么不用
chrome.windows.getAll()复用方案#739 讨论中有人提过用
chrome.windows.getAll()复用已有窗口,但实测会导致 service worker 崩溃、并破坏getAutomationWindow()的窗口隔离设计(@rickexpgame、@Astro-Han 的反馈)。本 PR 不走这条路,只在 extension 自己拥有的窗口上做最小化,保持隔离不变。测试
npx tsc --noEmit通过;extension/dist/background.js已同步更新以匹配extension/src/background.ts。说明
本 PR 只针对 #739 的残留抢焦,刻意保持最小范围。若需要我也可以补充集成测试或在后台/前台模式上加更明确的开关,请告知。