dsh-chrome-use 0.17.2 → 0.18.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/CHANGELOG.md +28 -0
- package/PRIVACY.md +1 -1
- package/README.md +48 -0
- package/extension/background.js +48 -13
- package/extension/host.js +89 -0
- package/extension/manifest.json +2 -2
- package/extension/popup-state.js +8 -2
- package/extension/popup.css +6 -0
- package/extension/popup.html +6 -0
- package/extension/popup.js +17 -2
- package/package.json +1 -1
- package/src/bridge-options.js +16 -0
- package/src/bridge.js +18 -3
- package/src/client.js +1 -1
- package/src/index.js +2 -7
- package/src/skill.js +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# 更新日志
|
|
2
2
|
|
|
3
|
+
## [0.18.0] - 2026-11-28
|
|
4
|
+
|
|
5
|
+
### 新增
|
|
6
|
+
|
|
7
|
+
- 「进阶:服务器地址」:Chrome 和 Harness 不在同一台机器上时(例如 Chrome 跑在局域网另一台机器的远程桌面或容器里),可以在扩展弹窗里填 Harness 所在机器的内网 IP,不用再手改源码。默认仍是本机 `127.0.0.1`,地址留空就等于默认。
|
|
8
|
+
- Harness 侧新增 `DSH_CHROME_USE_BIND_HOST`,默认只监听 `127.0.0.1`;设成内网 IP 才会在该地址上监听,并要求同时显式设置 `DSH_CHROME_USE_PORT`,因为自动选端口只在回环上探测。
|
|
9
|
+
- 扩展弹窗的替代入口:一个 Chrome 配置同时只连一个服务器地址,多台机器用多个配置或 SSH 隧道。
|
|
10
|
+
|
|
11
|
+
### 安全
|
|
12
|
+
|
|
13
|
+
- 服务器地址只接受环回和内网地址:`127.0.0.0/8`、`10.0.0.0/8`、`172.16.0.0/12`、`192.168.0.0/16`、`169.254.0.0/16`、`::1`、`fc00::/7`、`fe80::/10`;域名和公网 IP 直接拒绝,因为域名可以解析到任何地方,而这个设置决定页面内容发往哪里。
|
|
14
|
+
- 拒绝带前导零的 IPv4 写法。浏览器的 URL 解析器把 `010.0.0.1` 按八进制读成 `8.0.0.1`,只按十进制校验会让「只允许内网」的承诺失效;现在 `010.0.0.1`、`192.168.1.020`、`10.0.0.08` 都会被明确拒绝并提示改成十进制写法。
|
|
15
|
+
- 每个已保存的端口记着自己配对的那台机器,令牌只会发回给发出它的地址:换了服务器地址必须重新配对,重连和弹窗里「连接」都拨回原地址,不会把 A 机器的令牌发到 B 机器。
|
|
16
|
+
- 改地址是事务式的:先握手,成功后保存新地址;失败、地址写错或目标机没开,旧令牌、旧连接和留言游标都保持原样,不会因为一次笔误丢掉配对。
|
|
17
|
+
- IPv6 地址按 URL 解析器的规范形式校验和比较,`fd00::zz`、`fe80:`、带网卡后缀的写法会被拒绝,`fe80:0:0:0:0:0:0:1` 与 `fe80::1` 视为同一台机器。
|
|
18
|
+
- 桥的 `Host` 校验跟着绑定地址走:监听回环时同时接受 `127.0.0.1`、`localhost`、`[::1]` 三种写法,监听内网地址时只接受该地址。
|
|
19
|
+
- 扩展 CSP 的 `connect-src` 从 `ws://127.0.0.1:*` 放宽为 `ws:`,因为 CSP 无法表达网段;地址范围由弹窗校验和 Harness 侧绑定地址共同限制,默认行为不变。
|
|
20
|
+
|
|
21
|
+
### 其它
|
|
22
|
+
|
|
23
|
+
- 弹窗里没有名字的远端连接也会显示 `host:port`,不再和本机连接长得一样。
|
|
24
|
+
- 独立 JSON 运行器(`scripts/dev.mjs`)改用和插件相同的一套环境变量解析,`DSH_CHROME_USE_BIND_HOST` 在那里同样生效;`bridge.status()` 增加 `bindHost` 字段,远端场景下可以自查监听地址。
|
|
25
|
+
|
|
26
|
+
### 文档
|
|
27
|
+
|
|
28
|
+
- README 中英文各加一节「跨机器连接(进阶可选项,只允许内网)」,包含 `DSH_CHROME_USE_BIND_HOST` 用法、限制和 SSH 隧道建议。
|
|
29
|
+
- PRIVACY.md 说明可选的服务器地址以及页面内容会发往该地址。
|
|
30
|
+
|
|
3
31
|
## [0.17.2] - 2026-11-27
|
|
4
32
|
|
|
5
33
|
### 修复
|
package/PRIVACY.md
CHANGED
|
@@ -12,7 +12,7 @@ dsh-chrome-use 用于让你配置的 DeepSeek Harness 操作本机 Chrome。扩
|
|
|
12
12
|
|
|
13
13
|
## 数据流向
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
扩展默认只连接本机 `127.0.0.1` 的实际监听端口。未显式指定时,插件会从 18791、18793..18799 中自动选择并记住上次成功的端口;设置 `DSH_CHROME_USE_PORT` 时严格使用该端口。用户也可以打开弹窗的「进阶:服务器地址」,改连同一内网内的另一台机器;此时只接受环回和内网地址(域名和公网 IP 会被拒绝),页面内容会以明文 WebSocket 发往该地址。连接使用一次性配对码和后续配对令牌验证。插件不把页面内容发送给作者的服务器,也不内置统计或广告服务。
|
|
16
16
|
|
|
17
17
|
工具返回的页面文字、标题、URL、截图路径和调试信息会进入 Harness 会话。Harness 可能将这些内容发送给你选择的模型提供方。截图由其他图像工具读取后,也可能发送给模型提供方。模型服务和 Harness 自身的数据处理方式由它们各自的设置与政策决定。
|
|
18
18
|
|
package/README.md
CHANGED
|
@@ -90,6 +90,30 @@ DSH_CHROME_USE_PORT=18793 DSH_CHROME_USE_NAME=Codex dsh
|
|
|
90
90
|
|
|
91
91
|
不过扩展本身不挑 Harness:任何能连上 bridge 的客户端,都能操作同一个 Chrome。Codex、OpenCode、Workbody 这类 Harness 用独立 JSON 运行器启动同一个 bridge 即可,配对、端口、标签页租约和留言规则都和 DeepSeek Harness 一样,多个 Harness 还能同时连。具体步骤见 [独立 JSON 运行器](docs/standalone-runner.md)。
|
|
92
92
|
|
|
93
|
+
### 7. 跨机器连接(进阶可选项,只允许内网)
|
|
94
|
+
|
|
95
|
+
默认行为不变:扩展只连本机的 `127.0.0.1`。只有 Chrome 和 Harness 不在同一台机器上时(例如 Chrome 跑在局域网里另一台机器的远程桌面或容器里),才需要这一节。
|
|
96
|
+
|
|
97
|
+
Harness 侧要同时给端口和绑定地址,因为自动选端口只在 `127.0.0.1` 上探测:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
DSH_CHROME_USE_PORT=18791 DSH_CHROME_USE_BIND_HOST=192.168.1.20 dsh web
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
扩展侧:打开扩展弹窗 → 「进阶:服务器地址」→ 填同一个内网 IP → 重新粘贴配对码连接。地址留空就是默认的 `127.0.0.1`。
|
|
104
|
+
|
|
105
|
+
限制:
|
|
106
|
+
|
|
107
|
+
- 只接受环回和内网地址:`127.0.0.0/8`、`10.0.0.0/8`、`172.16.0.0/12`、`192.168.0.0/16`、`169.254.0.0/16`、`::1`、`fc00::/7`、`fe80::/10`。域名和公网 IP 会被拒绝,因为域名可以解析到任何地方,而这个设置决定页面内容发往哪里。
|
|
108
|
+
- 连接是明文 WebSocket:页面正文、截图和调试信息都会发到那台机器。只在信任的内网里用,不要把端口暴露到公网。
|
|
109
|
+
- 一个 Chrome 配置同时只填一个服务器地址;要连两台机器,用两个 Chrome 配置,或让其中一台走 SSH 隧道。
|
|
110
|
+
|
|
111
|
+
公网服务器更安全的做法是用 SSH 隧道,把远端的桥映射到本机回环,扩展地址保持 `127.0.0.1` 不变:
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
ssh -L 18791:127.0.0.1:18791 user@server
|
|
115
|
+
```
|
|
116
|
+
|
|
93
117
|
---
|
|
94
118
|
|
|
95
119
|
# dsh-chrome-use
|
|
@@ -183,3 +207,27 @@ Harnesses can also leave each other messages in the background: `chrome_send_mes
|
|
|
183
207
|
This package is a DSH/Cordis plugin. `package.json` has no MCP entry point and no command-line entry point; dropping the npm package into Codex or OpenCode will not make `chrome_*` tools appear.
|
|
184
208
|
|
|
185
209
|
The extension itself does not care which harness is on the other end: any client that can reach the bridge can drive the same Chrome. Harnesses such as Codex, OpenCode and Workbody start the same bridge with the standalone JSON runner, and get the same pairing, ports, tab leases and messaging rules as DeepSeek Harness; several harnesses can stay connected at once. See [Standalone JSON runner](docs/standalone-runner.md).
|
|
210
|
+
|
|
211
|
+
### 7. Connecting across machines (optional, private networks only)
|
|
212
|
+
|
|
213
|
+
The default does not change: the extension dials `127.0.0.1`. This section is only for the case where Chrome and the Harness run on different machines, for example Chrome inside a remote desktop or container on the LAN.
|
|
214
|
+
|
|
215
|
+
The Harness side needs an explicit port as well as the bind address, because automatic port selection only probes `127.0.0.1`:
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
DSH_CHROME_USE_PORT=18791 DSH_CHROME_USE_BIND_HOST=192.168.1.20 dsh web
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
In the extension: open the popup, expand "进阶:服务器地址" (advanced: server address), fill in the same private IP, paste the pairing code again and connect. Leave it empty for the `127.0.0.1` default.
|
|
222
|
+
|
|
223
|
+
Limits:
|
|
224
|
+
|
|
225
|
+
- Only loopback and private addresses are accepted: `127.0.0.0/8`, `10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`, `169.254.0.0/16`, `::1`, `fc00::/7`, `fe80::/10`. Hostnames and public IPs are refused, because a hostname can resolve anywhere and this setting decides where page content travels.
|
|
226
|
+
- The connection is plain WebSocket, so page text, screenshots and debug information go to that machine in clear text. Use it only on a network you trust, and never expose the port to the internet.
|
|
227
|
+
- One Chrome profile holds one server address. To reach two machines, use two profiles, or keep one of them behind an SSH tunnel.
|
|
228
|
+
|
|
229
|
+
For a server on the public internet, prefer an SSH tunnel that maps the remote bridge onto your own loopback and leave the extension address at `127.0.0.1`:
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
ssh -L 18791:127.0.0.1:18791 user@server
|
|
233
|
+
```
|
package/extension/background.js
CHANGED
|
@@ -3,6 +3,7 @@ import { createIdleTabs, IDLE_ALARM, IDLE_CHECK_MINUTES, IDLE_CLOSE_SECONDS, MAX
|
|
|
3
3
|
import { TabLeases } from './leases.js';
|
|
4
4
|
import { PORT, MAX_MESSAGE, PARALLEL_TABS, MESSAGE_UNREAD_MAX, validateArgs } from './protocol.js';
|
|
5
5
|
import { classifyPairingCode } from './pairing-code.js';
|
|
6
|
+
import { DEFAULT_HOST, bridgeUrl, normalizeServerHost } from './host.js';
|
|
6
7
|
import { classifyFailure } from './failures.js';
|
|
7
8
|
import { TAB_REFERENCE_MENU_ID, copyTabReference, createTabReferenceMenu } from './tab-reference.js';
|
|
8
9
|
|
|
@@ -139,7 +140,14 @@ function validConnections(value) {
|
|
|
139
140
|
if (!item || !isPort(item.port) || !isToken(item.token) || seen.has(item.port)) continue;
|
|
140
141
|
seen.add(item.port);
|
|
141
142
|
const name = cleanName(item.name);
|
|
142
|
-
|
|
143
|
+
// A stored host that no longer validates is dropped rather than relabelled
|
|
144
|
+
// loopback: dialling a token to some other address is exactly what this
|
|
145
|
+
// record exists to prevent, so the entry must be paired again.
|
|
146
|
+
let host = DEFAULT_HOST;
|
|
147
|
+
if (item.host !== undefined) {
|
|
148
|
+
try { host = normalizeServerHost(item.host); } catch { continue; }
|
|
149
|
+
}
|
|
150
|
+
connections.push({ port: item.port, token: item.token, host, ...(name ? { name } : {}) });
|
|
143
151
|
}
|
|
144
152
|
return connections.sort((a, b) => a.port - b.port);
|
|
145
153
|
}
|
|
@@ -245,18 +253,20 @@ function createClient(port) {
|
|
|
245
253
|
};
|
|
246
254
|
}
|
|
247
255
|
|
|
248
|
-
async function saveToken(client, port, token, name) {
|
|
256
|
+
async function saveToken(client, port, token, name, host = DEFAULT_HOST) {
|
|
249
257
|
return mutateStorage(async () => {
|
|
250
258
|
if (!isCurrent(client)) return false;
|
|
251
259
|
const stored = await readStored();
|
|
252
260
|
const connections = validConnections(stored.connections);
|
|
253
261
|
const existing = connections.find(item => item.port === port);
|
|
254
262
|
if (!existing && connections.length >= MAX_CONNECTIONS) throw new Error(`TOO_MANY_CONNECTIONS: forget a saved Harness before pairing another (maximum ${MAX_CONNECTIONS})`);
|
|
255
|
-
|
|
263
|
+
// A token belongs to one machine: pairing with a different host is a fresh
|
|
264
|
+
// pairing, so the message cursor starts over instead of reusing the old one.
|
|
265
|
+
client.persist.wasSaved = Boolean(existing) && existing.host === host;
|
|
256
266
|
if (!isCurrent(client)) return false;
|
|
257
267
|
const keptName = cleanName(name) ?? existing?.name;
|
|
258
268
|
const next = connections.filter(item => item.port !== port)
|
|
259
|
-
.concat({ port, token, ...(keptName ? { name: keptName } : {}) })
|
|
269
|
+
.concat({ port, token, host, ...(keptName ? { name: keptName } : {}) })
|
|
260
270
|
.sort((a, b) => a.port - b.port);
|
|
261
271
|
await chrome.storage.local.set({ connections: next, enabled: true });
|
|
262
272
|
await chrome.storage.local.remove('token');
|
|
@@ -479,16 +489,30 @@ function retireClient(client) {
|
|
|
479
489
|
return drainClient(client);
|
|
480
490
|
}
|
|
481
491
|
|
|
482
|
-
async function
|
|
492
|
+
async function storedHost() {
|
|
493
|
+
try {
|
|
494
|
+
return normalizeServerHost((await chrome.storage.local.get('serverHost')).serverHost);
|
|
495
|
+
} catch {
|
|
496
|
+
return DEFAULT_HOST;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
async function startClient(client, { code, restoreEpoch, host: requestedHost } = {}) {
|
|
483
501
|
const port = client.port;
|
|
502
|
+
const storedConnections = (await savedConnections()).connections;
|
|
503
|
+
const known = storedConnections.find(item => item.port === port);
|
|
504
|
+
// Prefer the address this port was paired with. A token is only ever sent to
|
|
505
|
+
// the machine that issued it.
|
|
506
|
+
const host = requestedHost ? normalizeServerHost(requestedHost) : known?.host ?? await storedHost();
|
|
484
507
|
const staleRestore = () => restoreEpoch !== undefined && restoreEpoch !== lifecycleEpoch;
|
|
485
508
|
if (staleRestore()) throw new Error(`COMMAND_CANCELED: restore for port ${port} was canceled`);
|
|
486
509
|
if (!code && forgottenPorts.has(port)) throw new Error(`COMMAND_CANCELED: port ${port} was forgotten`);
|
|
487
|
-
const
|
|
510
|
+
const connections = storedConnections;
|
|
488
511
|
if (staleRestore() || client.revoked) throw new Error(`COMMAND_CANCELED: connection to port ${port} was canceled`);
|
|
489
512
|
if (!code && forgottenPorts.has(port)) throw new Error(`COMMAND_CANCELED: port ${port} was forgotten`);
|
|
490
|
-
const saved =
|
|
513
|
+
const saved = known;
|
|
491
514
|
if (!code && !saved) throw new Error(`No saved pairing for port ${port}. Enter the 8-digit code from Harness.`);
|
|
515
|
+
if (!code && saved && saved.host !== host) throw new Error(`PAIRING_REQUIRED: ${host}:${port} is a different machine from ${saved.host}:${port}; enter its pairing code.`);
|
|
492
516
|
if (!saved) {
|
|
493
517
|
if (connections.length + pairingInFlight.size >= MAX_CONNECTIONS) throw new Error(`TOO_MANY_CONNECTIONS: forget a saved Harness before pairing another (maximum ${MAX_CONNECTIONS})`);
|
|
494
518
|
pairingInFlight.add(port);
|
|
@@ -498,8 +522,9 @@ async function startClient(client, { code, restoreEpoch } = {}) {
|
|
|
498
522
|
|
|
499
523
|
let socket;
|
|
500
524
|
try {
|
|
501
|
-
socket = new WebSocket(
|
|
525
|
+
socket = new WebSocket(bridgeUrl(host, port));
|
|
502
526
|
client.socket = socket;
|
|
527
|
+
client.host = host;
|
|
503
528
|
return await new Promise((resolve, reject) => {
|
|
504
529
|
let done = false;
|
|
505
530
|
let timer;
|
|
@@ -513,7 +538,7 @@ async function startClient(client, { code, restoreEpoch } = {}) {
|
|
|
513
538
|
finish(reject, error instanceof Error ? error : new Error(String(error)));
|
|
514
539
|
try { socket.close(); } catch {}
|
|
515
540
|
};
|
|
516
|
-
timer = setTimeout(() => fail(new Error(`Connection to
|
|
541
|
+
timer = setTimeout(() => fail(new Error(`Connection to ${host}:${port} timed out. Check that a Harness bridge is listening there.`)), 6000);
|
|
517
542
|
client.abortStart = () => fail(new Error(`COMMAND_CANCELED: connection to port ${port} was canceled`));
|
|
518
543
|
socket.onopen = () => {
|
|
519
544
|
if (!isCurrent(client, socket)) return;
|
|
@@ -527,7 +552,7 @@ async function startClient(client, { code, restoreEpoch } = {}) {
|
|
|
527
552
|
if (message.type === 'ready') {
|
|
528
553
|
if (message.protocol !== 1 || !isToken(message.token)) throw new Error('Unsupported bridge protocol');
|
|
529
554
|
const name = cleanName(message.name);
|
|
530
|
-
const persisted = await saveToken(client, port, message.token, name);
|
|
555
|
+
const persisted = await saveToken(client, port, message.token, name, host);
|
|
531
556
|
if (!persisted || !isCurrent(client, socket)) {
|
|
532
557
|
fail(new Error(`COMMAND_CANCELED: connection to port ${port} was canceled`));
|
|
533
558
|
return;
|
|
@@ -596,7 +621,12 @@ function connectPort(port, options = {}) {
|
|
|
596
621
|
beginIntent(port);
|
|
597
622
|
}
|
|
598
623
|
const existing = clients.get(port);
|
|
599
|
-
if (existing?.connected)
|
|
624
|
+
if (existing?.connected) {
|
|
625
|
+
// Same host: keep the live socket. A different host needs a new dial, and the
|
|
626
|
+
// old token must not be replayed to the new machine.
|
|
627
|
+
if (!options.host || options.host === existing.host) return Promise.resolve(existing);
|
|
628
|
+
return retireClient(existing).catch(() => {}).then(() => connectPort(port, options));
|
|
629
|
+
}
|
|
600
630
|
if (existing?.ready) return existing.ready;
|
|
601
631
|
if (existing) retireClient(existing).catch(() => {});
|
|
602
632
|
const client = createClient(port);
|
|
@@ -1037,7 +1067,12 @@ chrome.runtime.onMessage.addListener((message, sender, respond) => {
|
|
|
1037
1067
|
} else {
|
|
1038
1068
|
port = suppliedPort ?? PORT;
|
|
1039
1069
|
}
|
|
1040
|
-
|
|
1070
|
+
const host = message.host === undefined ? undefined : normalizeServerHost(message.host);
|
|
1071
|
+
await connectPort(port, { ...(code ? { code } : {}), ...(host === undefined ? {} : { host }) });
|
|
1072
|
+
// Persist only after the handshake succeeded: a typo must not replace the
|
|
1073
|
+
// address that reconnect uses. A token is stored with its own host, so a
|
|
1074
|
+
// failure here leaves the previous pairing intact.
|
|
1075
|
+
if (host !== undefined) await chrome.storage.local.set({ serverHost: host });
|
|
1041
1076
|
} else if (message.action === 'disconnect') await disconnectAll();
|
|
1042
1077
|
else if (message.action === 'forget') await forgetConnection(popupPort(message.port));
|
|
1043
1078
|
else if (message.action !== 'status') throw new Error('Unknown action');
|
|
@@ -1050,7 +1085,7 @@ chrome.runtime.onMessage.addListener((message, sender, respond) => {
|
|
|
1050
1085
|
reconnecting: auto && !connected,
|
|
1051
1086
|
connections: connections.map(item => {
|
|
1052
1087
|
const client = clients.get(item.port);
|
|
1053
|
-
return { port: item.port, name: client?.name ?? item.name ?? null, connected: Boolean(client?.connected), version: client?.version ?? null, error: client?.lastError || portErrors.get(item.port) || '' };
|
|
1088
|
+
return { port: item.port, host: client?.host ?? item.host ?? null, name: client?.name ?? item.name ?? null, connected: Boolean(client?.connected), version: client?.version ?? null, error: client?.lastError || portErrors.get(item.port) || '' };
|
|
1054
1089
|
}),
|
|
1055
1090
|
enabled: auto,
|
|
1056
1091
|
error: lastError,
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Where the extension may connect. The default stays loopback; the opt-in
|
|
2
|
+
// advanced setting accepts loopback and private addresses only. A hostname is
|
|
3
|
+
// rejected on purpose: it can resolve to anything, and this value decides where
|
|
4
|
+
// page content, screenshots and cookies travel.
|
|
5
|
+
export const DEFAULT_HOST = '127.0.0.1';
|
|
6
|
+
|
|
7
|
+
const IPV4 = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
|
|
8
|
+
|
|
9
|
+
function ipv4Octets(text) {
|
|
10
|
+
const match = IPV4.exec(text);
|
|
11
|
+
if (!match) return undefined;
|
|
12
|
+
// Chrome's URL parser reads a leading zero as octal, so "010.0.0.1" dials
|
|
13
|
+
// 8.0.0.1. Refuse those spellings instead of guessing which base was meant.
|
|
14
|
+
if (match.slice(1).some(part => part.length > 1 && part.startsWith('0'))) return undefined;
|
|
15
|
+
const octets = match.slice(1).map(Number);
|
|
16
|
+
return octets.every(octet => octet <= 255) ? octets : undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function ipv4Allowed([a, b]) {
|
|
20
|
+
if (a === 127) return true; // loopback
|
|
21
|
+
if (a === 10) return true;
|
|
22
|
+
if (a === 172 && b >= 16 && b <= 31) return true;
|
|
23
|
+
if (a === 192 && b === 168) return true;
|
|
24
|
+
if (a === 169 && b === 254) return true; // link-local
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Only the low 16 bits matter for the prefixes we allow, so parsing the text
|
|
29
|
+
// form is enough and avoids pulling in a full IPv6 parser.
|
|
30
|
+
function ipv6Allowed(lower) {
|
|
31
|
+
if (lower === '::1') return true;
|
|
32
|
+
const first = lower.split(':')[0];
|
|
33
|
+
if (!/^[0-9a-f]{1,4}$/.test(first)) return false;
|
|
34
|
+
const value = parseInt(first, 16);
|
|
35
|
+
if ((value & 0xfe00) === 0xfc00) return true; // fc00::/7 unique local
|
|
36
|
+
if ((value & 0xffc0) === 0xfe80) return true; // fe80::/10 link local
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Returns the canonical host to dial, or throws an Error with a readable
|
|
42
|
+
* message. Empty input means the default.
|
|
43
|
+
*/
|
|
44
|
+
export function normalizeServerHost(value) {
|
|
45
|
+
const text = String(value ?? '').trim();
|
|
46
|
+
if (!text) return DEFAULT_HOST;
|
|
47
|
+
if (text.toLowerCase() === 'localhost') return 'localhost';
|
|
48
|
+
// The popup has no port field, so a pasted "host:port" is a likely mistake.
|
|
49
|
+
if (text.includes(':') && text.includes('.') && !text.includes('::')) {
|
|
50
|
+
throw new Error('Enter only the host, without a port');
|
|
51
|
+
}
|
|
52
|
+
const unbracketed = text.startsWith('[') && text.endsWith(']') ? text.slice(1, -1) : text;
|
|
53
|
+
const shaped = IPV4.exec(unbracketed);
|
|
54
|
+
if (shaped && shaped.slice(1).some(part => part.length > 1 && part.startsWith('0'))) {
|
|
55
|
+
const canonical = shaped.slice(1).map(part => String(Number(part))).join('.');
|
|
56
|
+
throw new Error(`Leading zeros are not allowed; write ${canonical} instead of ${unbracketed}`);
|
|
57
|
+
}
|
|
58
|
+
const octets = ipv4Octets(unbracketed);
|
|
59
|
+
if (octets) {
|
|
60
|
+
if (!ipv4Allowed(octets)) throw new Error(`${unbracketed} is not a loopback or private address`);
|
|
61
|
+
// Return the canonical dotted form: the validator and the browser must agree
|
|
62
|
+
// on which machine this is.
|
|
63
|
+
return octets.join('.');
|
|
64
|
+
}
|
|
65
|
+
const lower = unbracketed.toLowerCase();
|
|
66
|
+
if (lower.includes(':')) {
|
|
67
|
+
// Parse through the URL parser so a malformed address (fd00::zz, a zone id)
|
|
68
|
+
// is refused here rather than failing later as an unusable WebSocket URL.
|
|
69
|
+
let parsed = '';
|
|
70
|
+
try {
|
|
71
|
+
parsed = new URL(`ws://[${lower}]/`).hostname;
|
|
72
|
+
} catch {
|
|
73
|
+
throw new Error(`${unbracketed} is not a valid IPv6 address`);
|
|
74
|
+
}
|
|
75
|
+
// The parser returns the compressed lowercase form, so the same machine
|
|
76
|
+
// always compares equal to itself.
|
|
77
|
+
const canonical = parsed.startsWith('[') && parsed.endsWith(']') ? parsed.slice(1, -1) : parsed;
|
|
78
|
+
if (!ipv6Allowed(canonical)) throw new Error(`${unbracketed} is not a loopback or private IPv6 address`);
|
|
79
|
+
return canonical;
|
|
80
|
+
}
|
|
81
|
+
throw new Error(`Use 127.0.0.1, a private IP such as 192.168.1.20, or a private IPv6 address; hostnames are not accepted`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** WebSocket URL for a host and port, bracketing bare IPv6 addresses. */
|
|
85
|
+
export function bridgeUrl(host, port) {
|
|
86
|
+
const normalized = normalizeServerHost(host);
|
|
87
|
+
const address = normalized.includes(':') ? `[${normalized}]` : normalized;
|
|
88
|
+
return `ws://${address}:${port}/bridge`;
|
|
89
|
+
}
|
package/extension/manifest.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"manifest_version": 3,
|
|
3
3
|
"name": "dsh-chrome-use",
|
|
4
4
|
"description": "Let DeepSeek Harness control Chrome tabs, with several agent sessions working in parallel.",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.18.0",
|
|
6
6
|
"minimum_chrome_version": "120",
|
|
7
7
|
"permissions": [
|
|
8
8
|
"debugger",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
33
|
"content_security_policy": {
|
|
34
|
-
"extension_pages": "script-src 'self'; object-src 'none'; connect-src ws
|
|
34
|
+
"extension_pages": "script-src 'self'; object-src 'none'; connect-src ws:"
|
|
35
35
|
},
|
|
36
36
|
"icons": {
|
|
37
37
|
"16": "icon-16.png",
|
package/extension/popup-state.js
CHANGED
|
@@ -22,16 +22,22 @@ export function popupState({ connections = [], reconnecting = false } = {}) {
|
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export function connectionRow({ port, connected = false, version = null, name = null, error = '' } = {}) {
|
|
25
|
+
export function connectionRow({ port, host = null, connected = false, version = null, name = null, error = '' } = {}) {
|
|
26
26
|
const state = connected ? 'connected' : error ? 'error' : 'saved';
|
|
27
|
+
// A non-default host is the interesting part of the row: without it two
|
|
28
|
+
// connections on the same port look identical.
|
|
29
|
+
const remote = host && host !== '127.0.0.1' && host !== 'localhost';
|
|
30
|
+
const address = remote ? (host.includes(':') ? `[${host}]` : host) : null;
|
|
31
|
+
const endpoint = address ? `${address}:${port}` : String(port);
|
|
27
32
|
return {
|
|
28
33
|
port,
|
|
34
|
+
host: host || null,
|
|
29
35
|
name: name || null,
|
|
30
36
|
state,
|
|
31
37
|
connected: Boolean(connected),
|
|
32
38
|
// A harness may name itself when it connects; the port stays visible so the
|
|
33
39
|
// popup still tells the user exactly which bridge the row refers to.
|
|
34
|
-
title: name ? `${name} · ${
|
|
40
|
+
title: name ? `${name} · ${endpoint}` : address ? endpoint : `端口 ${port}`,
|
|
35
41
|
meta: connected
|
|
36
42
|
? `已连接${version ? ` · ${version}` : ''}`
|
|
37
43
|
: error
|
package/extension/popup.css
CHANGED
|
@@ -52,3 +52,9 @@ footer { padding: 12px 22px 18px; color: #657083; font-size: 11px; }
|
|
|
52
52
|
footer p { margin: 0; }
|
|
53
53
|
a { color: #185adb; }
|
|
54
54
|
[hidden] { display: none !important; }
|
|
55
|
+
|
|
56
|
+
/* Advanced server address stays collapsed so the default path looks unchanged. */
|
|
57
|
+
.advanced { margin: 10px 0 2px; }
|
|
58
|
+
.advanced summary { cursor: pointer; font-size: 13px; color: #33507a; }
|
|
59
|
+
.advanced > * + * { margin-top: 6px; }
|
|
60
|
+
.advanced input { letter-spacing: 0; }
|
package/extension/popup.html
CHANGED
|
@@ -15,6 +15,12 @@
|
|
|
15
15
|
<input id="code" aria-label="配对码" inputmode="text" autocapitalize="characters" autocomplete="off" spellcheck="false" maxlength="8" placeholder="粘贴 8 位配对码">
|
|
16
16
|
<button type="submit">连接</button>
|
|
17
17
|
</div>
|
|
18
|
+
<details class="advanced">
|
|
19
|
+
<summary>进阶:服务器地址</summary>
|
|
20
|
+
<label class="help" for="server-host">Harness 所在机器,默认 127.0.0.1。只接受环回或内网 IP(10/8、172.16/12、192.168/16、169.254/16、::1、fc00::/7、fe80::/10),不接受域名。改完请重新连接。</label>
|
|
21
|
+
<input id="server-host" aria-label="服务器地址" inputmode="text" autocapitalize="off" autocomplete="off" spellcheck="false" placeholder="127.0.0.1">
|
|
22
|
+
<p class="help">页面正文、截图和调试信息会以明文发到这台机器,所以这里只允许内网和环回地址。公网服务器请用 SSH 隧道映射到本机。</p>
|
|
23
|
+
</details>
|
|
18
24
|
<p id="error" role="alert"></p>
|
|
19
25
|
<p class="help pair-help"><a href="https://github.com/tao1020/dsh-chrome-use/blob/main/README.md#安装" target="_blank" rel="noreferrer">使用帮助(Help: install and pair)</a></p>
|
|
20
26
|
</form>
|
package/extension/popup.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { popupState } from './popup-state.js';
|
|
2
|
+
import { DEFAULT_HOST, normalizeServerHost } from './host.js';
|
|
2
3
|
import { IDLE_CLOSE_SECONDS, MAX_IDLE_CLOSE_SECONDS, IDLE_TIMEOUT_SETTING } from './idle-tabs.js';
|
|
3
4
|
|
|
4
5
|
const $ = id => document.getElementById(id);
|
|
@@ -41,7 +42,7 @@ function connectionItem(row) {
|
|
|
41
42
|
connect.type = 'button';
|
|
42
43
|
connect.className = 'link';
|
|
43
44
|
connect.textContent = '连接';
|
|
44
|
-
connect.addEventListener('click', () => act('connect', { port: row.port }));
|
|
45
|
+
connect.addEventListener('click', () => act('connect', { port: row.port, ...(row.host ? { host: row.host } : {}) }));
|
|
45
46
|
actions.append(connect);
|
|
46
47
|
}
|
|
47
48
|
if (row.canForget) {
|
|
@@ -125,9 +126,23 @@ chrome.storage.local.get('autoCloseIdleTabs').then(
|
|
|
125
126
|
() => {}, // Keep the default (idle cleanup off) when settings cannot be read.
|
|
126
127
|
);
|
|
127
128
|
idleClose.addEventListener('change', () => { chrome.storage.local.set({ autoCloseIdleTabs: idleClose.checked }); });
|
|
129
|
+
// Show the saved address so the popup always says which machine it dials.
|
|
130
|
+
chrome.storage.local.get('serverHost').then(
|
|
131
|
+
({ serverHost }) => { $('server-host').value = serverHost ?? ''; },
|
|
132
|
+
() => {}, // Keep the loopback placeholder when storage cannot be read.
|
|
133
|
+
);
|
|
128
134
|
$('pair-form').addEventListener('submit', async event => {
|
|
129
135
|
event.preventDefault();
|
|
130
|
-
|
|
136
|
+
let host;
|
|
137
|
+
try {
|
|
138
|
+
host = normalizeServerHost($('server-host').value);
|
|
139
|
+
} catch (error) {
|
|
140
|
+
$('error').textContent = error.message;
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
$('error').textContent = '';
|
|
144
|
+
$('server-host').value = host === DEFAULT_HOST ? '' : host;
|
|
145
|
+
const result = await act('connect', { code: $('code').value, host });
|
|
131
146
|
if (result) $('code').value = '';
|
|
132
147
|
});
|
|
133
148
|
$('disconnect').addEventListener('click', () => act('disconnect'));
|
package/package.json
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { normalizeServerHost } from '../extension/host.js';
|
|
2
|
+
import { parsePort } from '../extension/protocol.js';
|
|
3
|
+
|
|
4
|
+
// Environment contract for the bridge. Kept out of the plugin entry so the
|
|
5
|
+
// standalone runner can use the same rules without loading the Cordis plugin.
|
|
6
|
+
export function bridgeOptions(env, baseStateDir) {
|
|
7
|
+
const configured = env?.DSH_CHROME_USE_PORT?.trim();
|
|
8
|
+
const options = configured ? { port: parsePort(configured), baseStateDir } : { auto: true, baseStateDir };
|
|
9
|
+
const name = env?.DSH_CHROME_USE_NAME?.trim().slice(0, 40);
|
|
10
|
+
const bindHost = env?.DSH_CHROME_USE_BIND_HOST?.trim();
|
|
11
|
+
const withHost = bindHost ? { ...options, bindHost: normalizeServerHost(bindHost) } : options;
|
|
12
|
+
// Auto mode probes candidate ports on loopback, so it cannot describe a
|
|
13
|
+
// network address; require an explicit port instead of guessing.
|
|
14
|
+
if (bindHost && !configured) throw new Error('DSH_CHROME_USE_BIND_HOST needs DSH_CHROME_USE_PORT; automatic port selection only probes 127.0.0.1');
|
|
15
|
+
return name ? { ...withHost, name } : withHost;
|
|
16
|
+
}
|
package/src/bridge.js
CHANGED
|
@@ -6,6 +6,7 @@ import { WebSocketServer, WebSocket } from 'ws';
|
|
|
6
6
|
import { PORT, MAX_MESSAGE, DEADLINE_MS, PARALLEL_TABS, MESSAGE_UNREAD_MAX } from '../extension/protocol.js';
|
|
7
7
|
import { classifyPairingCode, generatePairingCode, normalizePairingCode } from '../extension/pairing-code.js';
|
|
8
8
|
import { candidatePorts, portStateDir, preferencePath, probePort, readPreferredPort, writePreferredPort } from './port-selector.js';
|
|
9
|
+
import { DEFAULT_HOST, normalizeServerHost } from '../extension/host.js';
|
|
9
10
|
|
|
10
11
|
const equal = (a, b) => typeof a === 'string' && typeof b === 'string' && a.length === b.length && timingSafeEqual(Buffer.from(a), Buffer.from(b));
|
|
11
12
|
const extensionOrigin = /^chrome-extension:\/\/[a-p]{32}$/;
|
|
@@ -36,11 +37,14 @@ function describeDetach({ reason, tabExists, closeSource }) {
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
export class Bridge {
|
|
39
|
-
constructor({ port = PORT, auto = false, portCandidates, baseStateDir, stateDir, name, probe = probePort, deadlineMs = DEADLINE_MS, claimWaitMs = CLAIM_WAIT_MS } = {}) {
|
|
40
|
+
constructor({ port = PORT, auto = false, portCandidates, baseStateDir, stateDir, name, bindHost = DEFAULT_HOST, probe = probePort, deadlineMs = DEADLINE_MS, claimWaitMs = CLAIM_WAIT_MS } = {}) {
|
|
40
41
|
// Optional label the agent side shows in the popup so the user can tell
|
|
41
42
|
// Harnesses apart; it is display-only and never used for routing.
|
|
42
43
|
this.name = normalizeName(name);
|
|
43
44
|
this.port = auto ? undefined : port;
|
|
45
|
+
// Loopback by default. A private address is opt-in through
|
|
46
|
+
// DSH_CHROME_USE_BIND_HOST so a plain install never listens on the network.
|
|
47
|
+
this.bindHost = normalizeServerHost(bindHost);
|
|
44
48
|
this.requestedPort = auto ? undefined : port;
|
|
45
49
|
this.auto = auto;
|
|
46
50
|
this.portCandidates = portCandidates;
|
|
@@ -112,8 +116,18 @@ export class Bridge {
|
|
|
112
116
|
http.headersTimeout = 5000;
|
|
113
117
|
const ws = new WebSocketServer({ noServer: true, maxPayload: MAX_MESSAGE, perMessageDeflate: false });
|
|
114
118
|
const boundPort = () => http.address()?.port ?? port;
|
|
119
|
+
// The extension dials bindHost, so its Host header carries that name. When
|
|
120
|
+
// listening on loopback also accept the other loopback spellings.
|
|
121
|
+
const hostsFor = () => {
|
|
122
|
+
const current = boundPort();
|
|
123
|
+
if (['127.0.0.1', 'localhost', '::1'].includes(this.bindHost)) {
|
|
124
|
+
return new Set([`127.0.0.1:${current}`, `localhost:${current}`, `[::1]:${current}`]);
|
|
125
|
+
}
|
|
126
|
+
const address = this.bindHost.includes(':') ? `[${this.bindHost}]` : this.bindHost;
|
|
127
|
+
return new Set([`${address}:${current}`]);
|
|
128
|
+
};
|
|
115
129
|
http.on('upgrade', (req, socket, head) => {
|
|
116
|
-
if (this.closed || req.url !== '/bridge' || req.headers.host
|
|
130
|
+
if (this.closed || req.url !== '/bridge' || !hostsFor().has(req.headers.host) || !extensionOrigin.test(req.headers.origin ?? '') || ws.clients.size >= 4) {
|
|
117
131
|
socket.end('HTTP/1.1 403 Forbidden\r\nConnection: close\r\n\r\n');
|
|
118
132
|
return;
|
|
119
133
|
}
|
|
@@ -121,7 +135,7 @@ export class Bridge {
|
|
|
121
135
|
});
|
|
122
136
|
await new Promise((resolve, reject) => {
|
|
123
137
|
http.once('error', reject);
|
|
124
|
-
http.listen(port,
|
|
138
|
+
http.listen(port, this.bindHost, () => {
|
|
125
139
|
http.off('error', reject);
|
|
126
140
|
resolve();
|
|
127
141
|
});
|
|
@@ -171,6 +185,7 @@ export class Bridge {
|
|
|
171
185
|
return {
|
|
172
186
|
connected: this.peer?.readyState === WebSocket.OPEN,
|
|
173
187
|
port: this.port,
|
|
188
|
+
bindHost: this.bindHost,
|
|
174
189
|
...(this.requestedPort !== undefined && this.requestedPort !== this.port ? { requestedPort: this.requestedPort } : {}),
|
|
175
190
|
extensionVersion: this.peer?.extensionVersion ?? null,
|
|
176
191
|
claimedTabs: [...this.claims.keys()],
|
package/src/client.js
CHANGED
|
@@ -179,7 +179,7 @@ async function checkRelease(current, fetcher = fetch) {
|
|
|
179
179
|
} finally { clearTimeout(timer); }
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
-
const packageVersion = "0.
|
|
182
|
+
const packageVersion = "0.18.0";
|
|
183
183
|
// Wrapped by scripts/build-client.mjs for the Harness browser module loader.
|
|
184
184
|
const React = require('react');
|
|
185
185
|
const { createElement: h, useState, useEffect, useRef } = React;
|
package/src/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { randomUUID } from 'node:crypto';
|
|
|
6
6
|
import { Bridge } from './bridge.js';
|
|
7
7
|
import { storeUrl } from './links.js';
|
|
8
8
|
import { registerChromeUseSkill } from './skill.js';
|
|
9
|
-
import { TOOLS, validateArgs
|
|
9
|
+
import { TOOLS, validateArgs } from '../extension/protocol.js';
|
|
10
10
|
import { failureFromError, formatFailure } from '../extension/failures.js';
|
|
11
11
|
import { buildIssueReport } from './report.js';
|
|
12
12
|
import { createKeepAwake } from './keep-awake.js';
|
|
@@ -18,12 +18,7 @@ const pluginVersion = createRequire(import.meta.url)('../package.json').version;
|
|
|
18
18
|
export const name = 'dsh-chrome-use';
|
|
19
19
|
export const inject = ['tools'];
|
|
20
20
|
|
|
21
|
-
export
|
|
22
|
-
const configured = env?.DSH_CHROME_USE_PORT?.trim();
|
|
23
|
-
const options = configured ? { port: parsePort(configured), baseStateDir } : { auto: true, baseStateDir };
|
|
24
|
-
const name = env?.DSH_CHROME_USE_NAME?.trim().slice(0, 40);
|
|
25
|
-
return name ? { ...options, name } : options;
|
|
26
|
-
}
|
|
21
|
+
export { bridgeOptions } from './bridge-options.js';
|
|
27
22
|
|
|
28
23
|
// Diagnostics stay available even in a narrowed deployment: without them a
|
|
29
24
|
// harness cannot explain why a tool is missing.
|
package/src/skill.js
CHANGED
|
@@ -23,6 +23,7 @@ export const CAPABILITIES = [
|
|
|
23
23
|
['多 Harness 留言', 'chrome_send_message 发送'],
|
|
24
24
|
['保持 Mac 唤醒', 'chrome_keep_awake'],
|
|
25
25
|
['失败后的结构化自愈指引', 'Failure: {...}'],
|
|
26
|
+
['进阶:跨机器连接(仅内网地址)', 'DSH_CHROME_USE_BIND_HOST'],
|
|
26
27
|
];
|
|
27
28
|
|
|
28
29
|
export const chromeUseSkill = {
|
|
@@ -53,6 +54,7 @@ ${CAPABILITIES.map(([label]) => `- ${label}`).join('\n')}
|
|
|
53
54
|
1. 先调用 chrome_status 检查连接。
|
|
54
55
|
2. 未连接时调用 chrome_pair 生成 8 位配对码(10 分钟内有效)。返回里有 pairingCode 时优先把 pairingCode 给用户;它已经包含端口,新扩展会自动识别,不要要求用户再填端口。没有 pairingCode 时使用纯数字 code(旧桥/旧扩展,只在 18791 可用)。让用户在 Chrome 工具栏打开 dsh-chrome-use 扩展,粘贴配对码并点击“连接”。扩展还没安装时,让用户到 Harness 设置 → dsh-chrome-use 点商店链接安装。不要要求用户重装或手动加载文件夹。
|
|
55
56
|
3. 配对成功后,重启 Harness、Chrome 或扩展自动更新都会自动重连。用户主动断开后,留空配对码点“连接”即可。
|
|
57
|
+
4. 默认只连本机 127.0.0.1。Chrome 和 Harness 不在同一台机器上时,Harness 侧要同时设置 DSH_CHROME_USE_PORT 和 DSH_CHROME_USE_BIND_HOST=<内网 IP>,用户在扩展弹窗的「进阶:服务器地址」填同一个 IP 再连接;只接受环回和内网地址,公网服务器让用户用 SSH 隧道把远端端口映射到本机,不要建议直接暴露端口。
|
|
56
58
|
|
|
57
59
|
## 与其他 Harness 留言
|
|
58
60
|
|