跳到主要内容

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

浏览文件

browser-warning-smoke.mjs

46 行 · 2.6 KB历史下载
1import assert from "node:assert/strict";
2import { createPrivacyController } from "./browser-privacy-fixture.mjs";
3
4const fixture = await createPrivacyController();
5try {
6 const { api, evaluate, waitFor, origin, restart } = fixture;
7 async function check(id) {
8 await waitFor(() => evaluate(id, "document.readyState === 'complete'"), "page loaded");
9 assert.deepEqual(await evaluate(id, "[navigator.webdriver, globalThis.webdriverAtLoad]"), [false, false]);
10 assert.equal(await evaluate(id, "Object.getOwnPropertyDescriptor(Navigator.prototype, 'webdriver').get.toString()"),
11 "function get webdriver() { [native code] }", "browser identity must retain Chromium's native getter");
12 }
13 await check((await api("/tabs")).active);
14 for (const incognito of [false, true]) {
15 const tab = await api("/new", { url: origin + "/identity", incognito });
16 await check(tab.id);
17 const frameIdentity = await evaluate(tab.id, `new Promise(resolve => {
18 const frame = document.createElement('iframe');
19 const received = event => {
20 if (event.source !== frame.contentWindow || !('fixtureIdentity' in (event.data || {}))) return;
21 removeEventListener('message', received); frame.remove(); resolve([event.data.fixtureIdentity, event.data.fixtureGetter]);
22 };
23 addEventListener('message', received);
24 frame.src = ${JSON.stringify(origin.replace("localhost", "127.0.0.1") + "/frame")};
25 document.body.append(frame);
26 })`);
27 assert.deepEqual(frameIdentity, [false, "function get webdriver() { [native code] }"], "cross-site frame must retain the native browser identity");
28 await fixture.cdp(tab.id, "Runtime.evaluate", {
29 expression: `window.open(${JSON.stringify(origin + "/popup")}, '_blank'); true`,
30 userGesture: true,
31 });
32 const popup = await waitFor(async () => (await api("/tabs")).tabs.find(item => item.url === origin + "/popup"), "popup loaded");
33 await check(popup.id);
34 await api("/close", { id: popup.id });
35 await api("/navigate", { id: tab.id, url: origin + "/next" });
36 await check(tab.id);
37 await api("/close", { id: tab.id });
38 }
39 await restart();
40 await check((await api("/tabs")).active);
41 const beforeAudit = (await api("/tabs")).tabs.map(tab => tab.id);
42 const audit = await api("/audit", { timezone: "UTC", network: false });
43 assert.ok(audit.language && audit.timezone);
44 assert.deepEqual((await api("/tabs")).tabs.map(tab => tab.id), beforeAudit, "settings audit must not retain a diagnostic tab");
45 console.log("PASS: first page script, normal/private navigation, popups, cross-site frames and profile restart retain native browser identity");
46} finally { await fixture.close(); }