dsh-chrome-use 0.8.0 → 0.9.1
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 +20 -0
- package/README.md +5 -3
- package/docs/standalone-runner.md +1 -1
- package/extension/background.js +20 -8
- package/extension/manifest.json +1 -1
- package/extension/popup-state.js +11 -5
- package/extension/popup.css +15 -5
- package/extension/popup.html +4 -2
- package/extension/popup.js +55 -26
- package/package.json +1 -1
- package/src/bridge.js +10 -2
- package/src/client.js +1 -1
- package/src/index.js +3 -1
- package/src/port-selector.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,26 @@
|
|
|
3
3
|
版本号遵循语义化版本。格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/)。
|
|
4
4
|
扩展版本和 Harness 插件版本始终一起发布,数字保持一致。
|
|
5
5
|
|
|
6
|
+
## [0.9.1] - 2026-11-12
|
|
7
|
+
|
|
8
|
+
### 变更
|
|
9
|
+
|
|
10
|
+
- 弹窗把 Star 提示移到标题下方、分隔线上方,打开就能看到;底部只保留「本机连接 · 不上传到插件作者的服务器」。
|
|
11
|
+
|
|
12
|
+
## [0.9.0] - 2026-11-12
|
|
13
|
+
|
|
14
|
+
### 新增
|
|
15
|
+
|
|
16
|
+
- 扩展最多保存 10 个 Harness 连接(原来 4 个);自动端口扩展到 18791、18793..18801,仍然跳过 18792。
|
|
17
|
+
- 弹窗的每个连接改成独立圆角卡片,并带自己的边框和底色,条目之间不再连成一片。
|
|
18
|
+
- 连接失败的长错误不再直接铺在行里:状态行只显示「未连接」加一个红色「!」图标,悬停可看原因,点一下展开完整说明和「Harness 可能已离线或还没启动」的提示。
|
|
19
|
+
- 可以给 Harness 起显示名:启动时设置 `DSH_CHROME_USE_NAME`(例如 `Codex`),弹窗显示「Codex · 18793」;不设置就只显示端口。名字只用于显示,不影响路由。
|
|
20
|
+
- 连接列表超过一屏时可以滚动。
|
|
21
|
+
|
|
22
|
+
### 变更
|
|
23
|
+
|
|
24
|
+
- 弹窗标题改为「连接你的所有 Harness 与浏览器」。
|
|
25
|
+
|
|
6
26
|
## [0.8.0] - 2026-11-12
|
|
7
27
|
|
|
8
28
|
### 新增
|
package/README.md
CHANGED
|
@@ -50,17 +50,19 @@ dsh plugin --profile desktop add dsh-chrome-use
|
|
|
50
50
|
|
|
51
51
|
### 4. 多个 Harness 同时连接(可选)
|
|
52
52
|
|
|
53
|
-
不设置 `DSH_CHROME_USE_PORT` 时,插件自动选择端口:先试上次成功的端口(`~/.dsh/dsh-chrome-use/port.json`),再试 18791、18793..
|
|
53
|
+
不设置 `DSH_CHROME_USE_PORT` 时,插件自动选择端口:先试上次成功的端口(`~/.dsh/dsh-chrome-use/port.json`),再试 18791、18793..18801,跳过 18792。第一个可用端口生效,端口被占用不会让启动直接失败。设置页会显示实际端口。
|
|
54
54
|
|
|
55
55
|
设置 `DSH_CHROME_USE_PORT` 时严格使用该端口;端口被占用就报 `BRIDGE_START_FAILED`,不会自动换端口。脚本和测试建议显式设置。
|
|
56
56
|
|
|
57
57
|
```sh
|
|
58
|
-
DSH_CHROME_USE_PORT=18793 dsh
|
|
58
|
+
DSH_CHROME_USE_PORT=18793 DSH_CHROME_USE_NAME=Codex dsh
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
+
`DSH_CHROME_USE_NAME` 是可选的显示名:设置后扩展弹窗会把该端口显示成「Codex · 18793」,方便区分是哪个 Harness;不设置就只显示端口。名字只用于显示,不参与路由,也不会发给其他 Harness。
|
|
62
|
+
|
|
61
63
|
桌面版从图形界面启动时,可能读不到 shell 的环境变量。需要按桌面版的方式设置环境变量,或者从终端启动。
|
|
62
64
|
|
|
63
|
-
配对第二个 Harness 时,把新的 `pairingCode` 粘贴到扩展弹窗即可;它已经包含实际端口。扩展会分别保存每个端口的配对令牌,最多保存
|
|
65
|
+
配对第二个 Harness 时,把新的 `pairingCode` 粘贴到扩展弹窗即可;它已经包含实际端口。扩展会分别保存每个端口的配对令牌,最多保存 10 个。如果实际端口发生变化,旧令牌会失效,需要用新的配对码重新配对。纯数字旧版兼容码仍只用于 18791。
|
|
64
66
|
|
|
65
67
|
端口 18792 留给 `scripts/fixture.mjs` 测试页。自动选择会跳过它。
|
|
66
68
|
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
DSH_CHROME_USE_PORT=18793 node scripts/dev.mjs
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
未设置 `DSH_CHROME_USE_PORT` 时,运行器先试上次成功的端口,再试 18791、18793..
|
|
21
|
+
未设置 `DSH_CHROME_USE_PORT` 时,运行器先试上次成功的端口,再试 18791、18793..18801,并跳过 18792;设置时严格使用指定端口。端口 18792 留给 `scripts/fixture.mjs` 测试页,不要用于 bridge。
|
|
22
22
|
|
|
23
23
|
进程会一直运行,等待标准输入。首次使用先配对:
|
|
24
24
|
|
package/extension/background.js
CHANGED
|
@@ -7,7 +7,7 @@ import { classifyPairingCode } from './pairing-code.js';
|
|
|
7
7
|
// keeps its own socket, pairing token, command map and cleanup generation. The
|
|
8
8
|
// only shared authority is the lease table below: it decides which connection
|
|
9
9
|
// may touch a tab. Bridge-local chat claims stay unchanged.
|
|
10
|
-
const MAX_CONNECTIONS =
|
|
10
|
+
const MAX_CONNECTIONS = 10;
|
|
11
11
|
// Cross-Harness messages are stored here so a reconnect, or an MV3 worker
|
|
12
12
|
// restart, does not lose them. They are data from other agents, never user
|
|
13
13
|
// instructions; the bridge only surfaces a count until a tool reads the text.
|
|
@@ -93,6 +93,11 @@ function mutateStorage(operation) {
|
|
|
93
93
|
storageQueue = run.then(() => {}, () => {});
|
|
94
94
|
return run;
|
|
95
95
|
}
|
|
96
|
+
function cleanName(value) {
|
|
97
|
+
if (typeof value !== 'string') return undefined;
|
|
98
|
+
const name = value.replace(/[\u0000-\u001F\u007F]/g, ' ').trim().slice(0, 40);
|
|
99
|
+
return name || undefined;
|
|
100
|
+
}
|
|
96
101
|
function validConnections(value) {
|
|
97
102
|
const list = Array.isArray(value) ? value : [];
|
|
98
103
|
const seen = new Set();
|
|
@@ -100,7 +105,8 @@ function validConnections(value) {
|
|
|
100
105
|
for (const item of list) {
|
|
101
106
|
if (!item || !isPort(item.port) || !isToken(item.token) || seen.has(item.port)) continue;
|
|
102
107
|
seen.add(item.port);
|
|
103
|
-
|
|
108
|
+
const name = cleanName(item.name);
|
|
109
|
+
connections.push({ port: item.port, token: item.token, ...(name ? { name } : {}) });
|
|
104
110
|
}
|
|
105
111
|
return connections.sort((a, b) => a.port - b.port);
|
|
106
112
|
}
|
|
@@ -193,6 +199,7 @@ function createClient(port) {
|
|
|
193
199
|
connected: false,
|
|
194
200
|
ready: undefined,
|
|
195
201
|
version: null,
|
|
202
|
+
name: null,
|
|
196
203
|
lastError: '',
|
|
197
204
|
tasks: new Map(),
|
|
198
205
|
drain: undefined,
|
|
@@ -204,16 +211,19 @@ function createClient(port) {
|
|
|
204
211
|
};
|
|
205
212
|
}
|
|
206
213
|
|
|
207
|
-
async function saveToken(client, port, token) {
|
|
214
|
+
async function saveToken(client, port, token, name) {
|
|
208
215
|
return mutateStorage(async () => {
|
|
209
216
|
if (!isCurrent(client)) return false;
|
|
210
217
|
const stored = await readStored();
|
|
211
218
|
const connections = validConnections(stored.connections);
|
|
212
219
|
const existing = connections.find(item => item.port === port);
|
|
213
|
-
if (!existing && connections.length >= MAX_CONNECTIONS) throw new Error(`TOO_MANY_CONNECTIONS: forget a saved Harness before pairing
|
|
220
|
+
if (!existing && connections.length >= MAX_CONNECTIONS) throw new Error(`TOO_MANY_CONNECTIONS: forget a saved Harness before pairing another (maximum ${MAX_CONNECTIONS})`);
|
|
214
221
|
client.persist.wasSaved = Boolean(existing);
|
|
215
222
|
if (!isCurrent(client)) return false;
|
|
216
|
-
const
|
|
223
|
+
const keptName = cleanName(name) ?? existing?.name;
|
|
224
|
+
const next = connections.filter(item => item.port !== port)
|
|
225
|
+
.concat({ port, token, ...(keptName ? { name: keptName } : {}) })
|
|
226
|
+
.sort((a, b) => a.port - b.port);
|
|
217
227
|
await chrome.storage.local.set({ connections: next, enabled: true });
|
|
218
228
|
await chrome.storage.local.remove('token');
|
|
219
229
|
client.persist.wrote = true;
|
|
@@ -279,7 +289,7 @@ async function startClient(client, { code, restoreEpoch } = {}) {
|
|
|
279
289
|
const saved = connections.find(item => item.port === port);
|
|
280
290
|
if (!code && !saved) throw new Error(`No saved pairing for port ${port}. Enter the 8-digit code from Harness.`);
|
|
281
291
|
if (!saved) {
|
|
282
|
-
if (connections.length + pairingInFlight.size >= MAX_CONNECTIONS) throw new Error(`TOO_MANY_CONNECTIONS: forget a saved Harness before pairing
|
|
292
|
+
if (connections.length + pairingInFlight.size >= MAX_CONNECTIONS) throw new Error(`TOO_MANY_CONNECTIONS: forget a saved Harness before pairing another (maximum ${MAX_CONNECTIONS})`);
|
|
283
293
|
pairingInFlight.add(port);
|
|
284
294
|
client.pairingReserved = true;
|
|
285
295
|
}
|
|
@@ -315,7 +325,8 @@ async function startClient(client, { code, restoreEpoch } = {}) {
|
|
|
315
325
|
const message = JSON.parse(event.data);
|
|
316
326
|
if (message.type === 'ready') {
|
|
317
327
|
if (message.protocol !== 1 || !isToken(message.token)) throw new Error('Unsupported bridge protocol');
|
|
318
|
-
const
|
|
328
|
+
const name = cleanName(message.name);
|
|
329
|
+
const persisted = await saveToken(client, port, message.token, name);
|
|
319
330
|
if (!persisted || !isCurrent(client, socket)) {
|
|
320
331
|
fail(new Error(`COMMAND_CANCELED: connection to port ${port} was canceled`));
|
|
321
332
|
return;
|
|
@@ -326,6 +337,7 @@ async function startClient(client, { code, restoreEpoch } = {}) {
|
|
|
326
337
|
client.connected = true;
|
|
327
338
|
client.persist.committed = true;
|
|
328
339
|
client.version = chrome.runtime.getManifest().version;
|
|
340
|
+
client.name = name ?? client.name ?? null;
|
|
329
341
|
client.lastError = '';
|
|
330
342
|
portErrors.delete(port);
|
|
331
343
|
lastError = '';
|
|
@@ -742,7 +754,7 @@ chrome.runtime.onMessage.addListener((message, sender, respond) => {
|
|
|
742
754
|
reconnecting: auto && !connected,
|
|
743
755
|
connections: connections.map(item => {
|
|
744
756
|
const client = clients.get(item.port);
|
|
745
|
-
return { port: item.port, connected: Boolean(client?.connected), version: client?.version ?? null, error: client?.lastError || portErrors.get(item.port) || '' };
|
|
757
|
+
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) || '' };
|
|
746
758
|
}),
|
|
747
759
|
enabled: auto,
|
|
748
760
|
error: lastError,
|
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.9.1",
|
|
6
6
|
"minimum_chrome_version": "120",
|
|
7
7
|
"permissions": [
|
|
8
8
|
"debugger",
|
package/extension/popup-state.js
CHANGED
|
@@ -22,17 +22,23 @@ export function popupState({ connections = [], reconnecting = false } = {}) {
|
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export function connectionRow({ port, connected = false, version = null, error = '' } = {}) {
|
|
25
|
+
export function connectionRow({ port, connected = false, version = null, name = null, error = '' } = {}) {
|
|
26
26
|
const state = connected ? 'connected' : error ? 'error' : 'saved';
|
|
27
27
|
return {
|
|
28
28
|
port,
|
|
29
|
+
name: name || null,
|
|
29
30
|
state,
|
|
30
31
|
connected: Boolean(connected),
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
// A harness may name itself when it connects; the port stays visible so the
|
|
33
|
+
// popup still tells the user exactly which bridge the row refers to.
|
|
34
|
+
title: name ? `${name} · ${port}` : `端口 ${port}`,
|
|
35
|
+
meta: connected
|
|
36
|
+
? `已连接${version ? ` · ${version}` : ''}`
|
|
33
37
|
: error
|
|
34
|
-
?
|
|
35
|
-
:
|
|
38
|
+
? '未连接'
|
|
39
|
+
: '已保存,未连接',
|
|
40
|
+
error: error || '',
|
|
41
|
+
hint: error ? 'Harness 可能已离线或还没启动。' : '',
|
|
36
42
|
canConnect: !connected,
|
|
37
43
|
canForget: true,
|
|
38
44
|
};
|
package/extension/popup.css
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
:root { color-scheme: light; font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: #202b3e; background: #fff; }
|
|
2
2
|
* { box-sizing: border-box; }
|
|
3
3
|
body { width: 380px; margin: 0; }
|
|
4
|
-
header {
|
|
4
|
+
header { padding: 23px 22px 14px; border-bottom: 1px solid #dce4ef; }
|
|
5
|
+
.brand { display: flex; align-items: center; gap: 12px; }
|
|
6
|
+
header .star { margin: 10px 0 0; font-size: 12px; }
|
|
5
7
|
.mark { width: 42px; height: 42px; border-radius: 12px; object-fit: cover; }
|
|
6
8
|
h1 { font-size: 20px; line-height: 1.25; margin: 0; font-weight: 650; }
|
|
7
9
|
header p { margin: 3px 0 0; color: #657083; font-size: 12px; }
|
|
@@ -13,9 +15,18 @@ label { display: block; margin-bottom: 7px; font-size: 12px; }
|
|
|
13
15
|
.pair-row .field { flex: 1; min-width: 0; }
|
|
14
16
|
.pair-row button { padding: 10px 13px; }
|
|
15
17
|
#code { text-transform: uppercase; }
|
|
16
|
-
#connections { margin: 0 0 14px; padding: 0; list-style: none; }
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
#connections { margin: 0 0 14px; padding: 0; list-style: none; max-height: 300px; overflow-y: auto; display: grid; gap: 8px; }
|
|
19
|
+
.conn { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 2px 8px; padding: 9px 11px; border: 1px solid #dce4ef; border-radius: 8px; background: #fbfcfe; }
|
|
20
|
+
.conn.connected { border-color: #b7dccd; background: #f5fbf8; }
|
|
21
|
+
.conn.error { border-color: #efc6cb; background: #fdf7f7; }
|
|
22
|
+
.conn-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
|
|
23
|
+
.conn-title { font-weight: 600; overflow-wrap: anywhere; }
|
|
24
|
+
.conn-meta { display: inline-flex; align-items: center; gap: 6px; color: #657083; font-size: 12px; }
|
|
25
|
+
.conn-actions { display: flex; gap: 2px; }
|
|
26
|
+
.conn .link { background: none; border: 0; color: #657083; padding: 2px 4px; font-size: 12px; text-decoration: underline; }
|
|
27
|
+
.conn-warn { width: 17px; height: 17px; padding: 0; border: 1.5px solid #c0392b; border-radius: 50%; background: #fff; color: #c0392b; font-size: 11px; font-weight: 700; line-height: 1; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
|
|
28
|
+
.conn-warn:hover, .conn-warn:focus-visible { background: #c0392b; color: #fff; }
|
|
29
|
+
.conn-error { grid-column: 1 / -1; margin: 6px 0 0; color: #a22331; font-size: 12px; overflow-wrap: anywhere; }
|
|
19
30
|
input { min-width: 0; width: 100%; border: 1px solid #9caec6; padding: 10px; font: inherit; border-radius: 6px; letter-spacing: 2px; }
|
|
20
31
|
button { font: inherit; font-weight: 600; background: #185adb; color: white; border: 1px solid transparent; border-radius: 6px; padding: 10px 15px; cursor: pointer; white-space: nowrap; }
|
|
21
32
|
button:disabled { opacity: .45; cursor: default; }
|
|
@@ -34,6 +45,5 @@ li { padding: 5px 0; overflow-wrap: anywhere; }
|
|
|
34
45
|
#error:empty { display: none; }
|
|
35
46
|
footer { padding: 12px 22px 18px; color: #657083; font-size: 11px; }
|
|
36
47
|
footer p { margin: 0; }
|
|
37
|
-
footer .star { margin-bottom: 6px; font-size: 12px; }
|
|
38
48
|
a { color: #185adb; }
|
|
39
49
|
[hidden] { display: none !important; }
|
package/extension/popup.html
CHANGED
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
<html lang="zh-CN">
|
|
3
3
|
<head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>dsh-chrome-use</title><link rel="stylesheet" href="popup.css"></head>
|
|
4
4
|
<body>
|
|
5
|
-
<header
|
|
5
|
+
<header>
|
|
6
|
+
<div class="brand"><img class="mark" src="icon-48.png" alt=""><div><h1>dsh-chrome-use</h1><p>连接你的所有 Harness 与浏览器</p></div></div>
|
|
7
|
+
<p class="star"><a href="https://github.com/tao1020/dsh-chrome-use" target="_blank" rel="noreferrer">喜欢这个插件?点个 Star,让更多人发现它 ⭐</a></p>
|
|
8
|
+
</header>
|
|
6
9
|
<main>
|
|
7
10
|
<p id="status" role="status">正在检查连接…</p>
|
|
8
11
|
<ul id="connections" aria-label="已配对的 Harness"></ul>
|
|
@@ -27,7 +30,6 @@
|
|
|
27
30
|
<button id="disconnect" class="secondary">断开全部连接</button>
|
|
28
31
|
</main>
|
|
29
32
|
<footer>
|
|
30
|
-
<p class="star"><a href="https://github.com/tao1020/dsh-chrome-use" target="_blank" rel="noreferrer">喜欢这个插件?点个 Star,让更多人发现它 ⭐</a></p>
|
|
31
33
|
<p>本机连接 · 不上传到插件作者的服务器</p>
|
|
32
34
|
</footer>
|
|
33
35
|
<script type="module" src="popup.js"></script>
|
package/extension/popup.js
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
1
|
import { popupState } from './popup-state.js';
|
|
2
2
|
|
|
3
3
|
const $ = id => document.getElementById(id);
|
|
4
|
+
function connectionItem(row) {
|
|
5
|
+
const li = document.createElement('li');
|
|
6
|
+
li.className = `conn ${row.state}`;
|
|
7
|
+
const info = document.createElement('div');
|
|
8
|
+
info.className = 'conn-info';
|
|
9
|
+
const title = document.createElement('span');
|
|
10
|
+
title.className = 'conn-title';
|
|
11
|
+
title.textContent = row.title;
|
|
12
|
+
const meta = document.createElement('span');
|
|
13
|
+
meta.className = 'conn-meta';
|
|
14
|
+
meta.textContent = row.meta;
|
|
15
|
+
info.append(title);
|
|
16
|
+
let detail;
|
|
17
|
+
if (row.error) {
|
|
18
|
+
// The full reason lives behind the icon: a long browser error in the row
|
|
19
|
+
// wraps and makes every card unreadable.
|
|
20
|
+
const icon = document.createElement('button');
|
|
21
|
+
icon.type = 'button';
|
|
22
|
+
icon.className = 'conn-warn';
|
|
23
|
+
icon.textContent = '!';
|
|
24
|
+
icon.title = row.error;
|
|
25
|
+
icon.setAttribute('aria-label', `连接问题:${row.error}`);
|
|
26
|
+
detail = document.createElement('p');
|
|
27
|
+
detail.className = 'conn-error';
|
|
28
|
+
detail.textContent = `${row.error} ${row.hint}`;
|
|
29
|
+
detail.hidden = true;
|
|
30
|
+
icon.addEventListener('click', () => { detail.hidden = !detail.hidden; });
|
|
31
|
+
meta.append(icon);
|
|
32
|
+
info.append(meta);
|
|
33
|
+
} else {
|
|
34
|
+
info.append(meta);
|
|
35
|
+
}
|
|
36
|
+
const actions = document.createElement('span');
|
|
37
|
+
actions.className = 'conn-actions';
|
|
38
|
+
if (row.canConnect) {
|
|
39
|
+
const connect = document.createElement('button');
|
|
40
|
+
connect.type = 'button';
|
|
41
|
+
connect.className = 'link';
|
|
42
|
+
connect.textContent = '连接';
|
|
43
|
+
connect.addEventListener('click', () => act('connect', { port: row.port }));
|
|
44
|
+
actions.append(connect);
|
|
45
|
+
}
|
|
46
|
+
if (row.canForget) {
|
|
47
|
+
const forget = document.createElement('button');
|
|
48
|
+
forget.type = 'button';
|
|
49
|
+
forget.className = 'link';
|
|
50
|
+
forget.textContent = '忘记';
|
|
51
|
+
forget.addEventListener('click', () => act('forget', { port: row.port }));
|
|
52
|
+
actions.append(forget);
|
|
53
|
+
}
|
|
54
|
+
li.append(info, actions);
|
|
55
|
+
if (detail) li.append(detail);
|
|
56
|
+
return li;
|
|
57
|
+
}
|
|
4
58
|
async function act(action, extra = {}) {
|
|
5
59
|
$('error').textContent = '';
|
|
6
60
|
try {
|
|
@@ -9,32 +63,7 @@ async function act(action, extra = {}) {
|
|
|
9
63
|
const show = popupState(result);
|
|
10
64
|
$('status').textContent = show.statusText;
|
|
11
65
|
$('status').classList.toggle('connected', show.connected);
|
|
12
|
-
$('connections').replaceChildren();
|
|
13
|
-
for (const row of show.connections) {
|
|
14
|
-
const li = document.createElement('li');
|
|
15
|
-
const label = document.createElement('span');
|
|
16
|
-
label.textContent = row.text;
|
|
17
|
-
li.append(label);
|
|
18
|
-
const buttons = document.createElement('span');
|
|
19
|
-
if (row.canConnect) {
|
|
20
|
-
const connect = document.createElement('button');
|
|
21
|
-
connect.type = 'button';
|
|
22
|
-
connect.className = 'link';
|
|
23
|
-
connect.textContent = '连接';
|
|
24
|
-
connect.addEventListener('click', () => act('connect', { port: row.port }));
|
|
25
|
-
buttons.append(connect);
|
|
26
|
-
}
|
|
27
|
-
if (row.canForget) {
|
|
28
|
-
const forget = document.createElement('button');
|
|
29
|
-
forget.type = 'button';
|
|
30
|
-
forget.className = 'link';
|
|
31
|
-
forget.textContent = '忘记';
|
|
32
|
-
forget.addEventListener('click', () => act('forget', { port: row.port }));
|
|
33
|
-
buttons.append(forget);
|
|
34
|
-
}
|
|
35
|
-
li.append(buttons);
|
|
36
|
-
$('connections').append(li);
|
|
37
|
-
}
|
|
66
|
+
$('connections').replaceChildren(...show.connections.map(connectionItem));
|
|
38
67
|
$('tabs').replaceChildren();
|
|
39
68
|
for (const tab of result.tabs.length ? result.tabs : [{ title: '当前没有调试中的标签页' }]) {
|
|
40
69
|
const li = document.createElement('li');
|
package/package.json
CHANGED
package/src/bridge.js
CHANGED
|
@@ -10,13 +10,21 @@ import { candidatePorts, portStateDir, preferencePath, probePort, readPreferredP
|
|
|
10
10
|
const equal = (a, b) => typeof a === 'string' && typeof b === 'string' && a.length === b.length && timingSafeEqual(Buffer.from(a), Buffer.from(b));
|
|
11
11
|
const extensionOrigin = /^chrome-extension:\/\/[a-p]{32}$/;
|
|
12
12
|
const CLAIM_WAIT_MS = 10000;
|
|
13
|
+
const normalizeName = value => {
|
|
14
|
+
if (typeof value !== 'string') return undefined;
|
|
15
|
+
const name = value.replace(/[\u0000-\u001F\u007F]/g, ' ').trim().slice(0, 40);
|
|
16
|
+
return name || undefined;
|
|
17
|
+
};
|
|
13
18
|
const portValue = value => {
|
|
14
19
|
const port = typeof value === 'string' ? Number(value) : value;
|
|
15
20
|
return Number.isSafeInteger(port) && port >= 1024 && port <= 65535 ? String(port) : undefined;
|
|
16
21
|
};
|
|
17
22
|
|
|
18
23
|
export class Bridge {
|
|
19
|
-
constructor({ port = PORT, auto = false, portCandidates, baseStateDir, stateDir, probe = probePort, deadlineMs = DEADLINE_MS, claimWaitMs = CLAIM_WAIT_MS } = {}) {
|
|
24
|
+
constructor({ port = PORT, auto = false, portCandidates, baseStateDir, stateDir, name, probe = probePort, deadlineMs = DEADLINE_MS, claimWaitMs = CLAIM_WAIT_MS } = {}) {
|
|
25
|
+
// Optional label the agent side shows in the popup so the user can tell
|
|
26
|
+
// Harnesses apart; it is display-only and never used for routing.
|
|
27
|
+
this.name = normalizeName(name);
|
|
20
28
|
this.port = auto ? undefined : port;
|
|
21
29
|
this.requestedPort = auto ? undefined : port;
|
|
22
30
|
this.auto = auto;
|
|
@@ -243,7 +251,7 @@ export class Bridge {
|
|
|
243
251
|
client.parallel = Array.isArray(message.features) && message.features.includes(PARALLEL_TABS);
|
|
244
252
|
this.lastError = undefined;
|
|
245
253
|
clearTimeout(timer);
|
|
246
|
-
client.send(JSON.stringify({ type: 'ready', token: identity.token, protocol: 1 }));
|
|
254
|
+
client.send(JSON.stringify({ type: 'ready', token: identity.token, protocol: 1, ...(this.name ? { name: this.name } : {}) }));
|
|
247
255
|
return;
|
|
248
256
|
}
|
|
249
257
|
if (message.type === 'inbox') {
|
package/src/client.js
CHANGED
|
@@ -68,7 +68,7 @@ async function checkRelease(current, fetcher = fetch) {
|
|
|
68
68
|
} finally { clearTimeout(timer); }
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
const packageVersion = "0.
|
|
71
|
+
const packageVersion = "0.9.1";
|
|
72
72
|
// Wrapped by scripts/build-client.mjs for the Harness browser module loader.
|
|
73
73
|
const React = require('react');
|
|
74
74
|
const { createElement: h, useState, useEffect, useRef } = React;
|
package/src/index.js
CHANGED
|
@@ -18,7 +18,9 @@ export const inject = ['tools'];
|
|
|
18
18
|
|
|
19
19
|
export function bridgeOptions(env, baseStateDir) {
|
|
20
20
|
const configured = env?.DSH_CHROME_USE_PORT?.trim();
|
|
21
|
-
|
|
21
|
+
const options = configured ? { port: parsePort(configured), baseStateDir } : { auto: true, baseStateDir };
|
|
22
|
+
const name = env?.DSH_CHROME_USE_NAME?.trim().slice(0, 40);
|
|
23
|
+
return name ? { ...options, name } : options;
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
// DSH accepts a JSON Schema subset. Keep full bounds in the shared validator.
|
package/src/port-selector.js
CHANGED
|
@@ -4,7 +4,7 @@ import { dirname, join } from 'node:path';
|
|
|
4
4
|
import { PORT } from '../extension/protocol.js';
|
|
5
5
|
|
|
6
6
|
export const FIXTURE_PORT = 18792;
|
|
7
|
-
export const AUTO_PORTS = [PORT, 18793, 18794, 18795, 18796, 18797, 18798, 18799];
|
|
7
|
+
export const AUTO_PORTS = [PORT, 18793, 18794, 18795, 18796, 18797, 18798, 18799, 18800, 18801];
|
|
8
8
|
export const PREFERENCE_FILE = 'port.json';
|
|
9
9
|
|
|
10
10
|
export function isValidAutoPort(value) {
|