跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

提交记录

Merge pull request #2 from SweetGargamel/codex/fix-desktop-browser-handoff

fix(desktop): 打开外部登录页时切换到浏览器

作者
Shihao Li
时间
2026/11/04 20:42
提交
11d44ca
这个版本的全部文件

这是一个合并提交,下面是和第一个上一提交相比的改动。

修改docs/troubleshooting.md+2 −0看文件
@@ -85,6 +85,8 @@ Cage 需要先选择自己的代理。首次首页点击“配置网络与代理
8585
8686旧构建的尺寸控制脚本可能受到客机 zsh 中 mise 初始化的影响,持续返回尺寸调整失败。此时需要使用包含控制脚本修正的 Cage 构建。该修正兼容已有客机配置,在控制入口明确选择脚本解释器。复现条件和验证范围见[尺寸调整排查记录](test-reports/2026-11-04-desktop-resize/README.md)。
8787
88新增:Desktop 中的 Google 登录和外部链接会在 Cage 浏览器中打开,界面应自动切换到对应标签页;登录回调完成后会返回 Desktop。旧版本若只在后台打开页面,可先点击侧栏“浏览器”继续。
89新增:
8890## Claude 登录或请求失败
8991
9092Cage 不自动读取主机上的 Claude 登录。请在 Cage 终端运行 `claude`,按提示在 Cage 浏览器中完成授权;需要手动打开时复制完整授权链接到 Cage 地址栏。
修改ui/scripts/claude-desktop-smoke.mjs+32 −7看文件
@@ -8,6 +8,12 @@ const output = new URL(
88);
99await fs.mkdir(output, { recursive: true });
1010const { browser, page, state, errors } = await createWorkbench();
11新增:await page.addInitScript(() => {
12新增: window.EventSource = class {
13新增: constructor() { window.desktopBrowserEvents = this; }
14新增: close() {}
15新增: };
16新增:});
1117const desktop = {
1218 installed: false,
1319 running: false,
@@ -71,6 +77,25 @@ try {
7177 await page.getByRole("button", { name: "下载并安装", exact: true }).click();
7278 await page.getByRole("button", { name: "关闭应用", exact: true }).waitFor();
7379 assert.deepEqual(actions, ["install", "install", "start"]);
80新增: const desktopToolbar = page.locator(".claude-desktop-toolbar");
81新增: const sendBrowserState = (focus) => page.evaluate((snapshot) => {
82新增: window.desktopBrowserEvents.onmessage({ data: JSON.stringify(snapshot) });
83新增: }, { tabs: state.tabs, active: state.active, focus });
84新增: await sendBrowserState(false);
85新增: await desktopToolbar.waitFor();
86新增: const loginTab = { id: "desktop-login", kind: "web", title: "Desktop sign in", url: "https://claude.com/cai/login/app-google-auth" };
87新增: state.tabs.push(loginTab);
88新增: state.active = loginTab.id;
89新增: await sendBrowserState(true);
90新增: await desktopToolbar.waitFor({ state: "hidden" });
91新增: assert.equal(desktop.running, true, "opening an external login page must preserve Desktop");
92新增: await page.getByRole("button", { name: "Claude Desktop", exact: true }).click();
93新增: await sendBrowserState(false);
94新增: await desktopToolbar.waitFor();
95新增: state.tabs.push({ ...loginTab, id: "desktop-login-poll" });
96新增: state.active = "desktop-login-poll";
97新增: await desktopToolbar.waitFor({ state: "hidden" });
98新增: assert.equal(await page.getByRole("textbox", { name: "网页地址或搜索" }).inputValue(), loginTab.url);
7499 await page.getByRole("button", { name: "打开浏览器", exact: true }).click();
75100 assert.equal(
76101 desktop.running,
@@ -109,15 +134,12 @@ try {
109134 "claude --continue --model sonnet",
110135 );
111136 await page.getByRole("button", { name: /^在 .* 新建终端$/ }).click();
112删除: await page
113删除: .getByRole("dialog")
114删除: .getByText("claude --continue --model sonnet", { exact: true })
115删除: .waitFor();
137新增: await page.getByRole("menu", { name: "新建终端", exact: true }).waitFor();
116138 await page.screenshot({
117139 path: fileURLToPath(new URL("terminal-choice.png", output)),
118140 });
119141 await page
120删除: .getByRole("button", { name: "新建 Claude 终端", exact: true })
142新增: .getByRole("menuitem", { name: "Claude 终端", exact: true })
121143 .click();
122144 const terminalRequests = () =>
123145 state.requests.filter(
@@ -137,7 +159,7 @@ try {
137159 "reconnect must not relaunch Claude",
138160 );
139161 await page.getByRole("button", { name: /^在 .* 新建终端$/ }).click();
140删除: await page.getByRole("button", { name: "新建普通终端", exact: true }).click();
162新增: await page.getByRole("menuitem", { name: "普通终端", exact: true }).click();
141163 assert.equal(terminalRequests().at(-1).body.kind, "shell");
142164 await page.setViewportSize({ width: 820, height: 558 });
143165 await page
@@ -148,8 +170,11 @@ try {
148170 });
149171 assert.deepEqual(errors, []);
150172 console.log(
151删除: "PASS: sidebar, optional installation, failure/retry, shared application lifecycle, terminal choice, command settings and reconnect",
173新增: "PASS: sidebar, optional installation, failure/retry, Desktop login handoff via events and polling, background updates, lifecycle, terminal choice, settings and reconnect",
152174 );
175新增:} catch (error) {
176新增: console.error(JSON.stringify({ actions, desktop, status: state.status, errors, body: await page.locator("body").innerText() }));
177新增: throw error;
153178} finally {
154179 await browser.close();
155180}
修改ui/src/main.jsx+8 −0看文件
@@ -407,6 +407,10 @@ function App() {
407407 ...all.filter((item) => !previous.some((p) => p.id === item.id)),
408408 ];
409409 });
410新增: if (initialized.current && b.active && b.active !== activeRef.current && !browserIds.current.has(b.active)) {
411新增: setDesktopOpen(false);
412新增: setHome(false);
413新增: }
410414 if (
411415 !activeRef.current ||
412416 !all.some((item) => item.id === activeRef.current) ||
@@ -496,6 +500,10 @@ function App() {
496500 ...b.tabs.filter((t) => !previous.some((p) => p.id === t.id)),
497501 ];
498502 });
503新增: if (b.active && b.focus) {
504新增: setDesktopOpen(false);
505新增: setHome(false);
506新增: }
499507 if (
500508 b.active &&
501509 (b.focus ||