@liang-hz/agent-in-chrome 0.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.ext-id.txt +4 -0
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/PRIVACY.md +86 -0
- package/README.en.md +419 -0
- package/README.md +406 -0
- package/bin/agent-in-chrome.mjs +97 -0
- package/commands/agent-in-chrome.md +18 -0
- package/commands/install-agent-in-chrome.md +22 -0
- package/docs/AGENTS.md +94 -0
- package/docs/CLI.md +297 -0
- package/docs/client-compat.json +23 -0
- package/extension/about-toc.js +25 -0
- package/extension/about.html +240 -0
- package/extension/about.js +44 -0
- package/extension/agent-window.html +100 -0
- package/extension/icons/icon-128.png +0 -0
- package/extension/icons/icon-16.png +0 -0
- package/extension/icons/icon-24.png +0 -0
- package/extension/icons/icon-32.png +0 -0
- package/extension/icons/icon-48.png +0 -0
- package/extension/icons/icon-64.png +0 -0
- package/extension/icons/icon-attention-128.png +0 -0
- package/extension/icons/icon-attention-16.png +0 -0
- package/extension/icons/icon-attention-24.png +0 -0
- package/extension/icons/icon-attention-32.png +0 -0
- package/extension/icons/icon-attention-48.png +0 -0
- package/extension/icons/icon-attention-64.png +0 -0
- package/extension/icons/icon-attention.svg +18 -0
- package/extension/icons/icon-failed-128.png +0 -0
- package/extension/icons/icon-failed-16.png +0 -0
- package/extension/icons/icon-failed-24.png +0 -0
- package/extension/icons/icon-failed-32.png +0 -0
- package/extension/icons/icon-failed-48.png +0 -0
- package/extension/icons/icon-failed-64.png +0 -0
- package/extension/icons/icon-failed.svg +18 -0
- package/extension/icons/icon-idle-128.png +0 -0
- package/extension/icons/icon-idle-16.png +0 -0
- package/extension/icons/icon-idle-24.png +0 -0
- package/extension/icons/icon-idle-32.png +0 -0
- package/extension/icons/icon-idle-48.png +0 -0
- package/extension/icons/icon-idle-64.png +0 -0
- package/extension/icons/icon-idle.svg +18 -0
- package/extension/icons/icon-mark.svg +10 -0
- package/extension/icons/icon-running-128.png +0 -0
- package/extension/icons/icon-running-16.png +0 -0
- package/extension/icons/icon-running-24.png +0 -0
- package/extension/icons/icon-running-32.png +0 -0
- package/extension/icons/icon-running-48.png +0 -0
- package/extension/icons/icon-running-64.png +0 -0
- package/extension/icons/icon-running.svg +18 -0
- package/extension/icons/icon.svg +18 -0
- package/extension/manifest.json +44 -0
- package/extension/popup-ui.js +38 -0
- package/extension/popup.html +350 -0
- package/extension/popup.js +741 -0
- package/extension/sw.js +11127 -0
- package/extension/update-check.js +66 -0
- package/extension/welcome.html +110 -0
- package/extension/welcome.js +18 -0
- package/mcp/agent-identity.mjs +1007 -0
- package/mcp/cdp/bridge.mjs +239 -0
- package/mcp/cdp/browser-launch.mjs +1127 -0
- package/mcp/cdp/chrome-shim.mjs +1124 -0
- package/mcp/cdp/client.mjs +443 -0
- package/mcp/cli-invocation.mjs +67 -0
- package/mcp/config.mjs +191 -0
- package/mcp/foreground-guard.mjs +295 -0
- package/mcp/proc-win.mjs +112 -0
- package/mcp/secret-shape.mjs +155 -0
- package/mcp/server.mjs +3437 -0
- package/mcp/session-id.mjs +281 -0
- package/mcp/token.mjs +260 -0
- package/mcp/tool-tiers.mjs +84 -0
- package/mcp/trace.mjs +528 -0
- package/mcp/update-cli.mjs +163 -0
- package/mcp/update-notice.mjs +194 -0
- package/native-host/host.mjs +356 -0
- package/native-host/mac-foreground/aic-fg.swift +114 -0
- package/native-host/mac-foreground/build.mjs +43 -0
- package/package.json +46 -0
- package/scripts/agents.mjs +921 -0
- package/scripts/borrow-login.mjs +935 -0
- package/scripts/cli-browser.mjs +148 -0
- package/scripts/e2e-sweep.mjs +192 -0
- package/scripts/e2e.mjs +3911 -0
- package/scripts/fixture-server.mjs +1419 -0
- package/scripts/guard-publish.mjs +175 -0
- package/scripts/install.mjs +1383 -0
- package/scripts/launcher-provenance.mjs +74 -0
- package/scripts/pack-crx.mjs +82 -0
- package/scripts/pick.mjs +114 -0
- package/scripts/test-agents.mjs +968 -0
- package/scripts/test-borrow.mjs +289 -0
- package/scripts/test-config.mjs +618 -0
- package/scripts/test-e2e-sweep.mjs +251 -0
- package/scripts/test-foreground-guard.mjs +383 -0
- package/scripts/test-identity.mjs +1141 -0
- package/scripts/test-install-skill.mjs +378 -0
- package/scripts/test-protocol.mjs +712 -0
- package/scripts/test-security.mjs +1360 -0
- package/scripts/test-sw.mjs +14526 -0
- package/scripts/test-update.mjs +301 -0
- package/skills/agent-in-chrome/SKILL.md +60 -0
- package/skills/agent-in-chrome/references/actions-and-waits.md +136 -0
- package/skills/agent-in-chrome/references/amap-dir-dropdown.md +66 -0
- package/skills/agent-in-chrome/references/geetest-click-captcha.md +55 -0
- package/skills/agent-in-chrome/references/network-debugging.md +20 -0
- package/skills/agent-in-chrome/references/reading-pages.md +30 -0
- package/skills/agent-in-chrome/references/recovery.md +25 -0
- package/skills/agent-in-chrome/references/tabs-and-sessions.md +34 -0
- package/skills/install-agent-in-chrome/SKILL.md +252 -0
|
@@ -0,0 +1,741 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* 扩展弹窗(popup.html)的脚本:显示与 agent 的连接状态、按会话列出 agent 正开着的
|
|
3
|
+
* 标签页,并给出接管/交还、关页、解除全部托管、操作光标与独立窗口开关、工具档位、
|
|
4
|
+
* 凭据借出授权这几个入口。
|
|
5
|
+
* 数据一律经 chrome.runtime.sendMessage 向 service worker 要(popup-* 系列消息),
|
|
6
|
+
* 弹窗自己不持有状态:状态 1.5s 轮询一轮,待授权列表 2s 一轮。
|
|
7
|
+
*/
|
|
8
|
+
const $ = (id) => document.getElementById(id);
|
|
9
|
+
|
|
10
|
+
const CHIP_TEXT = { attention: "需要你", failed: "失败" };
|
|
11
|
+
const GROUP_CSS = {
|
|
12
|
+
grey: "#5f6368",
|
|
13
|
+
blue: "#1a73e8",
|
|
14
|
+
red: "#d93025",
|
|
15
|
+
yellow: "#f9ab00",
|
|
16
|
+
green: "#188038",
|
|
17
|
+
pink: "#d01884",
|
|
18
|
+
purple: "#a142f4",
|
|
19
|
+
cyan: "#007b83",
|
|
20
|
+
orange: "#fa903e",
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function host(url) {
|
|
24
|
+
try {
|
|
25
|
+
return new URL(url).host || url;
|
|
26
|
+
} catch {
|
|
27
|
+
return url || "";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function favicon(t) {
|
|
32
|
+
const u = t.favIconUrl || "";
|
|
33
|
+
if (/^(https?:|data:image\/)/.test(u)) {
|
|
34
|
+
const img = document.createElement("img");
|
|
35
|
+
img.className = "fav";
|
|
36
|
+
img.src = u;
|
|
37
|
+
img.alt = "";
|
|
38
|
+
img.addEventListener("error", () => img.replaceWith(fallbackFav()));
|
|
39
|
+
return img;
|
|
40
|
+
}
|
|
41
|
+
return fallbackFav();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function fallbackFav() {
|
|
45
|
+
const d = document.createElement("span");
|
|
46
|
+
d.className = "fav fallback";
|
|
47
|
+
d.textContent = "🌐";
|
|
48
|
+
return d;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const SURFACE_TEXT = { cli: "CLI", app: "桌面端" };
|
|
52
|
+
|
|
53
|
+
/*
|
|
54
|
+
* 「谁在开这一组」——四段身份,最多占两行:
|
|
55
|
+
*
|
|
56
|
+
* Claude Code · 桌面端 · agent-in-chrome ← 谁、什么形态、开在哪
|
|
57
|
+
* 修 sid 漂移与组认领 ← 这段对话叫什么
|
|
58
|
+
*
|
|
59
|
+
* 每一段都是别人给的任意字符串,只用 textContent,不拼 HTML。
|
|
60
|
+
*/
|
|
61
|
+
function agentTag(t) {
|
|
62
|
+
const frag = document.createDocumentFragment();
|
|
63
|
+
const surface = SURFACE_TEXT[t.agentSurface] || null;
|
|
64
|
+
const who = [t.agent, surface].filter(Boolean).join(" · ");
|
|
65
|
+
if (who || t.agentWorkspace) {
|
|
66
|
+
const line = document.createElement("div");
|
|
67
|
+
line.className = "agent";
|
|
68
|
+
if (who) {
|
|
69
|
+
const w = document.createElement("span");
|
|
70
|
+
w.className = "who";
|
|
71
|
+
w.textContent = who;
|
|
72
|
+
line.append(w);
|
|
73
|
+
}
|
|
74
|
+
if (t.agentWorkspace) {
|
|
75
|
+
const ws = document.createElement("span");
|
|
76
|
+
ws.className = "ws";
|
|
77
|
+
ws.textContent = (who ? "· " : "") + t.agentWorkspace;
|
|
78
|
+
line.append(ws);
|
|
79
|
+
}
|
|
80
|
+
const tip = [];
|
|
81
|
+
if (t.agentVersion) tip.push(`版本 ${t.agentVersion}`);
|
|
82
|
+
if (t.agentWorkspace) {
|
|
83
|
+
tip.push(`${t.agentWorkspaceKind === "git" ? "Git 仓库" : "工作目录"}:${t.agentWorkspace}`);
|
|
84
|
+
}
|
|
85
|
+
if (tip.length) line.title = tip.join("\n");
|
|
86
|
+
frag.append(line);
|
|
87
|
+
}
|
|
88
|
+
if (t.agentSession || t.agentTask) {
|
|
89
|
+
const line = document.createElement("div");
|
|
90
|
+
line.className = "agent asess";
|
|
91
|
+
line.textContent = [t.agentSession, t.agentTask].filter(Boolean).join(" › ");
|
|
92
|
+
const tip = [];
|
|
93
|
+
if (t.agentSession) tip.push(`这段对话的标题:${t.agentSession}`);
|
|
94
|
+
if (t.agentTask) tip.push(`正在动手的子任务:${t.agentTask}${t.agentTaskType ? `(${t.agentTaskType})` : ""}`);
|
|
95
|
+
line.title = tip.join("\n");
|
|
96
|
+
frag.append(line);
|
|
97
|
+
}
|
|
98
|
+
return frag;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const selecting = new Map();
|
|
102
|
+
let lastStatus = null;
|
|
103
|
+
function rerender() {
|
|
104
|
+
if (lastStatus !== undefined) render(lastStatus);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function render(s) {
|
|
108
|
+
lastStatus = s;
|
|
109
|
+
const ok = s && s.connected;
|
|
110
|
+
$("status").className = "status " + (ok ? "on" : "off");
|
|
111
|
+
$("state").textContent = ok ? "已连接 agent" : "未连接(agent 未运行或链路未通)";
|
|
112
|
+
$("reconnect").hidden = !!ok;
|
|
113
|
+
$("version").textContent = s && s.version ? `v${s.version}` : "";
|
|
114
|
+
const target = $("target");
|
|
115
|
+
target.innerHTML = "";
|
|
116
|
+
|
|
117
|
+
const list = (s && s.sessions) || [];
|
|
118
|
+
const groups = new Map();
|
|
119
|
+
for (const t of list) {
|
|
120
|
+
if (!groups.has(t.session)) groups.set(t.session, []);
|
|
121
|
+
groups.get(t.session).push(t);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
for (const key of [...selecting.keys()]) if (!groups.has(key)) selecting.delete(key);
|
|
125
|
+
|
|
126
|
+
const orphans = (s && s.orphans) || [];
|
|
127
|
+
const openWin = $("openwin");
|
|
128
|
+
if (openWin) openWin.hidden = !(s && s.agentWindow && s.agentWindow.id != null);
|
|
129
|
+
|
|
130
|
+
if (groups.size || orphans.length) {
|
|
131
|
+
const head = document.createElement("div");
|
|
132
|
+
head.className = "sec-title";
|
|
133
|
+
head.append("接管中");
|
|
134
|
+
const count = document.createElement("span");
|
|
135
|
+
count.className = "count";
|
|
136
|
+
const nTabs = list.length + orphans.reduce((n, g) => n + g.tabs.length, 0);
|
|
137
|
+
count.textContent = `${nTabs} 个页面 · ${groups.size + orphans.length} 个任务`;
|
|
138
|
+
head.append(count);
|
|
139
|
+
target.append(head);
|
|
140
|
+
|
|
141
|
+
for (const [key, tabs] of groups.entries()) {
|
|
142
|
+
const first = tabs[0];
|
|
143
|
+
const card = document.createElement("div");
|
|
144
|
+
card.className =
|
|
145
|
+
"sess" + (first.state === "failed" ? " bad" : first.state === "attention" ? " warn" : "") + (first.dormant ? " dormant" : "");
|
|
146
|
+
if (GROUP_CSS[first.color]) card.style.setProperty("--sc", GROUP_CSS[first.color]);
|
|
147
|
+
|
|
148
|
+
const sel = selecting.get(key);
|
|
149
|
+
if (sel) {
|
|
150
|
+
card.classList.add("selecting");
|
|
151
|
+
for (const t of tabs) if (!sel.has(t.tabId)) sel.set(t.tabId, true);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const headRow = document.createElement("div");
|
|
155
|
+
headRow.className = "sess-head";
|
|
156
|
+
if (sel) {
|
|
157
|
+
const allCb = document.createElement("input");
|
|
158
|
+
allCb.type = "checkbox";
|
|
159
|
+
allCb.checked = tabs.every((t) => sel.get(t.tabId) !== false);
|
|
160
|
+
allCb.title = "全选/全不选这个任务的页面";
|
|
161
|
+
allCb.addEventListener("change", () => {
|
|
162
|
+
for (const t of tabs) sel.set(t.tabId, allCb.checked);
|
|
163
|
+
rerender();
|
|
164
|
+
});
|
|
165
|
+
headRow.append(allCb);
|
|
166
|
+
}
|
|
167
|
+
const dot = document.createElement("span");
|
|
168
|
+
dot.className = "sdot";
|
|
169
|
+
const label = document.createElement("span");
|
|
170
|
+
label.className = "label";
|
|
171
|
+
label.textContent = first.label || first.title || "(无标题)";
|
|
172
|
+
label.title = first.label || "";
|
|
173
|
+
const titleCol = document.createElement("div");
|
|
174
|
+
titleCol.className = "sess-title";
|
|
175
|
+
titleCol.append(label);
|
|
176
|
+
titleCol.append(agentTag(first));
|
|
177
|
+
headRow.append(dot, titleCol);
|
|
178
|
+
if (first.dormant) {
|
|
179
|
+
const chip = document.createElement("span");
|
|
180
|
+
chip.className = "chip dormant";
|
|
181
|
+
chip.textContent = "休眠";
|
|
182
|
+
chip.title = "这个任务的 agent 进程已经退出。页面先留着(对话可能还没结束),闲置一段时间后自动回收;你还在看的页不会被关。";
|
|
183
|
+
headRow.append(chip);
|
|
184
|
+
} else if (CHIP_TEXT[first.state]) {
|
|
185
|
+
const chip = document.createElement("span");
|
|
186
|
+
chip.className = "chip " + first.state;
|
|
187
|
+
chip.textContent = CHIP_TEXT[first.state];
|
|
188
|
+
headRow.append(chip);
|
|
189
|
+
}
|
|
190
|
+
if (!sel) {
|
|
191
|
+
const n = document.createElement("span");
|
|
192
|
+
n.className = "tabn";
|
|
193
|
+
n.textContent = `${tabs.length} 页`;
|
|
194
|
+
headRow.append(n);
|
|
195
|
+
const heldIds = tabs.filter((t) => t.held).map((t) => t.tabId);
|
|
196
|
+
if (heldIds.length) {
|
|
197
|
+
const back = document.createElement("button");
|
|
198
|
+
back.className = "rel-btn";
|
|
199
|
+
back.textContent = "交给AI接管";
|
|
200
|
+
back.title = "把你接管中的页面立即交还给 agent:调试提示条和光晕马上回来,它可以继续操作。";
|
|
201
|
+
back.addEventListener("click", () => {
|
|
202
|
+
chrome.runtime.sendMessage({ type: "popup-unhold-tabs", tabIds: heldIds }, (r) => {
|
|
203
|
+
if (chrome.runtime.lastError || !r || r.error) {
|
|
204
|
+
toast(`失败:${r?.error || chrome.runtime.lastError?.message || "未知错误"}`);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
toast(`已交还 ${r.count} 个标签页`);
|
|
208
|
+
setTimeout(() => toast(""), 4000);
|
|
209
|
+
refresh();
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
headRow.append(back);
|
|
213
|
+
}
|
|
214
|
+
const takeable = tabs.filter((t) => !t.held);
|
|
215
|
+
if (takeable.length === 1) {
|
|
216
|
+
const rel = document.createElement("button");
|
|
217
|
+
rel.className = "rel-btn";
|
|
218
|
+
rel.textContent = "手动接管";
|
|
219
|
+
rel.title =
|
|
220
|
+
"暂时从 agent 手里接过这个页面:调试提示条立刻消失,你可以随意操作;agent 再碰它会被明确告知「用户接管中,等他说继续」。页面留在会话里,随时可以交还。";
|
|
221
|
+
rel.addEventListener("click", () => {
|
|
222
|
+
chrome.runtime.sendMessage({ type: "popup-hold-tabs", tabIds: [takeable[0].tabId] }, (r) => {
|
|
223
|
+
if (chrome.runtime.lastError || !r || r.error) {
|
|
224
|
+
toast(`失败:${r?.error || chrome.runtime.lastError?.message || "未知错误"}`);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
toast("已接管,agent 会被告知等你交还");
|
|
228
|
+
setTimeout(() => toast(""), 4000);
|
|
229
|
+
refresh();
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
headRow.append(rel);
|
|
233
|
+
} else if (takeable.length > 1) {
|
|
234
|
+
const rel = document.createElement("button");
|
|
235
|
+
rel.className = "rel-btn";
|
|
236
|
+
rel.textContent = "手动接管…";
|
|
237
|
+
rel.title =
|
|
238
|
+
"暂时从 agent 手里接过页面:点击后勾选要接管的页,再点「手动接管已选页面」生效。接管后调试提示条消失、你可以随意操作,agent 会被明确告知「用户接管中,等他说继续」。页面留在会话里,随时可以交还。";
|
|
239
|
+
rel.addEventListener("click", () => {
|
|
240
|
+
selecting.set(key, new Map(tabs.map((t) => [t.tabId, false])));
|
|
241
|
+
rerender();
|
|
242
|
+
});
|
|
243
|
+
headRow.append(rel);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
card.append(headRow);
|
|
247
|
+
|
|
248
|
+
for (const t of tabs) {
|
|
249
|
+
const row = document.createElement("div");
|
|
250
|
+
row.className = "tabrow";
|
|
251
|
+
if (sel) {
|
|
252
|
+
const cb = document.createElement("input");
|
|
253
|
+
cb.type = "checkbox";
|
|
254
|
+
cb.checked = !t.held && sel.get(t.tabId) !== false;
|
|
255
|
+
cb.disabled = !!t.held;
|
|
256
|
+
cb.addEventListener("change", () => {
|
|
257
|
+
sel.set(t.tabId, cb.checked);
|
|
258
|
+
rerender();
|
|
259
|
+
});
|
|
260
|
+
row.append(cb);
|
|
261
|
+
}
|
|
262
|
+
const meta = document.createElement("div");
|
|
263
|
+
meta.className = "tmeta";
|
|
264
|
+
const title = document.createElement("span");
|
|
265
|
+
title.className = "ttitle";
|
|
266
|
+
title.textContent = t.title || "(无标题)";
|
|
267
|
+
const h = document.createElement("span");
|
|
268
|
+
h.className = "thost";
|
|
269
|
+
h.textContent = host(t.url);
|
|
270
|
+
meta.title = `${t.title || ""}\n${t.url || ""}`;
|
|
271
|
+
meta.append(title, h);
|
|
272
|
+
if (t.openedBy) {
|
|
273
|
+
const by = document.createElement("span");
|
|
274
|
+
by.className = "tby";
|
|
275
|
+
by.textContent = `· ${t.openedBy}`;
|
|
276
|
+
by.title = `这个页面由子任务「${t.openedBy}」打开`;
|
|
277
|
+
meta.append(by);
|
|
278
|
+
}
|
|
279
|
+
row.append(favicon(t), meta);
|
|
280
|
+
if (t.held) {
|
|
281
|
+
const chip = document.createElement("span");
|
|
282
|
+
chip.className = "chip held";
|
|
283
|
+
chip.textContent = "你接管中";
|
|
284
|
+
chip.title = "你正在手动操作这个页面,agent 对它的操作会被叫停。点上方「交给AI接管」交还。";
|
|
285
|
+
row.append(chip);
|
|
286
|
+
}
|
|
287
|
+
card.append(row);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (sel) {
|
|
291
|
+
const picked = tabs.filter((t) => !t.held && sel.get(t.tabId) !== false).map((t) => t.tabId);
|
|
292
|
+
const actions = document.createElement("div");
|
|
293
|
+
actions.className = "sel-actions";
|
|
294
|
+
const go = document.createElement("button");
|
|
295
|
+
go.className = "go";
|
|
296
|
+
go.textContent = picked.length ? `手动接管已选页面(${picked.length})` : "先勾选要接管的页面";
|
|
297
|
+
go.title = "从 agent 手里接过勾选的页面:页面保持打开、留在会话里,agent 的操作会被叫停,直到你交还";
|
|
298
|
+
go.disabled = picked.length === 0;
|
|
299
|
+
go.addEventListener("click", () => {
|
|
300
|
+
chrome.runtime.sendMessage({ type: "popup-hold-tabs", tabIds: picked }, (r) => {
|
|
301
|
+
if (chrome.runtime.lastError || !r || r.error) {
|
|
302
|
+
toast(`失败:${r?.error || chrome.runtime.lastError?.message || "未知错误"}`);
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
selecting.delete(key);
|
|
306
|
+
toast(`已接管 ${r.count} 个标签页,agent 会被告知等你交还`);
|
|
307
|
+
setTimeout(() => toast(""), 4000);
|
|
308
|
+
refresh();
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
const cancel = document.createElement("button");
|
|
312
|
+
cancel.textContent = "取消";
|
|
313
|
+
cancel.addEventListener("click", () => {
|
|
314
|
+
selecting.delete(key);
|
|
315
|
+
rerender();
|
|
316
|
+
});
|
|
317
|
+
actions.append(go, cancel);
|
|
318
|
+
card.append(actions);
|
|
319
|
+
}
|
|
320
|
+
target.append(card);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
for (const g of orphans) {
|
|
324
|
+
const card = document.createElement("div");
|
|
325
|
+
card.className = "sess orphan";
|
|
326
|
+
if (GROUP_CSS[g.color]) card.style.setProperty("--sc", GROUP_CSS[g.color]);
|
|
327
|
+
|
|
328
|
+
const headRow = document.createElement("div");
|
|
329
|
+
headRow.className = "sess-head";
|
|
330
|
+
const label = document.createElement("span");
|
|
331
|
+
label.className = "label";
|
|
332
|
+
label.textContent = g.title || "(无标题)";
|
|
333
|
+
const dot = document.createElement("span");
|
|
334
|
+
dot.className = "sdot";
|
|
335
|
+
const chip = document.createElement("span");
|
|
336
|
+
chip.className = "chip orphan";
|
|
337
|
+
chip.textContent = g.reclaimable ? "待认领" : "遗留";
|
|
338
|
+
chip.title = g.reclaimable
|
|
339
|
+
? "扩展重载过,会话表清空了;这组的 agent 只要再有一次调用就会把它认回去。等不及就用下面两个按钮自己处置。"
|
|
340
|
+
: "扩展重载或浏览器重启前留下的 agent 标签组,现在没有会话在管它";
|
|
341
|
+
const titleCol = document.createElement("div");
|
|
342
|
+
titleCol.className = "sess-title";
|
|
343
|
+
titleCol.append(label);
|
|
344
|
+
if (g.agent || g.agentWorkspace || g.agentSession) {
|
|
345
|
+
titleCol.append(
|
|
346
|
+
agentTag({
|
|
347
|
+
agent: g.agent,
|
|
348
|
+
agentSurface: g.agentSurface,
|
|
349
|
+
agentWorkspace: g.agentWorkspace,
|
|
350
|
+
agentWorkspaceKind: g.agentWorkspaceKind,
|
|
351
|
+
agentSession: g.agentSession,
|
|
352
|
+
})
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
headRow.append(dot, titleCol, chip);
|
|
356
|
+
card.append(headRow);
|
|
357
|
+
|
|
358
|
+
for (const t of g.tabs) {
|
|
359
|
+
const row = document.createElement("div");
|
|
360
|
+
row.className = "tabrow";
|
|
361
|
+
const meta = document.createElement("div");
|
|
362
|
+
meta.className = "tmeta";
|
|
363
|
+
const title = document.createElement("span");
|
|
364
|
+
title.className = "ttitle";
|
|
365
|
+
title.textContent = t.title || "(无标题)";
|
|
366
|
+
const h = document.createElement("span");
|
|
367
|
+
h.className = "thost";
|
|
368
|
+
h.textContent = host(t.url);
|
|
369
|
+
meta.title = `${t.title || ""}\n${t.url || ""}`;
|
|
370
|
+
meta.append(title, h);
|
|
371
|
+
row.append(favicon(t), meta);
|
|
372
|
+
card.append(row);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
const actions = document.createElement("div");
|
|
376
|
+
actions.className = "sel-actions";
|
|
377
|
+
const ungroup = document.createElement("button");
|
|
378
|
+
ungroup.textContent = "解散分组";
|
|
379
|
+
ungroup.title = "把这组拆掉:页面全部保留,只是移出分组、变回普通标签页";
|
|
380
|
+
ungroup.addEventListener("click", () => {
|
|
381
|
+
chrome.runtime.sendMessage({ type: "popup-ungroup-group", groupId: g.groupId }, (r) => {
|
|
382
|
+
if (chrome.runtime.lastError || !r || r.error) {
|
|
383
|
+
toast(`失败:${r?.error || chrome.runtime.lastError?.message || "未知错误"}`);
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
toast(`已解散,${r.count} 个页面保留`);
|
|
387
|
+
setTimeout(() => toast(""), 4000);
|
|
388
|
+
refresh();
|
|
389
|
+
});
|
|
390
|
+
});
|
|
391
|
+
const close = document.createElement("button");
|
|
392
|
+
close.className = "go";
|
|
393
|
+
close.title = "关闭这组里的所有页面(不可撤销,要点两次确认)";
|
|
394
|
+
close.textContent = "关闭这组";
|
|
395
|
+
let closeArmed = false;
|
|
396
|
+
close.addEventListener("click", () => {
|
|
397
|
+
if (!closeArmed) {
|
|
398
|
+
closeArmed = true;
|
|
399
|
+
close.textContent = "再点一次确认";
|
|
400
|
+
setTimeout(() => {
|
|
401
|
+
closeArmed = false;
|
|
402
|
+
close.textContent = "关闭这组";
|
|
403
|
+
}, 4000);
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
chrome.runtime.sendMessage({ type: "popup-close-group", groupId: g.groupId }, (r) => {
|
|
407
|
+
if (chrome.runtime.lastError || !r || r.error) {
|
|
408
|
+
toast(`失败:${r?.error || chrome.runtime.lastError?.message || "未知错误"}`);
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
toast(`已关闭 ${r.count} 个页面`);
|
|
412
|
+
setTimeout(() => toast(""), 4000);
|
|
413
|
+
refresh();
|
|
414
|
+
});
|
|
415
|
+
});
|
|
416
|
+
actions.append(ungroup, close);
|
|
417
|
+
card.append(actions);
|
|
418
|
+
target.append(card);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
const hint = document.createElement("div");
|
|
422
|
+
hint.className = "drag-hint";
|
|
423
|
+
hint.textContent = "提示:把标签页拖进某个会话的标签组,等于允许该会话使用它。";
|
|
424
|
+
target.append(hint);
|
|
425
|
+
} else if (ok) {
|
|
426
|
+
const head = document.createElement("div");
|
|
427
|
+
head.className = "sec-title";
|
|
428
|
+
head.textContent = "接管中的页面";
|
|
429
|
+
const d = document.createElement("div");
|
|
430
|
+
d.className = "empty";
|
|
431
|
+
d.textContent = "当前没有会话在操作标签页";
|
|
432
|
+
target.append(head, d);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (!ok && s && s.lastDisconnect) {
|
|
436
|
+
const box = document.createElement("div");
|
|
437
|
+
box.className = "diag";
|
|
438
|
+
const why = document.createElement("b");
|
|
439
|
+
why.textContent = s.lastDisconnect.why;
|
|
440
|
+
const fix = document.createElement("div");
|
|
441
|
+
fix.textContent = s.lastDisconnect.fix;
|
|
442
|
+
box.append(why, fix);
|
|
443
|
+
if (s.lastDisconnect.raw) {
|
|
444
|
+
const raw = document.createElement("code");
|
|
445
|
+
raw.textContent = s.lastDisconnect.raw;
|
|
446
|
+
box.append(raw);
|
|
447
|
+
}
|
|
448
|
+
target.append(box);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// SW 里存的 title/url 是接管那一刻的快照;标签页此后可能导航过。
|
|
453
|
+
// 弹窗有 tabs 权限,直接问浏览器要当下的标题和图标,问不到(标签页已关)就用快照。
|
|
454
|
+
async function enrich(s) {
|
|
455
|
+
const list = (s && s.sessions) || [];
|
|
456
|
+
await Promise.all(
|
|
457
|
+
list.map(async (t) => {
|
|
458
|
+
if (!t.tabId) return;
|
|
459
|
+
try {
|
|
460
|
+
const live = await chrome.tabs.get(t.tabId);
|
|
461
|
+
if (live.title) t.title = live.title;
|
|
462
|
+
if (live.url) t.url = live.url;
|
|
463
|
+
if (live.favIconUrl) t.favIconUrl = live.favIconUrl;
|
|
464
|
+
} catch {}
|
|
465
|
+
})
|
|
466
|
+
);
|
|
467
|
+
return s;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
let renderSeq = 0;
|
|
471
|
+
function refresh() {
|
|
472
|
+
const seq = ++renderSeq;
|
|
473
|
+
chrome.runtime.sendMessage({ type: "popup-status" }, async (s) => {
|
|
474
|
+
if (chrome.runtime.lastError) return render(null);
|
|
475
|
+
await enrich(s);
|
|
476
|
+
if (seq === renderSeq) render(s);
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
(async () => {
|
|
481
|
+
const current = chrome.runtime.getManifest().version;
|
|
482
|
+
const { latest, hasUpdate, channel } = await window.aicUpdateCheck.check(current);
|
|
483
|
+
if (!hasUpdate) return;
|
|
484
|
+
const a = document.createElement("a");
|
|
485
|
+
a.href = "https://github.com/Liang-HZ/agent-in-chrome/releases";
|
|
486
|
+
a.target = "_blank";
|
|
487
|
+
a.textContent = `新版 ${latest} →`;
|
|
488
|
+
a.title =
|
|
489
|
+
channel === "store"
|
|
490
|
+
? `当前 ${current},落后较多——商店更新可能卡住了,去 chrome://extensions 开自动更新或重装商店版`
|
|
491
|
+
: `当前 ${current},点击查看更新说明`;
|
|
492
|
+
$("update").append(a);
|
|
493
|
+
})();
|
|
494
|
+
|
|
495
|
+
let armed = false;
|
|
496
|
+
let armTimer = null;
|
|
497
|
+
function disarm() {
|
|
498
|
+
armed = false;
|
|
499
|
+
clearTimeout(armTimer);
|
|
500
|
+
$("closeall").classList.remove("confirm");
|
|
501
|
+
$("closeall").textContent = "关闭 agent 开的所有标签页";
|
|
502
|
+
}
|
|
503
|
+
function toast(text) {
|
|
504
|
+
const t = $("toast");
|
|
505
|
+
t.textContent = text;
|
|
506
|
+
t.hidden = !text;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
$("closeall").addEventListener("click", () => {
|
|
510
|
+
if (!armed) {
|
|
511
|
+
armed = true;
|
|
512
|
+
$("closeall").classList.add("confirm");
|
|
513
|
+
$("closeall").textContent = "确定要关闭?再点一次";
|
|
514
|
+
armTimer = setTimeout(disarm, 4000);
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
disarm();
|
|
518
|
+
toast("清理中…");
|
|
519
|
+
chrome.runtime.sendMessage({ type: "popup-close-all" }, (r) => {
|
|
520
|
+
if (chrome.runtime.lastError || !r || r.error) {
|
|
521
|
+
toast(`失败:${r?.error || chrome.runtime.lastError?.message || "未知错误"}`);
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
const parts = [`已关闭 ${r.closedCount || 0} 个标签页`];
|
|
525
|
+
if (r.releasedCount) parts.push(`${r.releasedCount} 个你拖进来的已还给你`);
|
|
526
|
+
toast(parts.join(","));
|
|
527
|
+
setTimeout(() => toast(""), 4000);
|
|
528
|
+
refresh();
|
|
529
|
+
});
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
$("reconnect").addEventListener("click", () => {
|
|
533
|
+
chrome.runtime.sendMessage({ type: "popup-reconnect" }, () => setTimeout(refresh, 300));
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
let releaseArmed = false;
|
|
537
|
+
let releaseTimer = null;
|
|
538
|
+
const RELEASE_TITLE = $("release").title;
|
|
539
|
+
function disarmRelease() {
|
|
540
|
+
releaseArmed = false;
|
|
541
|
+
clearTimeout(releaseTimer);
|
|
542
|
+
$("release").classList.remove("confirm");
|
|
543
|
+
$("release").title = RELEASE_TITLE;
|
|
544
|
+
}
|
|
545
|
+
$("release").addEventListener("click", () => {
|
|
546
|
+
if (!releaseArmed) {
|
|
547
|
+
releaseArmed = true;
|
|
548
|
+
$("release").classList.add("confirm");
|
|
549
|
+
$("release").title = "再点一次确认:解除全部托管";
|
|
550
|
+
toast("再点一次「解除全部托管」确认:页面全保留,agent 需重新接管");
|
|
551
|
+
releaseTimer = setTimeout(() => {
|
|
552
|
+
disarmRelease();
|
|
553
|
+
toast("");
|
|
554
|
+
}, 4000);
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
disarmRelease();
|
|
558
|
+
chrome.runtime.sendMessage({ type: "popup-release" }, () => {
|
|
559
|
+
toast("已解除全部托管");
|
|
560
|
+
setTimeout(() => toast(""), 3000);
|
|
561
|
+
setTimeout(refresh, 200);
|
|
562
|
+
});
|
|
563
|
+
});
|
|
564
|
+
$("reload").addEventListener("click", () => {
|
|
565
|
+
toast("重载中…约 1-2 秒");
|
|
566
|
+
chrome.runtime.sendMessage({ type: "popup-reload" }, () => {
|
|
567
|
+
setTimeout(() => {
|
|
568
|
+
toast("");
|
|
569
|
+
refresh();
|
|
570
|
+
}, 2000);
|
|
571
|
+
});
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
$("cursor").addEventListener("change", (e) => {
|
|
575
|
+
chrome.runtime.sendMessage({ type: "popup-cursor", on: e.target.checked }, (r) => {
|
|
576
|
+
if (!chrome.runtime.lastError && r) $("cursor").checked = !!r.on;
|
|
577
|
+
});
|
|
578
|
+
});
|
|
579
|
+
chrome.runtime.sendMessage({ type: "popup-cursor" }, (r) => {
|
|
580
|
+
if (!chrome.runtime.lastError && r) $("cursor").checked = !!r.on;
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
$("openwin").addEventListener("click", () => {
|
|
584
|
+
chrome.runtime.sendMessage({ type: "popup-open-agent-window" }, () => window.close());
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
$("sepwin").addEventListener("change", (e) => {
|
|
588
|
+
chrome.runtime.sendMessage({ type: "popup-sepwin", on: e.target.checked }, (r) => {
|
|
589
|
+
if (!chrome.runtime.lastError && r) $("sepwin").checked = !!r.on;
|
|
590
|
+
});
|
|
591
|
+
});
|
|
592
|
+
chrome.runtime.sendMessage({ type: "popup-sepwin" }, (r) => {
|
|
593
|
+
if (!chrome.runtime.lastError && r) $("sepwin").checked = !!r.on;
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
// 工具档位。真源是 ~/.agent-in-chrome/config.json(经 SW → host 落盘),这里不留副本。
|
|
597
|
+
// 档位决定哪些工具出现在 agent 的工具列表里;改完 server 靠 fs.watch 立即热更新,
|
|
598
|
+
// 客户端那侧没跟上的话提示重启客户端(README「配置」一节的口径)。
|
|
599
|
+
function cfgShow(r, changed) {
|
|
600
|
+
const hint = $("cfghint");
|
|
601
|
+
const tiers = document.getElementById("profile");
|
|
602
|
+
if (!r || !r.ok) {
|
|
603
|
+
tiers.classList.add("off");
|
|
604
|
+
hint.textContent = (r && r.error) || "读不到配置";
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
tiers.classList.remove("off");
|
|
608
|
+
const cur = r.value?.tools?.profile || "full";
|
|
609
|
+
for (const el of tiers.querySelectorAll("input")) el.checked = el.value === cur;
|
|
610
|
+
const extras = (r.value?.tools?.disable || []).length;
|
|
611
|
+
hint.textContent = changed
|
|
612
|
+
? "已保存,立即生效。agent 那边没跟上的话,重启那个客户端。"
|
|
613
|
+
: extras
|
|
614
|
+
? `另有 ${extras} 个工具在 config.json 里被单独关掉`
|
|
615
|
+
: "";
|
|
616
|
+
}
|
|
617
|
+
document.getElementById("profile").addEventListener("change", (e) => {
|
|
618
|
+
chrome.runtime.sendMessage({ type: "popup-config", patch: { tools: { profile: e.target.value } } }, (r) => {
|
|
619
|
+
if (!chrome.runtime.lastError) cfgShow(r, true);
|
|
620
|
+
});
|
|
621
|
+
});
|
|
622
|
+
chrome.runtime.sendMessage({ type: "popup-config" }, (r) => {
|
|
623
|
+
if (!chrome.runtime.lastError) cfgShow(r, false);
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
// 凭据借出:cookie 导出的按域授权面板。真源是扩展自己的 storage.local(见 sw.js 的
|
|
627
|
+
// cookieLoanGate),不经 host、不进 config.json——闸在扩展里执行,判据就得在扩展手边,
|
|
628
|
+
// 否则 host 一断就成了失败开放。
|
|
629
|
+
function cgRow(cls) {
|
|
630
|
+
const d = document.createElement("div");
|
|
631
|
+
d.className = "cg-row" + (cls ? " " + cls : "");
|
|
632
|
+
return d;
|
|
633
|
+
}
|
|
634
|
+
function cgBtn(text, cls, title, onClick) {
|
|
635
|
+
const b = document.createElement("button");
|
|
636
|
+
b.textContent = text;
|
|
637
|
+
if (cls) b.className = cls;
|
|
638
|
+
if (title) b.title = title;
|
|
639
|
+
b.addEventListener("click", onClick);
|
|
640
|
+
return b;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
function cgShow(r) {
|
|
644
|
+
const askBox = $("cgask");
|
|
645
|
+
const grantBox = $("cggrants");
|
|
646
|
+
const hint = $("cghint");
|
|
647
|
+
askBox.innerHTML = "";
|
|
648
|
+
grantBox.innerHTML = "";
|
|
649
|
+
if (!r || r.error) {
|
|
650
|
+
askBox.hidden = grantBox.hidden = true;
|
|
651
|
+
hint.textContent = r?.error ? `读不到授权名单:${r.error}(读不到一律按拒绝处理)` : "";
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
const asks = r.asks || [];
|
|
656
|
+
askBox.hidden = !asks.length;
|
|
657
|
+
for (const a of asks) {
|
|
658
|
+
const row = cgRow();
|
|
659
|
+
const top = document.createElement("div");
|
|
660
|
+
top.className = "cg-dom";
|
|
661
|
+
const d = document.createElement("span");
|
|
662
|
+
d.className = "d";
|
|
663
|
+
d.textContent = a.domain;
|
|
664
|
+
d.title = a.domain;
|
|
665
|
+
const n = document.createElement("span");
|
|
666
|
+
n.className = "n";
|
|
667
|
+
n.textContent = `${a.n} 条 cookie`;
|
|
668
|
+
top.append(d, n);
|
|
669
|
+
if (a.sensitive) {
|
|
670
|
+
const tag = document.createElement("span");
|
|
671
|
+
tag.className = "cg-tag";
|
|
672
|
+
tag.textContent = "敏感";
|
|
673
|
+
tag.title = "银行 / 支付 / 券商这类域只给一次性授权,不进长期名单——下次还要再点一次。";
|
|
674
|
+
top.append(tag);
|
|
675
|
+
}
|
|
676
|
+
row.append(top);
|
|
677
|
+
const who = [a.agent, a.label].filter(Boolean).join(" · ");
|
|
678
|
+
if (who) {
|
|
679
|
+
const w = document.createElement("div");
|
|
680
|
+
w.className = "cg-who";
|
|
681
|
+
w.textContent = who;
|
|
682
|
+
w.title = who;
|
|
683
|
+
row.append(w);
|
|
684
|
+
}
|
|
685
|
+
const acts = document.createElement("div");
|
|
686
|
+
acts.className = "cg-acts";
|
|
687
|
+
if (!a.sensitive) {
|
|
688
|
+
acts.append(
|
|
689
|
+
cgBtn("允许", "ok", `以后这个 agent 导出 ${a.domain} 的 cookie 不再问你(30 天后失效,随时可以在下面撤销)`, () =>
|
|
690
|
+
cgSend("allow", a.domain)
|
|
691
|
+
)
|
|
692
|
+
);
|
|
693
|
+
}
|
|
694
|
+
acts.append(
|
|
695
|
+
cgBtn("只这一次", a.sensitive ? "ok" : "", "只放行接下来这一次导出,用掉即失效(5 分钟内没用也失效)", () =>
|
|
696
|
+
cgSend("once", a.domain)
|
|
697
|
+
),
|
|
698
|
+
cgBtn("拒绝", "", "把这条待授权划掉。agent 那边已经被拒过了,这只是清掉这条记录", () => cgSend("deny", a.domain))
|
|
699
|
+
);
|
|
700
|
+
row.append(acts);
|
|
701
|
+
askBox.append(row);
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
const grants = [...(r.grants || []), ...(r.onceGrants || [])];
|
|
705
|
+
grantBox.hidden = !grants.length;
|
|
706
|
+
for (const g of grants) {
|
|
707
|
+
const row = cgRow("granted");
|
|
708
|
+
const d = document.createElement("span");
|
|
709
|
+
d.className = "d";
|
|
710
|
+
d.textContent = g.domain;
|
|
711
|
+
d.title = g.domain;
|
|
712
|
+
row.append(d);
|
|
713
|
+
if (g.once) {
|
|
714
|
+
const tag = document.createElement("span");
|
|
715
|
+
tag.className = "cg-tag";
|
|
716
|
+
tag.textContent = "一次性";
|
|
717
|
+
tag.title = "只够用一次,用掉或 5 分钟后自动失效";
|
|
718
|
+
row.append(tag);
|
|
719
|
+
}
|
|
720
|
+
row.append(cgBtn("撤销", "rel-btn", `以后再导出 ${g.domain} 的 cookie 要重新问你`, () => cgSend("revoke", g.domain)));
|
|
721
|
+
grantBox.append(row);
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
hint.textContent = asks.length
|
|
725
|
+
? "有 agent 在申请借用你的登录态。允许之后让它原样重跑那一次调用即可。"
|
|
726
|
+
: grants.length
|
|
727
|
+
? "已授权的域,agent 导出它们的 cookie 时不再问你。授权 30 天后自动失效。"
|
|
728
|
+
: "agent 导出 cookie 明文(等于可直接冒用的登录态)默认被拒;它申请哪个域,这里就出现哪个域。";
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
function cgSend(action, domain) {
|
|
732
|
+
chrome.runtime.sendMessage({ type: "popup-cookie-gate", action, domain }, (r) => {
|
|
733
|
+
if (chrome.runtime.lastError) return cgShow({ error: chrome.runtime.lastError.message });
|
|
734
|
+
cgShow(r);
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
cgSend(null);
|
|
738
|
+
setInterval(() => cgSend(null), 2000);
|
|
739
|
+
|
|
740
|
+
refresh();
|
|
741
|
+
setInterval(refresh, 1500);
|