Repository navigation
feat(browser): 对话的 Agent 直接操作侧栏浏览器标签页(关联 #212) - #250
Merged
freedomkk-qfeng merged 27 commits intoNov 5, 2026
Merged
Conversation
In the desktop app the conversation's own Agent now uses Playwright MCP against the browser tabs in that conversation's right sidebar, so the user watches every step, shares logins and can take over. Subagents, Web and CLI keep the isolated browser. - dsh-electron: a loopback CDP endpoint per conversation behind a secret that only the Host receives; pages cannot reach other targets, the application window or cookie storage; keyboard input follows focus into cross-site frames; hidden, collapsed and background tabs keep painting while the Agent works. - dsh-electron: Sidebar pages paint the browser's own background, as in Chrome, instead of letting the application show through; the Agent's screenshots of a page without a background are no longer transparent. - browser-upstream: per-Agent Playwright MCP launch, sidebar guidance, and the renderer half that opens tabs, marks the tab being driven and returns focus to where the user was. - browser-upstream approvals name the action: the element to click, the text to type, the address to open. Reading pages, switching tabs and opening public pages no longer ask. - Electron test with a stand-in sidebar following upstream's mount and collapse rules, wired into validate-pinned-dsh-source.
A popup or a tab the user opened reached the Agent while its guest still showed the blank start the Sidebar navigates away from, so Playwright saw an already loaded blank page and could attach mid-navigation. bind now waits, for every new tab, until the Sidebar's page replaced the blank start, taking over the wait Target.createTarget did. Waiting for the whole load is no longer needed. The Sidebar reported a page failed when the user or the Agent navigated during its load, as the abort's code does not cross IPC, and Electron also failed the next load with the abort of the page it left. The desktop bridge lets such aborted loads end, so a page with an image that never finishes neither holds the tab back nor shows the failure banner. The installer startup checks import the built native-desktop.mjs, which now loads the sidebar broker; stub it there as the other adapters are.
On Windows, nothing written to stdin reaches Electron's main process and Electron writes a blank line to stdout before the app does, so the sidebar browser test never got the fixture's replies and its setup timed out. The test and its Electron app now exchange messages over Node's IPC channel, which works on Windows and macOS.
JunieXD
marked this pull request as ready for review
October 27, 2026 13:40
…the Agent A desktop Host connected every conversation's Agent to the desktop Sidebar, which loads a new tab only for the conversation on screen. A conversation driven from a phone through remote access, or one the user had left, could not open a page, not even its first. While the conversation is not on screen, the renderer now opens the Agent's new page as a background guest, out of sight. It takes a lease from the desktop as the Sidebar does, in the storage of the conversation's Sidebar tabs, so the page shares their logins and gets the same guest rules. Such pages close when the Agent's connection ends, including ones still opening. While the Agent's turn runs, the tab it acts on is covered by its marker, now with a Stop button that cancels the turn like the composer's. The user's clicks and keys reach the page once the turn ends or they stop it, so the user and the Agent never act on it at once. The Sidebar now opens once per connection where the user sees the Agent at work, including on returning to the conversation, instead of spending that on a show the user could not see.
browser_read returns the page as text, with every element the user can use numbered in place; browser_act runs every action the Agent can decide from that page through its Playwright MCP tools, stops once the page moves on, and returns the page as it is then. One approval covers a batch. MCP no longer writes a snapshot file into the workspace after each action or waits a fixed settle time.
A screenshot without a file name comes back to the Agent like a page read and is kept in MCP's own output folder, so it no longer asks. Saving a screenshot, snapshot or log into the workspace under a name follows the session's file access, as the Agent's own file writes do: it asks only in read-only sessions, and the approval names the file.
A canvas or SVG the size of a chart has no text to read, so browser_read names it and says a screenshot shows it, instead of leaving the Agent to dig the numbers out of the page's scripts.
A link that loads another page is opened by its address, as browser_read opens one, in a new tab when the link targets one. None of the page's own click handlers run, so the action asks only as opening that address does: a public page opens without asking. The Agent goes on in a new tab the page itself opens once a response lists it, so the wait for a late link tab goes.
…the answer The browser skill asks the Agent to look only at what its next step needs, and to follow a link the page shows rather than type an address it guesses. It opens an address itself only when it is sure of it, such as a site's home page or a search with its terms, and goes on from the page when that address does not show what it needs. Once the page shows the answer or the outcome the user asked for, it stops there. browser_read's url and browser_act's description say the same where the Agent chooses between them.
Browser steps run without asking, as in Codex's and Magentic-UI's browsers: the user's request covers opening pages, following links and filling in fields. The application still asks by itself before a script runs in the page, files leave the computer, a page's dialog is accepted, the browser closes, or the Agent goes into a local or private network from another site; links within that network no longer ask. For the steps browser_act's confirm lists, such as submitting an application, sending a message, paying, deleting or entering personal data, the Agent asks the user through it even when the user asked for the step. It asks once for the whole outcome, with all its data, at its first such step, and the approval lists every action it will take; the further pages of the form, the page's own "are you sure" and the final submit then go through without asking again.
A screenshot taken with a file name does not come back in the result: Playwright MCP only saves it in the workspace. The result now gives the file's full path, so the Agent opens it with read_image instead of searching the disk for it, and the browser skill says to give a file name only when the user wants the picture kept.
Brings in DSH rc.5 and the Mulan PSL v2 license. The browser approval tests that classify synthetic private addresses are recorded in the receipt as reviewed, as tool-browser's test is.
The browser adapter's README, in both languages, now covers browser_read and browser_act, and the confirmations as they are: the application asks only before risky steps, and the Agent asks through browser_act's confirm before an outcome the user must confirm.
Clicking a page element no longer asks, so the locale test renders the approval for running a script in the page instead.
Without the desktop Sidebar, every Agent's Playwright MCP server is now mounted the way subagents' already are, with an isolated browser and without action snapshots or settle waits, which the official provider has no option for. browser_read and browser_act then work alike in the desktop app, Web and CLI. The Sidebar guidance is added only with a Sidebar.
- A browser tool the Agent calls itself, other than one that only looks, and a read that fails leave no page read: browser_act asks for a new read, and a private address no longer counts as entered from the same site because of a page the Agent has since left. - browser_act first checks that the browser is still on the document it read, as after the user took over, and runs nothing otherwise. Each read tags its document, so a reload or a form posted back to the same address stops a batch too, and numbered elements in shadow roots are found. - With confirm, the one confirmation also names what the application would ask about itself, such as a link into a private network. - A page longer than the read budget is read around where it is scrolled to, and the result says which way it goes on. - A field is called by the name the page gives it (aria-labelledby, aria-label, a label) before a caption shown with it, and a caption too long to be one is passed over instead of leaving the field unnamed.
- The same-site exception for a private address now holds only for browser_act, which checks before its first action that the browser is still on the page read. Opening a private address with browser_read or an MCP tool always asks, as the user may have left that site. - Each read records what every numbered element is and says, apart from what a field holds; browser_act runs nothing on an element the page has since put to another use, as a single-page app reusing a button does. - The reading window drops only lines wholly above the viewport, so a block or card reaching into it stays, and a single line is cut at 4,000 characters so one block cannot take the whole budget. - These checks run in the page's own world: they tell ordinary changes apart, not a page that forges them.
- browser_act's check names a control with the same code as the page read, so a button's value or an aria-labelledby text that changes is a different control too, compared in any case, as showing a hidden menu can change the case of its text. - A line grown past 2,000 characters goes on in a new one, and a long run of text is read in pieces placed where they are drawn, instead of being cut at 4,000 characters: the end of a long paragraph or a row of cards, scrolled to, is read.
…ething The page lock now lifts while the conversation's current turn has an ask_user_question call without a result, as when the Agent asks the user to sign in, read from the session's own events rather than from the cards the composer shows. A question that timed out has its result and the Agent goes on; a hidden card still waits; an approval keeps the page the Agent's. The READMEs now say the lock also lifts once the Agent has not used the page for a while, as it always has.
The page read now notes the user's own input from then on, trusted pointer, key and input events, and browser_act's check before its first step runs nothing once there was any, and shows the page as it is: the user may have chosen another option, as while the Agent asked them something or waited on an approval. Between its own steps the Agent's input is its own, and every read starts over. A field without a name of its own goes by the text before it in its box again, a checkbox's after it, and the check compares that name, so a field whose caption or placeholder now asks for something else stops the actions, while a message the page adds after it does not.
…d window Each Sidebar guest has its own background throttling, apart from the window's. With only the window's turned off while an Agent works, a window covered by another app stopped its guests' animation frames, and every click the Agent made timed out waiting for the page to be stable. The guests of a conversation whose Agent works, and any that arrive meanwhile, are no longer throttled until it rests.
The page script only hears its own document, so a press in an iframe, as on a widget that changes what the page's button acts on, went unnoticed. The main process now sees every press and key the user gives a Sidebar guest, in any of its frames (before-mouse-event, before-input-event), tells it from the Agent's input, which it relays itself, and counts it in the page's top document through the debugger session the Agent's commands use, so the count is there before any command the Agent sends after it. The page's own count of trusted input goes on, installed once per document apart from the count. A read records the count, and browser_act's check before its first step compares it.
… shows it A field without a name of its own was known by all the text before it in its own box, or after it for a checkbox, as the DOM holds it: hidden text counted, a checkbox captioned in the cell before it had no name, and a caption over 20 characters was not compared at all. Its caption is now the text the read shows with it, shown or not as the read decides, in the nearest box holding no other field that has a letter or digit in it: before it, or anywhere in the box for a checkbox or radio. The check compares the whole caption, however long, and the field's own names (label, placeholder, title, name): any change to the caption counts, as a word the page adds may be a message such as "required" or one that turns the field to another use; what comes after a text field, such as a count or a countdown, and the same text split another way do not. The shown name is the caption up to 20 characters, without a required star, else the placeholder.
This was referenced Nov 23, 2026
This was referenced Nov 25, 2026
Closed
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.
目标
实现 #212 的第一步:桌面版里,对话自己的 Agent 直接操作该对话右侧侧栏里的浏览器标签页。用户能看到每一步,点“停止”即可接手,登录态与侧栏共享;对话不在电脑屏幕上时(例如用手机远程接入),Agent 新开的网页在后台打开。Agent 把网页读成文字、一个网页上的动作一次做完,只在有风险的步骤前确认。子 Agent、Web 与 CLI 仍用原来的独立浏览器,新的读页和操作工具在那里同样可用。
做法
webContents.debugger转给对应的<webview>(与automation-browser.mjs同一思路)。EDUWORK_SIDEBAR_BROWSER_SECRET只交给 Host,browser-upstream读取后立即从环境中删除;连接地址经PLAYWRIGHT_MCP_CDP_ENDPOINT交给 Playwright MCP,不出现在进程参数里。mountSessionMcp对所有 Agent 用同一组参数,所以browser-upstream按 Agent 挂同一个 Playwright MCP:主 Agent 连侧栏,子 Agent 照旧--isolated。官方支持按 Agent 传参后可删掉这一层(代码注释已写明)。browser-upstream新增的 client)把 guest 和“对话、标签页”对应起来,替 Agent 开关标签页(对话不在屏幕上时开后台页面),在被操作的标签页上显示标记和“停止”按钮,并把 Agent 点击时被带走的焦点还给用户。browser-upstream新增browser_read、browser_act两个工具,以嵌套工具调用使用同一个 Playwright MCP。browser_read在网页里运行一段脚本,把用户看得到的内容读成文字,能用的链接、按钮、输入框就地编号;browser_act按编号依次执行一批输入、点击、选择、按键等动作,网页换页时提前停下,返回此时的网页。原来模型每个动作一轮,每轮还要再读一次 MCP 写进工作区的快照文件;现在 MCP 不写快照(--snapshot-mode none、--timeout-settle 0),一个网页上的操作通常一轮完成。Playwright MCP 原有的工具仍保留,用于标签页、截图、上传和网页对话框。Web 与 CLI 没有侧栏,所有 Agent 都用与子 Agent 相同的独立浏览器挂载,同样不写快照(官方 provider 没有这个参数)。改动要点
Target.*、Browser.*和读写 Cookie 的方法(Cookie 属于整个工作区分区,不属于单个页面);带 Origin 的连接和错误密钥被拒绝;同一对话的新连接替换旧连接,旧连接的回复不会发到新连接。dshDesktop.browser.acquire,存储键与该对话的侧栏相同)在窗口内看不见的位置开一个<webview>交给 Agent:登录状态与侧栏相同,主进程对侧栏 guest 的偏好、导航、弹窗和权限规则同样生效;Agent 关闭浏览器或断开时关闭,还没开好的也会释放。[Feature 提案] 侧栏浏览器人机同页:Agent 直接操作右侧浏览器 #212 写的是“远程接入沿用无头浏览器”,这里没有照做:Host 分不出一条消息来自手机还是电脑(DSH 记录 owner 的消息时不区分连接),同一对话也可能中途换设备;按对话是否显示在屏幕上判断能覆盖这两种情况,也去掉了原来“后台对话新开标签页直接报错”的限制。code,上游认不出是ERR_ABORTED;离开一个还在加载的网页时,Electron 还会让下一次加载带着这次中断一起失败。两种情况上游都会在已正常打开的网页上显示“页面加载失败”。现在桌面端让被打断的加载正常结束(上游本来就忽略这种中断)。Agent 新开的标签页和网页弹出的新窗口,在侧栏的网页替换掉起始空白页后交给 Agent,网页上有图片一直加载不完也不会卡住。<webview>默认背景透明,没设背景的网页会透出应用底色(深色主题下默认的黑字看不清),Agent 截到的则是透明 PNG,模型看到一片黑。现在侧栏网页和 Chrome 一样使用浏览器自己的背景(没声明配色的网页为白色);空白页和上游的占位文字仍随应用主题深浅。browser_act的confirm请用户确认:一件事在第一个这类步骤前问一次,写明网站和数据,提示里列出将执行的每一步,应用自己要确认的内容(例如链接进入内网地址)也写在这一次里;确认后,表单后面的页面、网页自己的“确定吗”和最终提交不再问。这种确认在完全访问模式下也会出现。提示按工具参数写明具体操作,例如“允许智能体打开本机或内网地址 http://127.0.0.1:8080/”;认不出的工具仍要确认;新标签页的地址和导航一样只允许 HTTP(S)。aria-labelledby、aria-label、<label>),没有时才用旁边的短文字;输入框写明已填的内容和网页声明的要求(类型、取值范围、长度),密码只说明是否已填;很长的网页读滚动位置附近的部分(过长的段落按显示位置分成多行),并说明还往哪个方向延续;图表等大块 canvas/SVG 标出位置,提示用不带文件名的截图查看;网页弹出模态对话框时只显示对话框;折叠菜单里的链接列在最后。会换页的链接按地址打开(目标是新窗口时在新标签页打开),不执行网页自己的点击处理,所以确认范围与直接打开该地址相同。网页内容包在<untrusted_web_content>里交给模型。browser_act执行第一步前先确认浏览器还在读过的那个文档上(同一地址重新加载、表单提交回同一地址也算换了),要操作的控件仍是读到的那个(单页应用把按钮改作他用也算变了;网页没给名称的输入框按它所在的框里、它前面显示的文字核对(复选框、单选框取框里所有文字),这些文字有任何改动都算变,字段后面的字数统计、倒计时或提示变化不算),每步之后同样核对;读过之后用户在网页上点过或输入过(桌面侧栏里包括 iframe 中的,由主进程计数,Agent 自己的输入不算),第一步前就停下。不是就停下并返回当前网页,例如用户接手后换了页面、改了选项。Agent 自己调用会离开当前页面的 MCP 工具(切换标签页、导航等)或读页失败后,读过的页面作废,要先重新读。SKILL.md):每次只看下一步需要的内容;网页上有链接就点链接,不自己拼地址,只有确定的地址(网站首页、百科条目、带检索条件的搜索地址)可以直接打开,打不开就回到网页上继续;网页已经显示答案或办成的结果就停下。browser-upstream的中英文 README 和给模型的提示词说明桌面侧栏的行为、读页与操作工具、限制和确认范围。验证
dsh-electron/tests/sidebar-browser.test.mjs(11 组),已接入validate-pinned-dsh-source的 Windows/macOS 矩阵;替身侧栏按上游的首次挂载规则、首次加载方式和收起样式实现,替身桌面端按上游的 guest 租约实现。覆盖:只操作本对话的标签页、新标签页交出时机、键盘不进应用窗口、隐藏标签页/收起侧栏/后台对话、从未在电脑上显示的对话用后台页面(输入、白底、弹窗、存储键、断开后关闭)、后台页面还没开好时 Agent 断开、锁定与停止、Agent 提问时放开锁、这个对话各标签页的后台节流、用户在网页(含跨站 iframe)里的按下和按键在 Agent 下一个命令之前计入且不算 Agent 自己的输入、回到对话时展开一次、多个对话同时操作、连接与页面隔离。每个修复都临时改回旧逻辑确认测试会失败。本机 macOS 用固定的 Electron 44.0.0 全部通过(合并 main 后用 DSH 0.2.1-rc.5 的运行时重跑,仍全部通过);Windows 11 虚拟机(Electron 44.0.0 win32-x64,x64 仿真)上 3b52910 的 10 组全部通过,之后新增的一组没有在虚拟机上跑,由 CI 的 Windows 矩阵运行。probe-native-desktop:侧栏 guest 打开没设背景的网页时为不透明白色;从一直加载不完的网页离开时,这次加载和下一次加载都正常结束。改回旧逻辑时两项都失败(全透明像素;两次加载都报失败)。本机通过。browser-upstream/test/sidebar.test.mjs:启动参数与环境变量,后台页面的存储键等工作区列表到达、Agent 断开时停止等待(4 项)。browser-upstream/test/permission.test.mjs(3 组):确认范围(只在风险步骤前确认、从别的网站进入内网、文件保存跟随文件权限)、各工具的提示文案与最终拒绝。page.test.mjs(6 组,其中四组在 Chromium 里运行页面脚本)和read-act.test.mjs(10 组):编号、名称来源、看不见的元素、密码、画出来的内容、遮罩和模态对话框、字段要求、Shadow DOM、同一地址重新加载、长网页按滚动位置读;批量执行、换页时停下、网页或控件已不是读过的那个时不执行、读过之后用户用过网页时不执行、自己调用 MCP 工具后读过的页面作废、只有点所在内网网站的链接免确认、链接按地址打开、confirm的提示(含内网地址)、带文件名截图的路径说明。这三个文件要用已装配产品的依赖,在本机运行,连同sidebar.test.mjs(含没有侧栏时的启动参数)共 23 项全部通过(DSH 0.2.1-rc.5);CI 未包含。其中两个文件用合成的内网地址测确认分类,源码回执把它们登记为已审查,与tool-browser的测试相同。scripts/test/plugin-locale.test.mjs经官方 ApprovalPanel 渲染中文提示,通过。browser_read、一次browser_act完成,11 秒。只有一次确认“允许智能体打开本机或内网地址 http://127.0.0.1:…/”;运行中被操作的标签页始终被标记覆盖,这一轮结束后标记立即隐去。installer-cleanup.test.mjs(main 和本 PR 都改了这个文件)33 项通过。confirm,个别用提问卡,有一次两者都用了)。写明网址和步骤的 9 个任务:71de768 上 8/9(未通过的一次是测试脚本在确认卡弹出时误判这一轮已结束,脚本已修正),3b52910 上 9/9。browser_act一步也没执行,重新读页后完成设置,并在回复里说明了用户改过的开关;同一流程中另一窗口挡住应用,Agent 每次点击约 0.2 秒完成(修复前都超时);网页上的跨站 iframe 改变了主页面按钮的操作对象,用户在 Agent 提问时点了 iframe 里的按钮,Agent 随后要点的“删除”没有执行,Agent 看到对象已变,转而再问用户。写明网址和步骤的任务在修复过程中的三个版本上各 8/8 通过(华东师大官网新闻一项因本机暂时连不上 www.ecnu.edu.cn 未跑),只说目的的 14 个任务办成 13 个(未办成的也是要上华东师大官网的新闻任务)。最终提交只改了网页没给名称的输入框的核对规则,用插件测试验证,未再跑真实任务。已知限制
confirm参数的说明判断,应用本身认不出哪个按钮是提交;测试中这类任务每次都确认了,但不能保证每个网站上都如此。browser_read不读 iframe 里的内容,只标出 iframe 并提示改用browser_snapshot;开放的 Shadow DOM 可以读到。browser_act也会停下、重新看网页再继续:脚本分不出加的是提示,还是“禁止”这类改变用途的词。data-sidebar-right-*、data-sidebar-browser-frame、dock 容器)、桌面端dshDesktop.browser的租约接口和存储键规则,以及 Chromium 在 1% 不透明度下继续绘制的行为;升级 DSH 或 Electron 时要重跑sidebar-browser.test.mjs并在真实产品上复验。browser_act从 Playwright MCP 工具结果里的标签页列表判断是否开了新标签页,升级 Playwright MCP 时要重跑read-act.test.mjs和真实产品上的任务。关联 #212