feat(browser): 受管浏览器支持最小化与后台 session LRU 回收【已审核 PR】 - #1743
Merged
ErlichLiu merged 2 commits intoAug 19, 2026
Conversation
- 新增 MINIMIZE_BROWSER IPC:最小化保留 WebContents 与页面状态,X 仍为真正销毁 - 全局最多保留 8 个后台浏览器 session,按 LRU 回收,绝不回收前台或有 Agent 操作的 session - BrowserSlot overlay 临时遮挡时保持回收保护,仅真正卸载或最小化才进入候选 - Agent 浏览器操作 lease 覆盖安全校验、路径校验、排队、执行与 finally 释放 - 浏览器入口 tooltip 统一为「打开受管浏览器」 - 版本号:@proma/electron 0.17.43、@proma/shared 0.1.60 Made-with: Proma
Made-with: Proma
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.
概述
为受管浏览器加入「最小化」能力:点击
Minus隐藏浏览器面板时保留 WebContents、标签、页面状态与登录态,TabBar 上显示高亮的受管浏览器入口可随时恢复;X仍是真正的销毁。同时为后台浏览器 session 引入全局 LRU 上限(8 个),防止跨会话长期累积 WebContents 导致内存膨胀。本次改动同时修复两个生命周期边界问题:
改动
packages/shared/src/types/agent.ts— 新增MINIMIZE_BROWSERIPC 消息类型。packages/shared/src/types/browser.ts—BrowserViewLayout新增preserveSessionOnHide字段,区分 overlay 临时遮挡与真正卸载。apps/electron/src/main/lib/browser-controller.ts— 核心改动:MAX_BACKGROUND_BROWSER_SESSIONS = 8全局上限;minimize(sessionId)保留 WebContents、清除 presentation、触发 LRU 回收;pruneBackgroundSessions()按sessionLastActivityAtLRU 回收,跳过前台、overlay 保护、有 Agent 操作的 session;acquireAgentOperation()/ lease 机制:Navigate 与本地预览在异步安全校验前获取 lease,成功、失败、取消均finally释放;isBackgroundSession()显式排除preserveSessionOnHide与activeAgentOperationCount > 0的 session。apps/electron/src/main/ipc.ts— 注册MINIMIZE_BROWSERIPC 路由到browserController.minimize()。apps/electron/src/preload/index.ts— 暴露minimizeAgentBrowserAPI。apps/electron/src/renderer/components/browser/BrowserSlot.tsx— overlay 遮挡时发送preserveSessionOnHide: true;真正卸载时发送false。apps/electron/src/renderer/components/browser/BrowserPanel.tsx— 标题栏新增Minus最小化按钮(位于X左侧),调用最小化 IPC 并更新 minimized 原子状态。apps/electron/src/renderer/components/tabs/TabBar.tsx— 浏览器入口按钮在有最小化 session 时高亮显示,tooltip 统一为「打开受管浏览器」。apps/electron/src/renderer/atoms/browser-atoms.ts— 新增browserPanelMinimizedMapAtom。apps/electron/src/renderer/components/tabs/MainArea.tsx— 读取 minimized 状态使用store.get,避免 React 闭包拿到过期值。apps/electron/src/renderer/components/browser/AgentBrowserLinkProvider.tsx— Agent 响应打开链接前清除 minimized 状态。@proma/electron0.17.43、@proma/shared0.1.60。测试方法
bun run typecheck(workspace 全量)通过。bun run --filter='@proma/electron' build:main/build:preload/build:renderer通过。git diff --check无空白错误。Minus最小化 → TabBar 浏览器按钮高亮 → 点击恢复,页面状态保留;备注
Made with Proma · GitHub