跳到主要内容

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

浏览文件

browser-login.test.mjs

34 行 · 1.6 KB历史下载
1import assert from "node:assert/strict";
2import test from "node:test";
3import { LoginBrowser } from "./browser-login.mjs";
4
5test("login redirects and popups stay private, closing one login leaves the other open", async () => {
6 const closed = [];
7 let contexts = 0;
8 const browser = new LoginBrowser(async (method, params, sessionId) => {
9 if (method === "Target.createBrowserContext") return { browserContextId: String(++contexts) };
10 if (method === "Target.createTarget") {
11 assert.equal(params.url, "about:blank", "login must be prepared before navigation");
12 return { targetId: "tab-" + params.browserContextId };
13 }
14 if (method === "Page.navigate") assert.equal(sessionId, "prepared-page");
15 if (method === "Target.disposeBrowserContext") closed.push(params.browserContextId);
16 });
17 const page = { url: "https://claude.ai/oauth/authorize?state=secret", title: "secret" };
18 assert.equal(browser.tab(page), page);
19 for (const id of ["a", "b"]) {
20 await browser.open(id.repeat(24), page.url, async tab => {
21 assert.equal(browser.tab(tab).url, "https://claude.ai");
22 return "prepared-page";
23 });
24 }
25 const popup = { ...page, targetId: "popup", browserContextId: "1", url: "http://localhost:9123/callback?code=secret" };
26 const privateTab = browser.tab(popup);
27 assert.equal(privateTab.title, "账号授权");
28 assert.equal(privateTab.url, "http://localhost:9123");
29 await browser.finish("a".repeat(24));
30 assert.deepEqual(closed, ["1"]);
31 assert.equal(browser.tab(popup, privateTab).url, privateTab.url);
32 await browser.finish("b".repeat(24));
33 assert.deepEqual(closed, ["1", "2"]);
34});