@chendaleiq/dsh-chrome 0.1.0 → 0.1.2
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 +12 -13
- package/README.en.md +6 -4
- package/README.md +6 -4
- package/cordis.patch.yml +1 -1
- package/docs/DETAIL.md +3 -1
- package/extension/_locales/en/messages.json +18 -6
- package/extension/_locales/zh_CN/messages.json +18 -6
- package/extension/service_worker.js +99 -2
- package/package.json +9 -1
- package/src/index.js +1 -1
- package/src/tools.js +30 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 0.1.2 — 2026-11-17
|
|
4
4
|
|
|
5
|
-
-
|
|
6
|
-
`
|
|
7
|
-
|
|
5
|
+
- 上架准备:`package.json` 新增 `dsh.catalog`(tool 类目 + 中英 summary),README 中英双语补齐 `dsh plugin --profile web add @chendaleiq/dsh-chrome` 一键安装命令。
|
|
6
|
+
Market readiness: `dsh.catalog` metadata + copyable `dsh plugin --profile web add` install command in both READMEs.
|
|
7
|
+
- GitHub 仓库补齐 `dsh-plugin` 等 8 个 topics、描述与 npm 主页,三大自动发现市场(dsh-plugin.org / awesome-dsh-plugin / dsh-plugin-shop)开始收录。
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
`
|
|
13
|
-
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
-
|
|
17
|
-
Bilingual tool descriptions, bundle locales, README in both languages.
|
|
9
|
+
## 0.1.1 — 2026-11-17
|
|
10
|
+
|
|
11
|
+
- 新增 `chrome_fill`:CSP 安全的表单填写(静态注入函数,无 eval),discover 先拿选择器。
|
|
12
|
+
New `chrome_fill`: CSP-safe form fill via a static injected function (no eval).
|
|
13
|
+
- 新增 `chrome_onboard`:扩展没连上时打开文件管理器定位扩展目录,首次加载自动做一次。
|
|
14
|
+
- 扩展 UI 卡片式重做 + 全量 chrome.i18n(en + zh_CN);工具描述、README/DETAIL/TESTING 中英双语。
|
|
15
|
+
- 安装流程:一键 `scripts/setup.mjs`、`--install-launchd` 开机自启、`scripts/bridge.mjs` 独立入口、market 索引(Discover 可搜)。
|
|
16
|
+
- 修过两个真 bug:EADDRINUSE 未接住会崩宿主(现降级为 client);空闲轮询 return 跳过紧循环(现统一收敛)。
|
|
18
17
|
|
|
19
18
|
## 0.1.0 — 2026-11-17
|
|
20
19
|
|
package/README.en.md
CHANGED
|
@@ -33,7 +33,7 @@ node scripts/setup.mjs # env checks + tests + prints the paths below
|
|
|
33
33
|
projects/dsh-chrome/
|
|
34
34
|
package.json # @chendaleiq/dsh-chrome, Host-only bundle
|
|
35
35
|
cordis.patch.yml # id/name/config (bridgePort defaults to 17319, loopback only)
|
|
36
|
-
src/index.js # apply(ctx, config): wrap with defineTool, register
|
|
36
|
+
src/index.js # apply(ctx, config): wrap with defineTool, register 11 tools
|
|
37
37
|
src/tools.js # tool definitions (pure module, unit-testable)
|
|
38
38
|
src/bridge-client.js # minimal wire-protocol client
|
|
39
39
|
src/bridge-server.js # local bridge: /status /command /next (25s long-poll) /result
|
|
@@ -49,7 +49,7 @@ projects/dsh-chrome/
|
|
|
49
49
|
test/*.test.mjs
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
## Tools (
|
|
52
|
+
## Tools (11)
|
|
53
53
|
|
|
54
54
|
| Tool | Approval | Notes |
|
|
55
55
|
|---|---|---|
|
|
@@ -58,6 +58,7 @@ projects/dsh-chrome/
|
|
|
58
58
|
| `chrome_tabs_list` | no | Bounded tab list |
|
|
59
59
|
| `chrome_snapshot` | no | Accessibility snapshot; prefer over screenshots for reading |
|
|
60
60
|
| `chrome_screenshot` | no | Returns file path only, never base64 |
|
|
61
|
+
| `chrome_fill` | yes | Discover selectors first, then fill/click; no eval, CSP-safe |
|
|
61
62
|
| `chrome_tab_select` | yes | Activate one tab by id |
|
|
62
63
|
| `chrome_tab_new` | yes | Background tab, tracked as owned |
|
|
63
64
|
| `chrome_tab_close` | yes | Close one tab by id |
|
|
@@ -91,7 +92,8 @@ MIT, see [LICENSE](LICENSE). Shipped files are whitelisted in `package.json`.
|
|
|
91
92
|
|
|
92
93
|
| Channel | Status | How |
|
|
93
94
|
|---|---|---|
|
|
94
|
-
| npm `@chendaleiq/dsh-chrome` |
|
|
95
|
-
| GitHub release (with tarball) |
|
|
95
|
+
| npm `@chendaleiq/dsh-chrome` | ✅ Published (auto-released by GitHub Actions) | `dsh plugin --profile web add @chendaleiq/dsh-chrome` (replace `web` with your profile; `npm i @chendaleiq/dsh-chrome` also works) |
|
|
96
|
+
| GitHub release (with tarball) | ✅ Published | `dsh plugin add github:chendaleiQ/dsh-chrome` |
|
|
96
97
|
| DSH Discover index | Ready | Settings → Plugins → Discover, add the raw URL of `market/index.json` (see [market/README.md](market/README.md)) |
|
|
97
98
|
| Local directory | Always works | Plugins → Add plugin → pick this directory |
|
|
99
|
+
| Third-party markets | See below | dsh-plugin.org (`dsh-plugin` topic auto-indexed) · awesome-dsh-plugin (same topic, daily crawl) · dsh-plugin-shop (npm keyword auto-indexed) |
|
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ node scripts/setup.mjs # 检查环境 + 单测 + 打印下面两步要
|
|
|
25
25
|
projects/dsh-chrome/
|
|
26
26
|
package.json # @chendaleiq/dsh-chrome,Host-only bundle
|
|
27
27
|
cordis.patch.yml # id/name/config(bridgePort 默认 17319,只听本机)
|
|
28
|
-
src/index.js # apply(ctx, config):defineTool 包装后注册
|
|
28
|
+
src/index.js # apply(ctx, config):defineTool 包装后注册 11 个工具
|
|
29
29
|
src/tools.js # 工具定义(纯模块,可单测;defineTool 契约见注释)
|
|
30
30
|
src/bridge-client.js # 最小 wire 协议客户端
|
|
31
31
|
src/bridge-server.js # 本地桥:/status /command /next(25s 长轮询)/result
|
|
@@ -41,7 +41,7 @@ projects/dsh-chrome/
|
|
|
41
41
|
test/*.test.mjs
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
## 工具(
|
|
44
|
+
## 工具(11 个)
|
|
45
45
|
|
|
46
46
|
| 工具 | 要审批 | 说明 |
|
|
47
47
|
|---|---|---|
|
|
@@ -50,6 +50,7 @@ projects/dsh-chrome/
|
|
|
50
50
|
| `chrome_tabs_list` | 否 | 标签页列表(有界) |
|
|
51
51
|
| `chrome_snapshot` | 否 | 无障碍快照,阅读优先用它而不是截图 |
|
|
52
52
|
| `chrome_screenshot` | 否 | 只回文件 path,不回 base64 |
|
|
53
|
+
| `chrome_fill` | 是 | 先 discover 拿选择器,再 fill 填值/点按钮;无 eval,CSP 页面可用 |
|
|
53
54
|
| `chrome_tab_select` | 是 | 按 id 激活标签页 |
|
|
54
55
|
| `chrome_tab_new` | 是 | 后台开新标签页,记为自有 |
|
|
55
56
|
| `chrome_tab_close` | 是 | 按 id 关闭标签页 |
|
|
@@ -79,7 +80,8 @@ MIT,见 [LICENSE](LICENSE)。`files` 白名单见 `package.json`。
|
|
|
79
80
|
|
|
80
81
|
| 渠道 | 状态 | 怎么装 |
|
|
81
82
|
|---|---|---|
|
|
82
|
-
| npm `@chendaleiq/dsh-chrome` |
|
|
83
|
-
| GitHub release(含 tarball) |
|
|
83
|
+
| npm `@chendaleiq/dsh-chrome` | ✅ 已发布(GitHub Actions 自动发版) | `dsh plugin --profile web add @chendaleiq/dsh-chrome`(把 `web` 换成你的 profile 名;`npm i @chendaleiq/dsh-chrome` 也可) |
|
|
84
|
+
| GitHub release(含 tarball) | ✅ 已发布 | `dsh plugin add github:chendaleiQ/dsh-chrome` |
|
|
84
85
|
| DSH 发现页索引 | 就绪 | 设置 → 插件 → 发现页,加 `market/index.json` 的 raw URL(见 [market/README.md](market/README.md)) |
|
|
85
86
|
| 本地目录 | 一直可用 | 插件页 → Add plugin → 选本目录 |
|
|
87
|
+
| 第三方大市场 | 见下 | dsh-plugin.org(加 `dsh-plugin` topic 自动收录) · awesome-dsh-plugin(同 topic 每日抓取) · dsh-plugin-shop(npm 关键词自动收录) |
|
package/cordis.patch.yml
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
bridgeHost: '127.0.0.1'
|
|
15
15
|
# 只读默认放行,写操作默认问;与 DSH approval/sandbox 叠加,不替代
|
|
16
16
|
approvalPolicy: 'read-auto'
|
|
17
|
-
requireApprovalFor: ['chrome_navigate', 'chrome_evaluate', 'chrome_tab_select', 'chrome_tab_new', 'chrome_tab_close']
|
|
17
|
+
requireApprovalFor: ['chrome_navigate', 'chrome_evaluate', 'chrome_tab_select', 'chrome_tab_new', 'chrome_tab_close', 'chrome_fill']
|
|
18
18
|
blockPrivateIPs: true
|
|
19
19
|
snapshotMaxChars: 8000
|
|
20
20
|
evaluateMaxChars: 4000
|
package/docs/DETAIL.md
CHANGED
|
@@ -9,8 +9,10 @@ Read tabs, snapshot pages, navigate, screenshot, and evaluate JS in local Chrome
|
|
|
9
9
|
- `chrome_tabs_list` / `chrome_snapshot`:先看列表与快照,截图只是确认。
|
|
10
10
|
List tabs and snapshot first; screenshot only to confirm.
|
|
11
11
|
- `chrome_navigate` / `chrome_tab_select` / `chrome_tab_new` / `chrome_tab_close` /
|
|
12
|
-
`chrome_evaluate`:写操作与最高危取值,走 DSH 审批;私有网段直接硬拒。
|
|
12
|
+
`chrome_fill` / `chrome_evaluate`:写操作与最高危取值,走 DSH 审批;私有网段直接硬拒。
|
|
13
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.
|
|
14
16
|
- 截图只回文件 path,不把 base64 塞进上下文;快照与求值超长截断。
|
|
15
17
|
Screenshots return file paths (no base64); snapshots/evals truncate.
|
|
16
18
|
|
|
@@ -11,20 +11,32 @@
|
|
|
11
11
|
"description": "Shown when the bridge answers but no poll arrived"
|
|
12
12
|
},
|
|
13
13
|
"statusHeartbeat": {
|
|
14
|
-
"message": "SW heartbeat: #$
|
|
15
|
-
"description": "Service-worker liveness: poll count, state, age, version"
|
|
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
|
+
}
|
|
16
22
|
},
|
|
17
23
|
"statusHeartbeatNone": {
|
|
18
24
|
"message": "SW heartbeat: none (the service worker has never polled)"
|
|
19
25
|
},
|
|
20
26
|
"connectNow": { "message": "Connect now" },
|
|
21
27
|
"lastSeen": {
|
|
22
|
-
"message": "lastSeen: $
|
|
23
|
-
"description": "Last poll timestamp"
|
|
28
|
+
"message": "lastSeen: $p1$",
|
|
29
|
+
"description": "Last poll timestamp",
|
|
30
|
+
"placeholders": {
|
|
31
|
+
"p1": { "content": "$1" }
|
|
32
|
+
}
|
|
24
33
|
},
|
|
25
34
|
"clientLabel": {
|
|
26
|
-
"message": "client: $
|
|
27
|
-
"description": "Connected client name"
|
|
35
|
+
"message": "client: $p1$",
|
|
36
|
+
"description": "Connected client name",
|
|
37
|
+
"placeholders": {
|
|
38
|
+
"p1": { "content": "$1" }
|
|
39
|
+
}
|
|
28
40
|
},
|
|
29
41
|
"bridgeLabel": { "message": "Bridge" },
|
|
30
42
|
"openDocs": { "message": "Docs" }
|
|
@@ -11,20 +11,32 @@
|
|
|
11
11
|
"description": "桥通但无轮询时显示"
|
|
12
12
|
},
|
|
13
13
|
"statusHeartbeat": {
|
|
14
|
-
"message": "SW 心跳:#$
|
|
15
|
-
"description": "Service Worker 存活:次数、状态、时长、版本"
|
|
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
|
+
}
|
|
16
22
|
},
|
|
17
23
|
"statusHeartbeatNone": {
|
|
18
24
|
"message": "SW 心跳:无(service worker 还没跑过一次轮询)"
|
|
19
25
|
},
|
|
20
26
|
"connectNow": { "message": "立即连接" },
|
|
21
27
|
"lastSeen": {
|
|
22
|
-
"message": "lastSeen:$
|
|
23
|
-
"description": "上次轮询时间"
|
|
28
|
+
"message": "lastSeen:$p1$",
|
|
29
|
+
"description": "上次轮询时间",
|
|
30
|
+
"placeholders": {
|
|
31
|
+
"p1": { "content": "$1" }
|
|
32
|
+
}
|
|
24
33
|
},
|
|
25
34
|
"clientLabel": {
|
|
26
|
-
"message": "client:$
|
|
27
|
-
"description": "连接的客户端名"
|
|
35
|
+
"message": "client:$p1$",
|
|
36
|
+
"description": "连接的客户端名",
|
|
37
|
+
"placeholders": {
|
|
38
|
+
"p1": { "content": "$1" }
|
|
39
|
+
}
|
|
28
40
|
},
|
|
29
41
|
"bridgeLabel": { "message": "桥" },
|
|
30
42
|
"openDocs": { "message": "使用文档" }
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* POSTs back to /result. Matches projects/dsh-chrome/src/bridge-server.js.
|
|
4
4
|
*
|
|
5
5
|
* Wire actions implemented:
|
|
6
|
-
* tab.version / tab.list / tab.activate
|
|
7
|
-
* page.navigate / page.snapshot / page.screenshot / page.evaluate
|
|
6
|
+
* tab.version / tab.list / tab.activate / tab.new / tab.close
|
|
7
|
+
* page.navigate / page.snapshot / page.screenshot / page.evaluate / page.fill
|
|
8
8
|
* Everything else returns an explicit "unsupported in 0.1.0" error (fail-closed).
|
|
9
9
|
*/
|
|
10
10
|
const BRIDGE = "http://127.0.0.1:17319";
|
|
@@ -156,6 +156,15 @@ async function handleAction(action, params) {
|
|
|
156
156
|
const dataUrl = await chrome.tabs.captureVisibleTab(windowId, { format: "png" });
|
|
157
157
|
return { dataUrl, fullPage: false, tabId: String(id) };
|
|
158
158
|
}
|
|
159
|
+
case "page.fill": {
|
|
160
|
+
const id = await resolveTabId(params);
|
|
161
|
+
const [{ result }] = await chrome.scripting.executeScript({
|
|
162
|
+
target: { tabId: id },
|
|
163
|
+
func: fillPage,
|
|
164
|
+
args: [params.mode === "discover" ? "discover" : "fill", Array.isArray(params.fields) ? params.fields : []],
|
|
165
|
+
});
|
|
166
|
+
return result;
|
|
167
|
+
}
|
|
159
168
|
case "page.evaluate": {
|
|
160
169
|
if (typeof params.expression !== "string" || params.expression === "") throw new Error("missing expression");
|
|
161
170
|
const id = await resolveTabId(params);
|
|
@@ -199,6 +208,94 @@ function snapshotPage() {
|
|
|
199
208
|
return out;
|
|
200
209
|
}
|
|
201
210
|
|
|
211
|
+
/**
|
|
212
|
+
* Runs in the page (isolated world). Fully static — no eval, so page CSP
|
|
213
|
+
* (and the extension's own CSP) cannot block it.
|
|
214
|
+
* mode "discover": list visible form controls with generated selectors.
|
|
215
|
+
* mode "fill": [{ selector, value?, click? }] — set values with native
|
|
216
|
+
* setters + input/change events (React-friendly), or click.
|
|
217
|
+
*/
|
|
218
|
+
function fillPage(mode, fields) {
|
|
219
|
+
const cssPath = (el) => {
|
|
220
|
+
if (el.id) return "#" + CSS.escape(el.id);
|
|
221
|
+
const parts = [];
|
|
222
|
+
let cur = el;
|
|
223
|
+
while (cur && cur !== document.body && parts.length < 6) {
|
|
224
|
+
let seg = cur.tagName.toLowerCase();
|
|
225
|
+
const parent = cur.parentElement;
|
|
226
|
+
if (parent) {
|
|
227
|
+
const sibs = Array.prototype.filter.call(parent.children, (c) => c.tagName === cur.tagName);
|
|
228
|
+
if (sibs.length > 1) seg += ":nth-of-type(" + (sibs.indexOf(cur) + 1) + ")";
|
|
229
|
+
}
|
|
230
|
+
parts.unshift(seg);
|
|
231
|
+
cur = parent;
|
|
232
|
+
}
|
|
233
|
+
return parts.join(" > ");
|
|
234
|
+
};
|
|
235
|
+
const labelOf = (el) => {
|
|
236
|
+
if (el.id) {
|
|
237
|
+
const lab = document.querySelector('label[for="' + el.id + '"]');
|
|
238
|
+
if (lab && lab.innerText) return lab.innerText.trim().replace(/\s+/g, " ").slice(0, 80);
|
|
239
|
+
}
|
|
240
|
+
return ((el.getAttribute("aria-label") || el.placeholder || el.name || "").trim().replace(/\s+/g, " ").slice(0, 80));
|
|
241
|
+
};
|
|
242
|
+
if (mode === "discover") {
|
|
243
|
+
const els = Array.prototype.filter.call(
|
|
244
|
+
document.querySelectorAll("input, select, textarea, button"),
|
|
245
|
+
(e) => e.offsetParent !== null,
|
|
246
|
+
);
|
|
247
|
+
return {
|
|
248
|
+
fields: els.slice(0, 50).map((el) => ({
|
|
249
|
+
selector: cssPath(el),
|
|
250
|
+
tag: el.tagName.toLowerCase(),
|
|
251
|
+
type: el.type || "",
|
|
252
|
+
label: labelOf(el),
|
|
253
|
+
})),
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
const out = [];
|
|
257
|
+
for (const f of fields) {
|
|
258
|
+
const el = document.querySelector(f.selector);
|
|
259
|
+
if (!el) {
|
|
260
|
+
out.push({ selector: f.selector, ok: false, error: "not found" });
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
if (f.click) {
|
|
264
|
+
el.click();
|
|
265
|
+
out.push({ selector: f.selector, ok: true, clicked: true });
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
const tag = el.tagName.toLowerCase();
|
|
269
|
+
if (tag === "select") {
|
|
270
|
+
const want = String(f.value === undefined ? "" : f.value).trim();
|
|
271
|
+
const opts = Array.prototype.slice.call(el.options);
|
|
272
|
+
const idx = opts.findIndex((o) => o.value === f.value || o.text.trim() === want);
|
|
273
|
+
if (idx < 0) {
|
|
274
|
+
out.push({ selector: f.selector, ok: false, error: "option not found" });
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
el.selectedIndex = idx;
|
|
278
|
+
el.dispatchEvent(new Event("change", { bubbles: true }));
|
|
279
|
+
out.push({ selector: f.selector, ok: true });
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
if (el.type === "checkbox") {
|
|
283
|
+
el.checked = !!f.value && f.value !== "false" && f.value !== "0";
|
|
284
|
+
el.dispatchEvent(new Event("change", { bubbles: true }));
|
|
285
|
+
out.push({ selector: f.selector, ok: true });
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
const proto = tag === "textarea" ? window.HTMLTextAreaElement.prototype : window.HTMLInputElement.prototype;
|
|
289
|
+
const setter = Object.getOwnPropertyDescriptor(proto, "value");
|
|
290
|
+
if (setter && setter.set) setter.set.call(el, String(f.value === undefined ? "" : f.value));
|
|
291
|
+
else el.value = f.value === undefined ? "" : f.value;
|
|
292
|
+
el.dispatchEvent(new Event("input", { bubbles: true }));
|
|
293
|
+
el.dispatchEvent(new Event("change", { bubbles: true }));
|
|
294
|
+
out.push({ selector: f.selector, ok: true });
|
|
295
|
+
}
|
|
296
|
+
return { fields: out };
|
|
297
|
+
}
|
|
298
|
+
|
|
202
299
|
chrome.runtime.onInstalled.addListener(() => {
|
|
203
300
|
// 0.5 分钟是期望值:Chrome 会按自身下限钳制,失败也不影响轮询(setInterval + poll-now 兜底)。
|
|
204
301
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chendaleiq/dsh-chrome",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Control local Chrome from DSH: status, tabs, snapshot, navigate, screenshot, evaluate.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,6 +28,14 @@
|
|
|
28
28
|
"dsh": {
|
|
29
29
|
"bundle": {
|
|
30
30
|
"patch": "./cordis.patch.yml"
|
|
31
|
+
},
|
|
32
|
+
"catalog": {
|
|
33
|
+
"category": "tool",
|
|
34
|
+
"summary": {
|
|
35
|
+
"en": "Control local Chrome from DSH: tabs, snapshot, navigate, screenshot, fill and evaluate.",
|
|
36
|
+
"zh": "在 DSH 里操控本地 Chrome:标签页、快照、导航、截图、填表与取值。"
|
|
37
|
+
},
|
|
38
|
+
"capabilities": ["tools"]
|
|
31
39
|
}
|
|
32
40
|
},
|
|
33
41
|
"icon": "./icon.svg",
|
package/src/index.js
CHANGED
|
@@ -27,7 +27,7 @@ const DEFAULTS = {
|
|
|
27
27
|
bridgeHost: "127.0.0.1",
|
|
28
28
|
bridgePort: 17319,
|
|
29
29
|
approvalPolicy: "read-auto",
|
|
30
|
-
requireApprovalFor: ["chrome_navigate", "chrome_evaluate", "chrome_tab_select", "chrome_tab_new", "chrome_tab_close"],
|
|
30
|
+
requireApprovalFor: ["chrome_navigate", "chrome_evaluate", "chrome_tab_select", "chrome_tab_new", "chrome_tab_close", "chrome_fill"],
|
|
31
31
|
blockPrivateIPs: true,
|
|
32
32
|
snapshotMaxChars: 8000,
|
|
33
33
|
evaluateMaxChars: 4000,
|
package/src/tools.js
CHANGED
|
@@ -120,6 +120,36 @@ export function compileToolDefinition(def) {
|
|
|
120
120
|
*/
|
|
121
121
|
export function buildTools({ send, bridgeStatus, config, saveScreenshot, sessionKey, doOnboard }) {
|
|
122
122
|
return [
|
|
123
|
+
{
|
|
124
|
+
name: "chrome_fill",
|
|
125
|
+
description: "列出或填写页面表单:先 discover 拿选择器,再 fill 填值/点按钮;无 eval,CSP 页面也可用。List or fill page forms: discover first for selectors, then fill values/click; no eval, works under page CSP.",
|
|
126
|
+
parameters: {
|
|
127
|
+
tabId: { type: "string", description: "默认当前活动标签页。Defaults to the active tab." },
|
|
128
|
+
discover: { type: "boolean", description: "true 则只列出可见表单控件与选择器。List visible form controls with selectors." },
|
|
129
|
+
fields: { type: "array", description: "要填的项:[{ selector, value?, click? }],先用 discover 拿 selector。Fields: [{selector, value?, click?}]; discover first." },
|
|
130
|
+
},
|
|
131
|
+
output: {
|
|
132
|
+
schema: {
|
|
133
|
+
type: "object",
|
|
134
|
+
additionalProperties: false,
|
|
135
|
+
properties: {
|
|
136
|
+
fields: { type: "array", required: true, items: { type: "object" } },
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
render: (_args, value) => textBlock(JSON.stringify(value.fields, null, 1).slice(0, 4000)),
|
|
140
|
+
},
|
|
141
|
+
async execute(args, exec) {
|
|
142
|
+
void exec;
|
|
143
|
+
if (args.discover === true) {
|
|
144
|
+
const r = await send("page.fill", { mode: "discover", tabId: args.tabId }, 20000, exec);
|
|
145
|
+
return { fields: Array.isArray(r?.fields) ? r.fields : [] };
|
|
146
|
+
}
|
|
147
|
+
const fields = args.fields;
|
|
148
|
+
if (!Array.isArray(fields) || fields.length === 0) throw new Error("fill needs fields: [{ selector, value?, click? }] (or discover: true first)");
|
|
149
|
+
const r = await send("page.fill", { mode: "fill", tabId: args.tabId, fields }, 30000, exec);
|
|
150
|
+
return { fields: Array.isArray(r?.fields) ? r.fields : [] };
|
|
151
|
+
},
|
|
152
|
+
},
|
|
123
153
|
{
|
|
124
154
|
name: "chrome_onboard",
|
|
125
155
|
description: "引导安装 Chrome 扩展:桥不通或扩展没连上时调它,会打开文件管理器定位扩展目录并返回步骤。Guide extension setup: opens the file manager at the extension folder and returns steps.",
|