Skip to content

feat(browser): 侧栏浏览器清除数据(关联 #359) - #368

Merged
freedomkk-qfeng merged 4 commits into
ECNU:mainfrom
JunieXD:feat/sidebar-browser-clear-data
Nov 26, 2026
Merged

freedomkk-qfeng merged 4 commits into
ECNU:mainfrom
JunieXD:feat/sidebar-browser-clear-data

Conversation

@JunieXD

@JunieXD JunieXD commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

关联 #359

本 PR 基于 #366(右键菜单)和 #367(runner 修复),包含这两个 PR 的提交,请先审它们。清除数据的改动只在最后一个提交里。Agent 的 site 范围要用 browser_read 读过的网页,测试也要在真实的 DSH 工具管线里跑,所以要先有 runner 修复。

问题

侧栏浏览器的登录状态和网站数据按工作区存在内存里,同一工作区的对话共用一份,重启应用才会清空。界面上没有清除入口,Agent 读、写、删 Cookie 的调试命令都被拦下,Playwright MCP 自带的 Cookie 工具在侧栏里也用不了。想换账号,或让 Agent 从未登录的状态重新开始,只能重启应用。

修改

清除和随后的重新加载只在主进程实现一份(新文件 dsh-electron/src/sidebar-browser-data.mjs),有三个入口:

  • 网页右键菜单(侧栏浏览器:网页右键菜单 #358)的空白处加「清除此网站的数据…」。确认后清除这个网页所在工作区里这个网站的数据。侧栏自己的新标签页不是网站,不显示这一项。
  • 设置 → 通用设置,紧跟 DSH 的「网页链接默认打开方式」加一行「侧边栏浏览器数据」。按「清除」并确认后清除所有工作区。
  • Agent 工具 browser_clear_data,scope 为 site(Agent 最后用 browser_read 读过的网页所在的网站,和 browser_act 用同一个网页)或 workspace(本工作区的所有网站)。
    • 非 Full Access 下执行前请用户确认,确认文字写明清除范围,并说明同一工作区其他对话里也会退出登录。Full Access 下不问,和其他浏览器确认项一致。
    • Agent 仍然读不到 Cookie,也不开启 Playwright MCP 的 storage 工具。子 Agent 有自己的浏览器,不提供这个工具。
    • 工具经侧栏 broker 的本机端点调用,只发网页的来源。

清除的内容:

  • 一个网站:这个网站所有子域名的 Cookie,以及本工作区里这个网站出现过的各个来源的存储(网页自身,加上工作区里任何 frame 加载过的同站来源),用 clearData({ origins, originMatchingMode: 'origin-in-all-contexts' })。网站按可注册域划分,用 Cookie 的 Domain 能否设置来探测公共后缀:登录 Cookie 常设在主域上,只清一个来源会留下登录。
  • 一个网站时,还用 clearCache() 清掉这个工作区的整个 HTTP 缓存:Electron 按来源清不到只作为资源加载过的同站来源的缓存。清缓存不会让其他网站退出登录。
  • 工作区或全部:session.clearData()。

清除后:

  • 已打开的网页会继续显示清除前的内容,所以重新加载受影响的网页:清网站时重新加载这个网站的网页,清工作区时重新加载其中所有网页和 Agent 的后台页面。
  • 用 reloadIgnoringCache():普通的重新加载会沿用渲染进程内存里清除前的脚本。
  • 等到新文档提交、加载失败、网页关闭,或网站回 204/205 不换页面而停止加载后才返回,最多等 10 秒。
  • Agent 正在用这些网页时不拦截:browser_act 发现网页已经换了就不执行,返回新网页让 Agent 重新判断。工具的返回文字也提醒 Agent 先重新读网页。

文档:插件 README(中英文)的「确认」和「桌面侧栏」两节写明了这些入口和影响。

取舍

  • 数据仍只存在内存里,重启后清空。DSH 的设计把持久化存储留作后续工作,本 PR 不改。DSH 以后若自带清除入口,删掉我们的入口即可。
  • 只用 Electron 公开接口和 DSH 文档写明的 settings.general.item。各工作区的存储分区在 DSH 分配时经过我们的桌面桥,由桌面桥记录,不依赖分区命名。

验证

  • sidebar-browser.test.mjs(锁定的 Electron 44.0.0,真实 broker 和 sidebar-client.js),新增清除测试:
    • 清网站:同一网站各子域名的 Cookie 和各来源的存储被清除,其他网站保留;只作为资源加载过的同站来源的缓存也被清除;停在这个网站的网页重新加载,并且等新文档提交后才返回。
    • 网站回 204 时网页保留原页面,清除在 5 秒内返回;新标签页的地址被拒绝。
    • 清工作区、设置页清全部、确认期间标签页被关闭等情况。
    • macOS 完整跑多遍 13/13。
  • 插件测试(真实 DSH 工具管线)18/18:确认文字和范围;没读过网页时 site 先提示读网页;很长的网页地址只发来源;端点报错和连接中断时 Agent 收到的说明。
  • Windows 11 虚拟机(x64 仿真):sidebar-browser.test.mjs 3 次都是 13/13。
  • macOS 本地构建的候选包,真实产品加模拟模型:
    • 右键菜单显示「清除此网站的数据…」;取消时数据不变;确认后 www.qa.test、sso.qa.test 和网站级 Cookie 被清除,other.test 保留;网页重新加载后本地存储和 IndexedDB 都为空。
    • Agent 清网站:只清 other.test,审批卡写明网站和影响范围。Agent 清工作区:全部清空。
    • 设置页:弹出“清除侧边栏浏览器的所有数据?”,确认后全部清空。这一行显示在「网页链接默认打开方式」之后。
  • 原生冒烟(probe-native-desktop.mjs,本地构建的壳)新增一项:经真实桌面桥分配的工作区分区,从设置页清除。macOS 上 27 项全部通过。
  • 真实模型(ecnu-plus,同一候选包,合成测试站,非 Full Access,审批选「允许一次」)3 项都通过:
    • 「换个账号登录 www.qa.test,把这个网站的登录数据清掉,其他网站别动」:Agent 先读网页,再用 site 范围清除,审批卡写明网站和影响范围;www.qa.test、sso.qa.test 和网站级 Cookie 及存储被清除,other.test 保留。
    • 「把这个工作区的登录状态和网站数据全部清掉,然后打开 … 确认一下」:Agent 用 workspace 范围,6 个 Cookie 全部清除,打开网页确认后才回答。
    • 「看看现在有哪些 Cookie,清除这个网站的数据后再看一次,告诉我前后变化」:Agent 清除后重新读网页,报告的前后变化(Cookie、本地存储、会话存储、IndexedDB 都已清空)与实际一致。

JunieXD and others added 4 commits November 26, 2026 13:20
A page in the Sidebar browser showed nothing on a right click. The desktop
bridge now opens a native menu for what was clicked, in the application's
language: link items (new tab, system browser, copy address), image items
(copy image, copy address), editing or copy for fields and selected text,
and back, forward and reload elsewhere. New tabs and the system browser go
through the same paths as the Sidebar's own toolbar and DSH's popup checks.

The broker marks a page whose latest input came from its Agent, so the
Agent's right clicks and menu keys reach the page's own handlers without
showing a menu on the user's screen.

Closes ECNU#358
…0.2.2 tool pipeline

Since the upgrade to DSH 0.2.2 (ECNU#276), ctx.tools.execute takes only a model
batch ({ calls, signal, agent, toolSet }). The runner behind browser_read and
browser_act still passed one call ({ callId, name, arguments, parent }), so
every page read or action in the desktop app failed with "Tool batch
execution failed". The plugin's test replaced ctx.tools.execute with a
hand-written stand-in and was not in CI, so it kept passing.

The runner now prepares, dispatches and completes each Playwright MCP call
through ToolExecutionPipeline, as DSH's program tool calls do
(tool-executor-ptc): under the run's root call, Agent, step tool set, signal
and token as parent, so the browser permission still lets the run's own
calls through without asking again. Context that hooks add to those calls is
deferred to the run's result, and a call that concludes the turn concludes
it.

read-act.test.mjs now runs the tools in DSH's real registry, executor and
pipeline from the pinned Runtime, with only Playwright MCP's tools as
stand-ins, and installs the plugin's guard, permission and screenshot note as
its apply does. It checks each MCP call's place in the run's call tree, one
approval per run, a rejected run not running, step admission, stopping a
run, and hook context reaching the batch. CI runs it next to the Sidebar
launch test.
… data

The Sidebar browser keeps sign-ins and site data for each workspace, in
memory, and nothing short of restarting the app cleared them. Clearing now
lives in one place in the main process (sidebar-browser-data.mjs), reached
from three entries:
- "Clear data for this site…" on a page's menu, for that site in the
  page's workspace;
- a row in Settings → General, for every workspace;
- the Agent's browser_clear_data, for the site of the page it last read or
  its whole workspace, asked for outside Full Access.

A site's cookies go on every subdomain, the storage of each of its origins
the workspace loaded, and the workspace's HTTP cache, which Electron cannot
clear by origin for resources other pages loaded. The open pages concerned
then reload, bypassing what their renderers hold in memory, and clearing
answers once they have.

Closes ECNU#359
@freedomkk-qfeng
freedomkk-qfeng merged commit f5b6fab into ECNU:main Nov 26, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants