@chendaleiq/dsh-chrome 0.0.0-stage → 0.1.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 ADDED
@@ -0,0 +1,17 @@
1
+ # Changelog
2
+
3
+ ## 0.1.1 — 2026-11-17
4
+
5
+ - 新增 `chrome_fill`:CSP 安全的表单填写(静态注入函数,无 eval),discover 先拿选择器。
6
+ New `chrome_fill`: CSP-safe form fill via a static injected function (no eval).
7
+ - 新增 `chrome_onboard`:扩展没连上时打开文件管理器定位扩展目录,首次加载自动做一次。
8
+ - 扩展 UI 卡片式重做 + 全量 chrome.i18n(en + zh_CN);工具描述、README/DETAIL/TESTING 中英双语。
9
+ - 安装流程:一键 `scripts/setup.mjs`、`--install-launchd` 开机自启、`scripts/bridge.mjs` 独立入口、market 索引(Discover 可搜)。
10
+ - 修过两个真 bug:EADDRINUSE 未接住会崩宿主(现降级为 client);空闲轮询 return 跳过紧循环(现统一收敛)。
11
+
12
+ ## 0.1.0 — 2026-11-17
13
+
14
+ - 立项:Host-only bundle 骨架(`src/index.js` 7 个 `chrome_*` 工具 + `src/bridge-client.js` + `src/bridge-server.js`)。
15
+ - 自有 MV3 companion(`extension/`):`GET /next` 长轮询 + `POST /result` 回传,先实现 `tab.version/list/activate`。
16
+ - 已验证:`manifest` / `guard`(私有网段硬拒)/ `bridge`(无扩展时超时)/ `e2e`(fake 扩展完整回路)4 项测试全过。
17
+ - 修过一个真 bug:`command` 入队对象带 `timer/resolve`,直接序列化会报 circular,`wireCommand` 只发 `id/action/params`。
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 chendaleiQ
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.en.md ADDED
@@ -0,0 +1,98 @@
1
+ # dsh-chrome
2
+
3
+ A local Chrome control plugin for DeepSeek Harness: drive the Chrome profile you are
4
+ already signed into — list tabs, snapshot pages, navigate, screenshot, and
5
+ evaluate JS.
6
+
7
+ > 中文版:[README.md](README.md)
8
+
9
+ ## Quick start
10
+
11
+ ```bash
12
+ cd projects/dsh-chrome
13
+ node scripts/setup.mjs # env checks + tests + prints the paths below
14
+ ```
15
+
16
+ 1. **Install the extension**: `chrome://extensions` → enable Developer mode →
17
+ “Load unpacked” → pick `projects/dsh-chrome/extension/`. Look for
18
+ **DSH Chrome Connector**.
19
+ (On first load with no connection yet, the plugin opens the folder for you;
20
+ later, call the `chrome_onboard` tool whenever setup help is needed.)
21
+ 2. **Run the bridge** (either):
22
+ - Hands-free: `node scripts/setup.mjs --install-launchd` — starts on login;
23
+ - Or do nothing: the DSH plugin starts the bridge on load (falls back to
24
+ client mode if the port is taken).
25
+ 3. **Install into DSH**: Plugins → Add plugin → pick this directory
26
+ (`projects/dsh-chrome`). New sessions get 10 `chrome_*` tools.
27
+ 4. **Verify**: `npm run verify` (waits for the extension, then tab.version +
28
+ tab.list in one go).
29
+
30
+ ## Layout
31
+
32
+ ```text
33
+ projects/dsh-chrome/
34
+ package.json # @chendaleiq/dsh-chrome, Host-only bundle
35
+ cordis.patch.yml # id/name/config (bridgePort defaults to 17319, loopback only)
36
+ src/index.js # apply(ctx, config): wrap with defineTool, register 11 tools
37
+ src/tools.js # tool definitions (pure module, unit-testable)
38
+ src/bridge-client.js # minimal wire-protocol client
39
+ src/bridge-server.js # local bridge: /status /command /next (25s long-poll) /result
40
+ src/screenshot.js # dataUrl → file + PNG dimension parsing
41
+ src/auto-bridge.js # bridge autostart with port-taken fallback
42
+ scripts/setup.mjs # one-command setup check (incl. --install-launchd)
43
+ scripts/bridge.mjs # standalone bridge entry (used by LaunchAgent)
44
+ scripts/verify.mjs # one-command real-Chrome verification
45
+ extension/ # MV3 companion: manifest + service worker + popup
46
+ extension/_locales/ # extension UI in English + 简体中文 (en + zh_CN)
47
+ locale/en.json zh.json
48
+ docs/DETAIL.md docs/TESTING.md
49
+ test/*.test.mjs
50
+ ```
51
+
52
+ ## Tools (11)
53
+
54
+ | Tool | Approval | Notes |
55
+ |---|---|---|
56
+ | `chrome_onboard` | no | Setup guide: opens the folder at the extension and returns steps |
57
+ | `chrome_status` | no | Bridge health; call first when others fail |
58
+ | `chrome_tabs_list` | no | Bounded tab list |
59
+ | `chrome_snapshot` | no | Accessibility snapshot; prefer over screenshots for reading |
60
+ | `chrome_screenshot` | no | Returns file path only, never base64 |
61
+ | `chrome_fill` | yes | Discover selectors first, then fill/click; no eval, CSP-safe |
62
+ | `chrome_tab_select` | yes | Activate one tab by id |
63
+ | `chrome_tab_new` | yes | Background tab, tracked as owned |
64
+ | `chrome_tab_close` | yes | Close one tab by id |
65
+ | `chrome_navigate` | yes | Navigate; private hosts hard-rejected |
66
+ | `chrome_evaluate` | yes | Read-only page eval, truncated output |
67
+
68
+ All outputs are bounded: snapshots/evals truncate, screenshots return paths only.
69
+ The bridge listens on `127.0.0.1` only.
70
+
71
+ ## Security
72
+
73
+ - Reads are auto-approved; writes go through DSH approval. `navigate` hard-rejects
74
+ `localhost`/private ranges/non-http(s).
75
+ - Extension permissions kept minimal: `tabs/scripting/storage/alarms`, no
76
+ `debugger` (never fights DevTools).
77
+ - Screenshots/audit land in `~/.dsh/chrome/<session>/` by default.
78
+
79
+ ## Status
80
+
81
+ - [x] Bridge protocol + end-to-end loop with a fake extension
82
+ - [x] Real-Chrome verification: tab.version / tab.list (13 tabs) / evaluate /
83
+ snapshot (27 nodes) / screenshot saved to disk
84
+ - [x] `install_bundle` into the desktop profile (`application: applied`, no warnings)
85
+ - [x] Open source: https://github.com/chendaleiQ/dsh-chrome
86
+
87
+ ## License
88
+
89
+ MIT, see [LICENSE](LICENSE). Shipped files are whitelisted in `package.json`.
90
+
91
+ ## Distribution
92
+
93
+ | Channel | Status | How |
94
+ |---|---|---|
95
+ | npm `@chendaleiq/dsh-chrome` | ✅ 0.1.0 published | `npm i @chendaleiq/dsh-chrome` |
96
+ | GitHub release (with tarball) | v0.1.0 tagged, release page pending publish | `dsh plugin add github:chendaleiQ/dsh-chrome` |
97
+ | DSH Discover index | Ready | Settings → Plugins → Discover, add the raw URL of `market/index.json` (see [market/README.md](market/README.md)) |
98
+ | Local directory | Always works | Plugins → Add plugin → pick this directory |
package/README.md CHANGED
@@ -1,3 +1,86 @@
1
- # Temporary Holding Version
1
+ # dsh-chrome
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ DeepSeek Harness 用的本地 Chrome 操控插件:连你已经登录的那个 Chrome,能看标签页、抓快照、导航、截图、执行 JS 取值。
4
+
5
+ > English version: [README.en.md](README.en.md)
6
+
7
+ ## 一分钟上手
8
+
9
+ ```bash
10
+ cd projects/dsh-chrome
11
+ node scripts/setup.mjs # 检查环境 + 单测 + 打印下面两步要填的路径
12
+ ```
13
+
14
+ 1. **装扩展**:`chrome://extensions` → 打开开发者模式 → 「加载已解压的扩展程序」→ 选择 `projects/dsh-chrome/extension/`。认准 **DSH Chrome Connector**。
15
+ (插件首次加载且从没连上过时,会自动帮你打开文件夹定位到这一步;平时连不上就调 `chrome_onboard` 工具,它会再开一次并给步骤。)
16
+ 2. **起桥**(二选一):
17
+ - 省事:`node scripts/setup.mjs --install-launchd` —— 开机自启,常驻后台;
18
+ - 或者什么都不做:DSH 插件加载时会自动把桥拉起来(端口被占就当 client 用)。
19
+ 3. **装进 DSH**:插件页 → Add plugin → 选择本目录(`projects/dsh-chrome`)。装完新开会话就有 10 个 `chrome_*` 工具。
20
+ 4. **验证**:`npm run verify`(等扩展上线,tab.version + tab.list 一把过)。
21
+
22
+ ## 布局
23
+
24
+ ```text
25
+ projects/dsh-chrome/
26
+ package.json # @chendaleiq/dsh-chrome,Host-only bundle
27
+ cordis.patch.yml # id/name/config(bridgePort 默认 17319,只听本机)
28
+ src/index.js # apply(ctx, config):defineTool 包装后注册 11 个工具
29
+ src/tools.js # 工具定义(纯模块,可单测;defineTool 契约见注释)
30
+ src/bridge-client.js # 最小 wire 协议客户端
31
+ src/bridge-server.js # 本地桥:/status /command /next(25s 长轮询)/result
32
+ src/screenshot.js # dataUrl 落盘 + PNG 宽高解析
33
+ src/auto-bridge.js # 桥自启与端口占用降级
34
+ scripts/setup.mjs # 一键安装检查(含 --install-launchd 开机自启)
35
+ scripts/bridge.mjs # 桥独立入口(给 LaunchAgent 用)
36
+ scripts/verify.mjs # 一键真机验证
37
+ extension/ # 自有 MV3 companion:manifest + service worker + popup
38
+ extension/_locales/ # 扩展界面中英双语(en + zh_CN)
39
+ locale/en.json zh.json
40
+ docs/DETAIL.md docs/TESTING.md
41
+ test/*.test.mjs
42
+ ```
43
+
44
+ ## 工具(11 个)
45
+
46
+ | 工具 | 要审批 | 说明 |
47
+ |---|---|---|
48
+ | `chrome_onboard` | 否 | 扩展没连上时调它:打开文件夹定位扩展目录并返回步骤 |
49
+ | `chrome_status` | 否 | 桥连通性;别的工具出错先调它 |
50
+ | `chrome_tabs_list` | 否 | 标签页列表(有界) |
51
+ | `chrome_snapshot` | 否 | 无障碍快照,阅读优先用它而不是截图 |
52
+ | `chrome_screenshot` | 否 | 只回文件 path,不回 base64 |
53
+ | `chrome_fill` | 是 | 先 discover 拿选择器,再 fill 填值/点按钮;无 eval,CSP 页面可用 |
54
+ | `chrome_tab_select` | 是 | 按 id 激活标签页 |
55
+ | `chrome_tab_new` | 是 | 后台开新标签页,记为自有 |
56
+ | `chrome_tab_close` | 是 | 按 id 关闭标签页 |
57
+ | `chrome_navigate` | 是 | 导航;私有网段/非 http(s) 直接硬拒 |
58
+ | `chrome_evaluate` | 是 | 页面内只读取值,超长截断 |
59
+
60
+ 输出全部有界:快照/求值截断,截图只给 path。桥只听 `127.0.0.1`,不对外暴露。
61
+
62
+ ## 安全
63
+
64
+ - 只读默认放行,写操作走 DSH 审批;`navigate` 对 `localhost`/内网段/非 http(s) 同步硬拒。
65
+ - 扩展权限收敛到 `tabs/scripting/storage/alarms`,无 `debugger`(不跟 DevTools 抢)。
66
+ - 截图与审计落盘默认 `~/.dsh/chrome/<session>/`。
67
+
68
+ ## 状态
69
+
70
+ - [x] 本地桥协议 + fake 扩展端到端回路
71
+ - [x] 真机验证:tab.version / tab.list(13 标签)/ evaluate / snapshot(27 节点)/ screenshot 落盘
72
+ - [x] `install_bundle` 进 desktop profile(`application: applied`,零警告)
73
+ - [x] 开源:https://github.com/chendaleiQ/dsh-chrome
74
+
75
+ ## 开源
76
+
77
+ MIT,见 [LICENSE](LICENSE)。`files` 白名单见 `package.json`。
78
+
79
+ ## 获取渠道 / Distribution
80
+
81
+ | 渠道 | 状态 | 怎么装 |
82
+ |---|---|---|
83
+ | npm `@chendaleiq/dsh-chrome` | ✅ 0.1.0 已发布 | `npm i @chendaleiq/dsh-chrome` |
84
+ | GitHub release(含 tarball) | v0.1.0 已打 tag,release 页待点发布 | `dsh plugin add github:chendaleiQ/dsh-chrome` |
85
+ | DSH 发现页索引 | 就绪 | 设置 → 插件 → 发现页,加 `market/index.json` 的 raw URL(见 [market/README.md](market/README.md)) |
86
+ | 本地目录 | 一直可用 | 插件页 → Add plugin → 选本目录 |
@@ -0,0 +1,23 @@
1
+ # dsh-chrome bundle patch.
2
+ #
3
+ # Host-only:src/index.js 的 apply(ctx, config) 注册 chrome_* tools,
4
+ # 走自有本地桥(默认 127.0.0.1:17319)连自有 companion 扩展。
5
+ #
6
+ # loader 行 id、package 名、src/index.js 里 export const name 三者必须一致。
7
+ - insert:
8
+ - id: dsh-chrome
9
+ name: '@chendaleiq/dsh-chrome'
10
+ config:
11
+ enabled: true
12
+ # 本地桥监听地址;默认 127.0.0.1:17319(回环专用端口)
13
+ bridgePort: 17319
14
+ bridgeHost: '127.0.0.1'
15
+ # 只读默认放行,写操作默认问;与 DSH approval/sandbox 叠加,不替代
16
+ approvalPolicy: 'read-auto'
17
+ requireApprovalFor: ['chrome_navigate', 'chrome_evaluate', 'chrome_tab_select', 'chrome_tab_new', 'chrome_tab_close', 'chrome_fill']
18
+ blockPrivateIPs: true
19
+ snapshotMaxChars: 8000
20
+ evaluateMaxChars: 4000
21
+ screenshotMaxBytes: 512000
22
+ # 截图与审计落盘;空 = ~/.dsh/chrome
23
+ dataDir: ''
package/docs/DETAIL.md ADDED
@@ -0,0 +1,23 @@
1
+ # Chrome 操控 · Chrome control
2
+
3
+ 读取标签页、抓取页面快照、导航、截图、在本地 Chrome 里执行 JS 取值。
4
+ Read tabs, snapshot pages, navigate, screenshot, and evaluate JS in local Chrome.
5
+
6
+ 桥默认 `http://127.0.0.1:17319`,只听本机。Bridge listens on loopback only.
7
+
8
+ - `chrome_status`:先调它,失败再查桥与扩展版本。Check connection first.
9
+ - `chrome_tabs_list` / `chrome_snapshot`:先看列表与快照,截图只是确认。
10
+ List tabs and snapshot first; screenshot only to confirm.
11
+ - `chrome_navigate` / `chrome_tab_select` / `chrome_tab_new` / `chrome_tab_close` /
12
+ `chrome_fill` / `chrome_evaluate`:写操作与最高危取值,走 DSH 审批;私有网段直接硬拒。
13
+ Writes and eval go through DSH approval; private hosts are hard-rejected.
14
+ `chrome_fill` 无 eval,CSP 页面(npmjs.com 这类)也能填表点按钮。
15
+ `chrome_fill` uses no eval, so it works even under strict page CSP.
16
+ - 截图只回文件 path,不把 base64 塞进上下文;快照与求值超长截断。
17
+ Screenshots return file paths (no base64); snapshots/evals truncate.
18
+
19
+ 限制 / Limits:debugger 同一时间只能一方 attach(DevTools 正在调就互斥,扩展不用
20
+ debugger,正为避开这点);隐藏标签页的真实输入会被 Chrome 丢弃;整页截图会滚动
21
+ 页面(0.1.0 只做可视区)。No debugger use (never fights DevTools); hidden-tab
22
+ input is dropped by Chrome; full-page capture scrolls the page (viewport only
23
+ in 0.1.0).
@@ -0,0 +1,75 @@
1
+ # 真机验证手册 · Real-device verification
2
+
3
+ 目标:证明 DSH 的桥能操控你已登录的 Chrome。只读先行,写操作后置。
4
+ Goal: prove the DSH bridge drives your signed-in Chrome. Reads first, writes later.
5
+
6
+ ## 0. 一键安装检查 / Setup check
7
+
8
+ ```bash
9
+ node scripts/setup.mjs # 环境 + 单测 + 桥状态 + 打印下面要填的路径
10
+ node scripts/setup.mjs --install-launchd # 开机自启桥 / autostart bridge on login
11
+ ```
12
+
13
+ ## 1. 起桥 / Start the bridge
14
+
15
+ ```bash
16
+ node scripts/bridge.mjs # 常驻前台 / foreground
17
+ # DSH 插件加载时也会自动起桥(端口被占就当 client 用)
18
+ # The DSH plugin also starts the bridge on load (client fallback if taken).
19
+ ```
20
+
21
+ ## 2. 看连接 / Check connection
22
+
23
+ ```bash
24
+ curl -s http://127.0.0.1:17319/status
25
+ ```
26
+
27
+ - `connected:false, lastSeenAt:0` = 扩展一次都没来过 → 点工具栏图标 → 「立即连接」。
28
+ No poll ever → click the toolbar icon → Connect now.
29
+ - `connected:true` = 通了,继续第 3 步。Connected → go to step 3.
30
+
31
+ 扩展装不上时看弹窗里的 `SW 心跳` 行:无心跳 = SW 没跑起来,去
32
+ `chrome://extensions` 点 Service worker 看红字。
33
+ If the popup shows no SW heartbeat, open the extension's Service worker console
34
+ and copy the red text.
35
+
36
+ ## 3. 只读验证(不碰页面)/ Read-only verification
37
+
38
+ 一键跑(等扩展 120 秒,超时退出码 2)/ One command (waits 120s, exit 2 on timeout):
39
+
40
+ ```bash
41
+ npm run verify
42
+ npm run verify -- --snapshot # 加抓一次当前页快照 / plus one page snapshot
43
+ ```
44
+
45
+ 手动版 / Manual:
46
+
47
+ ```bash
48
+ # 握手:应返回 { extensionVersion, bridge, userAgent }
49
+ # Handshake, expect { extensionVersion, bridge, userAgent }
50
+ curl -s -X POST http://127.0.0.1:17319/command \
51
+ -H 'content-type: application/json' \
52
+ -d '{"action":"tab.version","params":{},"timeoutMs":15000}'
53
+
54
+ # 列标签页:应返回数组 [{ id, title, url }]
55
+ # List tabs, expect an array of { id, title, url }
56
+ curl -s -X POST http://127.0.0.1:17319/command \
57
+ -H 'content-type: application/json' \
58
+ -d '{"action":"tab.list","params":{},"timeoutMs":15000}'
59
+ ```
60
+
61
+ ## 4. 写操作(逐个确认后再做)/ Writes (confirm each first)
62
+
63
+ `page.navigate` / `tab.activate` / `page.evaluate` 走 DSH 审批;
64
+ `page.screenshot` 只回 dataUrl,由 Host 落盘。整页截图 0.1.0 不支持。
65
+ navigate/activate/evaluate need approval; screenshots return dataUrl for the
66
+ Host to save; full-page capture is not supported in 0.1.0.
67
+
68
+ ## 排错 / Troubleshooting
69
+
70
+ | 现象 / Symptom | 查哪里 / Check |
71
+ |---|---|
72
+ | `/status` 永远 `connected:false` | 扩展版本 stale(删掉重加)、点错图标、SW 被杀(点图标唤醒)/ stale install (re-add), wrong icon, SW suspended (click icon) |
73
+ | `/command` 504 超时 / timeout | 扩展在线但动作卡住,看扩展 SW 控制台报错 / extension stuck; read its SW console |
74
+ | `tab.list` 空数组 / empty | 无打开标签页,或扩展无 `tabs` 权限(重装)/ no tabs, or missing permission |
75
+ | `http-403` 刷屏 / log spam | 桥版本旧(`--install-launchd` 装的桥和代码不是同一版),重跑 setup / bridge older than extension; re-run setup |
@@ -0,0 +1,43 @@
1
+ {
2
+ "appName": { "message": "DSH Chrome Connector" },
3
+ "appDesc": { "message": "Poll the local DSH bridge and drive the signed-in Chrome profile." },
4
+ "statusTitle": { "message": "DSH Chrome Connector" },
5
+ "statusChecking": { "message": "checking…" },
6
+ "statusConnected": { "message": "● Connected" },
7
+ "statusNotConnected": { "message": "○ Not connected" },
8
+ "statusBridgeDown": { "message": "○ Bridge is not running" },
9
+ "statusBodyOnline": {
10
+ "message": "Bridge is up, but the extension has not polled yet. Click “Connect now”.",
11
+ "description": "Shown when the bridge answers but no poll arrived"
12
+ },
13
+ "statusHeartbeat": {
14
+ "message": "SW heartbeat: #$p1$ $p2$ ($p3$s ago, v$p4$)",
15
+ "description": "Service-worker liveness: poll count, state, age, version",
16
+ "placeholders": {
17
+ "p1": { "content": "$1" },
18
+ "p2": { "content": "$2" },
19
+ "p3": { "content": "$3" },
20
+ "p4": { "content": "$4" }
21
+ }
22
+ },
23
+ "statusHeartbeatNone": {
24
+ "message": "SW heartbeat: none (the service worker has never polled)"
25
+ },
26
+ "connectNow": { "message": "Connect now" },
27
+ "lastSeen": {
28
+ "message": "lastSeen: $p1$",
29
+ "description": "Last poll timestamp",
30
+ "placeholders": {
31
+ "p1": { "content": "$1" }
32
+ }
33
+ },
34
+ "clientLabel": {
35
+ "message": "client: $p1$",
36
+ "description": "Connected client name",
37
+ "placeholders": {
38
+ "p1": { "content": "$1" }
39
+ }
40
+ },
41
+ "bridgeLabel": { "message": "Bridge" },
42
+ "openDocs": { "message": "Docs" }
43
+ }
@@ -0,0 +1,43 @@
1
+ {
2
+ "appName": { "message": "DSH Chrome Connector" },
3
+ "appDesc": { "message": "轮询本地 DSH 桥,接管你已登录的 Chrome。" },
4
+ "statusTitle": { "message": "DSH Chrome Connector" },
5
+ "statusChecking": { "message": "检查中…" },
6
+ "statusConnected": { "message": "● 已连接" },
7
+ "statusNotConnected": { "message": "○ 未连接" },
8
+ "statusBridgeDown": { "message": "○ 桥没在跑" },
9
+ "statusBodyOnline": {
10
+ "message": "桥在线,扩展还没轮询到。点「立即连接」。",
11
+ "description": "桥通但无轮询时显示"
12
+ },
13
+ "statusHeartbeat": {
14
+ "message": "SW 心跳:#$p1$ $p2$($p3$秒前,v$p4$)",
15
+ "description": "Service Worker 存活:次数、状态、时长、版本",
16
+ "placeholders": {
17
+ "p1": { "content": "$1" },
18
+ "p2": { "content": "$2" },
19
+ "p3": { "content": "$3" },
20
+ "p4": { "content": "$4" }
21
+ }
22
+ },
23
+ "statusHeartbeatNone": {
24
+ "message": "SW 心跳:无(service worker 还没跑过一次轮询)"
25
+ },
26
+ "connectNow": { "message": "立即连接" },
27
+ "lastSeen": {
28
+ "message": "lastSeen:$p1$",
29
+ "description": "上次轮询时间",
30
+ "placeholders": {
31
+ "p1": { "content": "$1" }
32
+ }
33
+ },
34
+ "clientLabel": {
35
+ "message": "client:$p1$",
36
+ "description": "连接的客户端名",
37
+ "placeholders": {
38
+ "p1": { "content": "$1" }
39
+ }
40
+ },
41
+ "bridgeLabel": { "message": "桥" },
42
+ "openDocs": { "message": "使用文档" }
43
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "manifest_version": 3,
3
+ "name": "__MSG_appName__",
4
+ "version": "0.1.0",
5
+ "default_locale": "en",
6
+ "description": "__MSG_appDesc__",
7
+ "permissions": ["tabs", "scripting", "storage", "alarms"],
8
+ "host_permissions": ["<all_urls>"],
9
+ "background": {
10
+ "service_worker": "service_worker.js"
11
+ },
12
+ "action": {
13
+ "default_title": "DSH Chrome Connector",
14
+ "default_popup": "popup.html"
15
+ }
16
+ }
@@ -0,0 +1,29 @@
1
+ <!doctype html>
2
+ <html>
3
+ <meta charset="utf-8">
4
+ <style>
5
+ :root { color-scheme: light dark; }
6
+ body { font-family: system-ui, sans-serif; width: 300px; margin: 0; padding: 14px; }
7
+ .head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
8
+ .head h3 { margin: 0; font-size: 14px; flex: 1; }
9
+ .ver { font-size: 11px; opacity: .6; }
10
+ .card { border: 1px solid color-mix(in srgb, currentColor 20%, transparent); border-radius: 10px; padding: 10px 12px; }
11
+ .status { font-size: 14px; font-weight: 600; margin-bottom: 6px; }
12
+ .ok { color: #0a7d2c; } .bad { color: #b3261e; }
13
+ .row { font-size: 12px; opacity: .85; margin-top: 4px; word-break: break-all; }
14
+ #retry { margin-top: 10px; width: 100%; padding: 8px; border: 0; border-radius: 8px;
15
+ background: #0b57d0; color: #fff; font-size: 13px; cursor: pointer; }
16
+ #retry:disabled { opacity: .45; cursor: default; }
17
+ .foot { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; font-size: 11px; opacity: .65; }
18
+ .foot a { color: inherit; }
19
+ </style>
20
+ <div class="head"><h3 id="title">…</h3><span class="ver" id="ver"></span></div>
21
+ <div class="card">
22
+ <div class="status" id="status">…</div>
23
+ <div class="row" id="detail"></div>
24
+ <div class="row" id="hb"></div>
25
+ </div>
26
+ <button id="retry">…</button>
27
+ <div class="foot"><span id="bridge"></span><a id="docs" href="#" target="_blank" rel="noreferrer">…</a></div>
28
+ <script src="popup.js"></script>
29
+ </html>
@@ -0,0 +1,63 @@
1
+ /* Popup: bridge status + service-worker heartbeat + reconnect.
2
+ * All user-visible strings go through chrome.i18n (see _locales/).
3
+ */
4
+ const BRIDGE = "http://127.0.0.1:17319";
5
+ const DOCS_URL = "https://github.com/chendaleiQ/dsh-chrome#readme";
6
+ const t = (key, ...args) => chrome.i18n.getMessage(key, args) || key;
7
+
8
+ async function refresh() {
9
+ document.title = t("statusTitle");
10
+ document.getElementById("title").textContent = t("statusTitle");
11
+ try {
12
+ document.getElementById("ver").textContent = `v${chrome.runtime.getManifest().version}`;
13
+ } catch { /* ignore */ }
14
+ const retry = document.getElementById("retry");
15
+ retry.textContent = t("connectNow");
16
+ retry.disabled = false;
17
+ document.getElementById("bridge").textContent = `${t("bridgeLabel")}: ${BRIDGE.replace(/^http:\/\//, "")}`;
18
+ const docs = document.getElementById("docs");
19
+ docs.textContent = t("openDocs");
20
+ docs.href = DOCS_URL;
21
+
22
+ let hb = null;
23
+ try {
24
+ ({ swHeartbeat: hb = null } = await chrome.storage.local.get("swHeartbeat"));
25
+ } catch { /* ignore */ }
26
+ const hbText = hb
27
+ ? t("statusHeartbeat", String(hb.polls), String(hb.state), String(Math.round((Date.now() - hb.at) / 1000)), String(hb.version || "?"))
28
+ : t("statusHeartbeatNone");
29
+
30
+ const statusEl = document.getElementById("status");
31
+ const detailEl = document.getElementById("detail");
32
+ try {
33
+ const res = await fetch(`${BRIDGE}/status`, { cache: "no-store" });
34
+ const st = await res.json();
35
+ if (st.connected) {
36
+ statusEl.innerHTML = `<span class="ok">${escapeHtml(t("statusConnected"))}</span>`;
37
+ detailEl.textContent = `${t("lastSeen", new Date(st.lastSeenAt).toLocaleTimeString())} · ${t("clientLabel", st.clientName || "")}`;
38
+ retry.disabled = true;
39
+ } else {
40
+ statusEl.innerHTML = `<span class="bad">${escapeHtml(t("statusNotConnected"))}</span>`;
41
+ detailEl.textContent = t("statusBodyOnline");
42
+ }
43
+ } catch (e) {
44
+ statusEl.innerHTML = `<span class="bad">${escapeHtml(t("statusBridgeDown"))}</span>`;
45
+ detailEl.textContent = String(e).slice(0, 120);
46
+ }
47
+ document.getElementById("hb").textContent = hbText;
48
+ }
49
+
50
+ function escapeHtml(s) {
51
+ return String(s).replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" }[c]));
52
+ }
53
+
54
+ document.getElementById("retry").addEventListener("click", async () => {
55
+ try {
56
+ await chrome.runtime.sendMessage({ type: "poll-now" });
57
+ } catch {
58
+ // service worker 尚未唤醒:本次点击本身就是一次唤醒尝试
59
+ }
60
+ setTimeout(refresh, 1500);
61
+ });
62
+
63
+ refresh();