@glittering0717/ai-browser 2.6.2 → 2.6.3

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.
@@ -11,12 +11,12 @@ npx -y @glittering0717/ai-browser skill install
11
11
 
12
12
  | 技能 | 干什么 |
13
13
  |---|---|
14
- | `ai-browser` | 最小循环、卡住时的第一反应、难搞页面的处理(抓请求/看接口在它的 `references/network.md`) |
14
+ | `ai-browser` | 最小循环、卡住时第一反应、难搞页面(抓请求见 `references/network.md`) |
15
15
  | `content-publish` | 把文章发布到 CSDN / 知乎 / 掘金 |
16
16
  | `read-webpage` | 读一篇文章正文并总结 |
17
17
 
18
- 不装技能也能用——17 个工具的 schema 之外,MCP 初始化时还会给客户端一段 `instructions`
19
- (我是谁、什么时候用我、最小循环)。技能只是把"怎么组合"讲得更细。
18
+ 不装技能也能用:MCP 初始化还会给客户端一段 `instructions`(我是谁、何时用我、最小循环)。
19
+ 技能只是把"怎么组合"讲得更细。
20
20
 
21
21
  ---
22
22
 
@@ -29,19 +29,21 @@ npx -y @glittering0717/ai-browser skill install
29
29
  我可以用 ai-browser 操作一个真实可见的浏览器(MCP: browse_* 工具)。
30
30
 
31
31
  循环:browse_navigate {url} → browse_get_tree {subset:"interactive"} 取节点 id →
32
- browse_act {action:"click"|"type", target:id, text?}
32
+ browse_act {action:"click"|"type"|"setContent", target:id, text?}
33
33
 
34
- success:true 只代表动作发出去了,不代表页面变了。要证明生效:browse_diff 先 snapshot、
35
- 操作后 diff,看 verdict。unchanged 说明要么点错了、要么页面没响应,别接着瞎点。
34
+ 改值也只走 browse_act(type 追加 / setContent 覆盖)。**不要**用 browse_evaluate 里的
35
+ el.value= / el.click() 直接改 DOM:绕过框架状态,页面看着变了、提交上去还是旧值。
36
+
37
+ success:true 只代表动作发出去了。要证明生效:browse_diff 先 snapshot、操作后 diff 看 verdict;
38
+ unchanged = 点错了或页面没响应,别接着瞎点。
36
39
 
37
40
  卡住时的顺序:节点没有 → browse_wait 再重读树;有节点但操作失败 → 动作层问题(iframe /
38
41
  canvas / 富文本),换动作不是换选择器;点了没反应 → browse_screenshot 看视觉 或
39
42
  browse_network 看请求;怀疑掉登录 → browse_auth_state;都不是 → browse_errors。
40
43
 
41
- 需要人(登录/扫码/滑块/支付):**在你这轮回复里直接说一句**,请用户在窗口里操作,然后结束这轮等
42
- 回话;收到"好了"再 browse_get_tree 确认。这一步不需要任何工具——本项目没有 chat / message /
43
- ask_user 这类工具,也没有"发起一次性会话",别去调宿主的临时对话能力。不要编造凭据,不要重试
44
- 注定失败的点击。窗口是真的,人随时能抢鼠标。
44
+ 需要人(登录/扫码/滑块/支付):在这轮回复里说一句,请用户操作,然后结束这轮等回话;
45
+ 收到"好了"再 browse_get_tree 确认。没有 chat / message / ask_user 这类工具,别去调宿主的
46
+ 临时对话能力。不要编造凭据,不要重试注定失败的点击。窗口是真的,人随时能抢鼠标。
45
47
 
46
48
  收尾:browse_quit 关掉窗口和进程(人正在操作时不要调)。
47
49
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glittering0717/ai-browser",
3
- "version": "2.6.2",
3
+ "version": "2.6.3",
4
4
  "description": "AI-native browser — renders pixels for humans, structured semantic-tree API for agents. No screenshots, no OCR, no coordinate guessing.",
5
5
  "main": "src/main/index.js",
6
6
  "bin": {
@@ -489,6 +489,29 @@ if (args.includes('--no-install')) {
489
489
  warn(`未知平台 ${process.platform},跳过安装`);
490
490
  }
491
491
 
492
+ // ---- 7.5 同步技能副本 ------------------------------------------------------
493
+ // 装完 App 不等于"agent 也用上新版":agent 读的是 ~/.workbuddy/skills 这些
494
+ // 副本,而这个副本只有 `skill install` 才会刷。发版不刷 = 用户以为更新了,
495
+ // agent 还按几个版本前的说明干活(2026-11-29 实测:三个客户端 9 个副本全停在
496
+ // 2.5.9,仓库已经是 2.6.2)。技能里的操作指引一改,这条链就断在这儿。
497
+ step('同步技能副本到各 agent 客户端');
498
+ if (args.includes('--no-install')) {
499
+ warn('--no-install:跳过技能同步');
500
+ } else {
501
+ const sk = spawnSync(process.execPath, ['scripts/skill.cjs', 'install'], {
502
+ cwd: ROOT, encoding: 'utf8',
503
+ });
504
+ const skOut = `${sk.stdout || ''}${sk.stderr || ''}`;
505
+ if (sk.status === 0) {
506
+ const m = skOut.match(/更新了\s*(\d+)\s*个技能/);
507
+ ok(m ? `已同步 ${m[1]} 个技能副本` : '技能副本本来就是最新的');
508
+ mark('技能同步');
509
+ } else {
510
+ warn('技能同步失败(不影响产物;用户可运行 ai-browser skill install):'
511
+ + skOut.split('\n').filter(Boolean).slice(-2).join(' | '));
512
+ }
513
+ }
514
+
492
515
  // ---- 8. 验收"装好的那个 App" ----------------------------------------------
493
516
  // 前面每一步验的都是"仓库里的东西":测试跑 dev 树、verify_build 比 asar 里的
494
517
  // 字节。但用户双击的是安装后的那个包,**没有人跑过它**。
package/scripts/skill.cjs CHANGED
@@ -284,6 +284,12 @@ function run(argv) {
284
284
  return 2;
285
285
  }
286
286
 
287
+ // 直接 `node scripts/skill.cjs install` 也能跑:发版脚本要在装完 App 之后
288
+ // 顺手把技能副本刷一遍(否则用户"更新了浏览器",agent 读到的还是旧说明)。
289
+ if (require.main === module) {
290
+ process.exitCode = run(process.argv.slice(2));
291
+ }
292
+
287
293
  module.exports = {
288
294
  run,
289
295
  listSkills,
@@ -7,45 +7,46 @@ description: >-
7
7
 
8
8
  # ai-browser
9
9
 
10
- > 任务根本不碰网页?直接回用户「这个不需要浏览器」,别硬用。
10
+ 不碰网页?回「不需要浏览器」,别硬用。
11
11
 
12
- ## 兄弟技能(并列,不在本文件里)
12
+ ## 兄弟技能(并列)
13
13
 
14
- - 发文章(CSDN / 知乎 / 掘金 / 公众号)→ `content-publish` 技能
15
- - 提取文章正文 → `read-webpage` 技能
16
- - 抓请求 / 看登录后的接口 → `references/network.md`
14
+ - 发文章(CSDN/知乎/掘金/公众号)→ `content-publish` 技能
15
+ - 读文章正文 → `read-webpage` 技能
17
16
 
18
- ## 两条路
19
-
20
- 工具在就 `browse_navigate {"url":"https://example.com"}`;不在走 CLI(没这命令就加 `npx -y @glittering0717/ai-browser`):
17
+ ## 顺序:读树 → 点 id
21
18
 
22
19
  ```
23
- ai-browser call ui.get_tree '{"subset":"interactive"}' # 读页面
24
- ai-browser call ui.act '{"action":"click","target":"e:a-3"}' # 点它
20
+ browse_navigate {"url":"https://example.com"}
21
+ browse_get_tree {"subset":"interactive"} // 先这个形态,不够再 full
22
+ browse_act {"action":"click","target":"e:a-3"} // target 只认树里的 id,传文字报 target_not_found
25
23
  ```
26
24
 
27
- 方法名 = 工具名把 `browse_` 换成 `ui.`(tabs 等例外)。
28
-
29
- ## 你的标签组
25
+ 改内容也走 `act`(type/setContent)。**别用** `evaluate` 里的 `el.value=`、`el.click()`
26
+ 抄近路:绕过合成事件,页面看着变了、提交的仍是旧值(见 `references/hard-pages.md`)。
27
+ 挂着别的浏览器/电脑工具时,网页操作也走这三个。
30
28
 
31
- 第一次动手给你一页**空白工作页**,归你的标签组;省略 `tab` 就打它,用户的页不会被碰。
29
+ 工具不在就 CLI(没这命令加 `npx -y @glittering0717/ai-browser`),方法名 = 工具名把 `browse_` 换成 `ui.`:
32
30
 
33
- 用完的页随手关掉(`browse_tabs {"op":"close","tab":N}`)。组是你这一轮任务的空间,
34
- 页攒着不关就会一直挂在用户的标签栏上(每组上限 8,满了会挤掉最久没用的那页)。
31
+ ```
32
+ ai-browser call ui.get_tree '{"subset":"interactive"}'
33
+ ai-browser call ui.act '{"action":"click","target":"e:a-3"}'
34
+ ```
35
35
 
36
- ## 点东西只认 id
36
+ ## 你的标签组
37
37
 
38
- `act` 的 `target` 只认 `get_tree` 给的 id;传文字会报 `target_not_found`。
38
+ 第一次动手给你一页**空白工作页**(归你的组);省略 `tab` 就打它,不碰用户的页。
39
+ 用完的页随手关掉(`browse_tabs {"op":"close","tab":N}`):上限 8,攒着不关就一直挂在用户标签栏上。
39
40
 
40
- ## 操作后先看 effect_state
41
+ ## 操作后看 effect_state
41
42
 
42
- `committed` 继续|`none` 换 target 或重读树|`unknown` **先重读树**再决定,盲目重试会提交两次。
43
+ `committed` 继续|`none` 换 target 或重读树|`unknown` **先重读树**再决定,盲试会提交两次。
43
44
 
44
45
  ## 卡住时
45
46
 
46
47
  | 现象 | 先做什么 |
47
48
  |---|---|
48
- | 树里没有要点的东西 | 等 `{"condition":"text_contains","text":"关键词"}` 再重读 |
49
+ | 树里没有要点 | 等 `{"condition":"text_contains","text":"关键词"}` 再重读 |
49
50
  | `target_not_found` + `stale_ref` | 页面变了 → 重读树拿新 id |
50
51
  | `target_not_found` + `never_seen` | id 本身错 → 别重读,改参数 |
51
52
  | 点了没反应 | `screenshot` 看画面;`network_list` 看请求 |
@@ -58,9 +59,6 @@ ai-browser call ui.act '{"action":"click","target":"e:a-3"}' # 点它
58
59
 
59
60
  ## 按需深挖
60
61
 
61
- - `references/tabs.md` — 标签组 / 人接管
62
- - `references/cli.md` — CLI 全量
63
- - `references/troubleshooting.md` — 排查
64
- - `references/hard-pages.md` — 难搞页面
65
- - `references/network.md` — 抓请求 / 接口
66
- - `references/tasks.md` — 发文章 / 读正文
62
+ - `references/tabs.md` 标签组/人接管 · `references/cli.md` CLI 全量
63
+ - `references/hard-pages.md` 难搞页面/表单 · `references/network.md` 抓请求
64
+ - `references/tasks.md` 发文章/读正文 · `references/troubleshooting.md` 排查
@@ -1,5 +1,32 @@
1
1
  # 难搞的页面
2
2
 
3
+ ## 表单与输入(改完点保存,提交的还是旧值)
4
+
5
+ **不要用 `browse_evaluate` 里的 `el.value = "…"` / `el.click()` 代替 `browse_act`。**
6
+ 三个坑叠在一起,任何一个都足以让你"改成功了、保存不上去":
7
+
8
+ 1. **值没进框架状态。** React 受控输入把值放在 `_valueTracker` 里。直接赋 `el.value` 只改 DOM 表象,
9
+ 下一次渲染就被改回去;即便补一个 `input` 事件,追踪器也可能认为"值没变"而吞掉 change。
10
+ 2. **键形缺失。** CDP 派发的事件若没有 `code` / `windowsVirtualKeyCode`,页面照样收到 input,
11
+ 但依赖 `keydown`/`keypress` 的组件(联想下拉、金额格式化、输入法组合)不认。
12
+ 3. **没有失焦 = 没有提交。** 不少表单层(如阿里的 `SellOInput`)只在 **blur** 时把内层草稿
13
+ 提交给数据源。实测:type 完内层 Input 已是新值、外层还是旧的,手动 blur 一下整条链立刻刷新。
14
+ 不 blur 就点保存 = POST 出去旧值,页面还把输入框回滚。
15
+
16
+ 所以走这条:
17
+
18
+ ```
19
+ browse_act { action:"setContent", target:"<id>", text:"新标题" } // 覆盖整段
20
+ browse_act { action:"type", target:"<id>", text:"追加" } // 光标处追加
21
+ browse_act { action:"click", target:"<保存按钮 id>" }
22
+ ```
23
+
24
+ `act` 派发完整键形,且输入成功后自动 blur(回执里 `committed_by_blur`)—— 这就是它比
25
+ `evaluate` 可靠的地方。改完先看 `effect_state`,`committed` 才算落地。
26
+
27
+ **验收口径**:页面显示变了不算数,必须 **保存 → 刷新 → 再读**,服务端才是真相。
28
+ 这类页面点保存**可能不发 XHR**,抓不到包 ≠ 没保存。
29
+
3
30
  ## canvas(纯绘制,没有 DOM 节点)
4
31
 
5
32
  **先找应用模型,再退到绘制层。**「图是 canvas」不等于「没有结构」:
@@ -117,7 +117,8 @@ press / drag / wheel / paste / setContent / clear)投递之前,浏览器会
117
117
 
118
118
  ⚠️ 两次都问不到(`AI_BROWSER_INPUT_FOCUS=0`、或 `AI_BROWSER_FOCUS=never` 那种组合)时,
119
119
  动作**不会执行**,回执是 `success:false` + `input_blocked:true` —— 这是"什么都没发生",
120
- 不是"点了没反应"。别重试:换 `ui.evaluate` 走 JS 路径,或先 `ui.window {visible:true}`
120
+ 不是"点了没反应"。别重试:**最后**才换 `ui.evaluate` 走 JS 路径(受控组件可能不认),
121
+ 首选先 `ui.window {visible:true}`
121
122
  把窗口显示出来一次(此后每一页都一路收得到)。看到 `input_blocked` 还照着 success 的
122
123
  经验再点一次,就会把一次点击变成两次。
123
124
 
@@ -26,7 +26,8 @@
26
26
  (通常是你设了 `AI_BROWSER_INPUT_FOCUS=0` 或 `AI_BROWSER_FOCUS=never`)。
27
27
 
28
28
  **照着 success 的经验再点一次,就会把一次点击变成两次。** 三条出路按代价排:
29
- ① 改走 JS 路径(`browse_evaluate` 直接改值 / 派发合成事件 —— 富文本框架可能不认);
29
+ ① **最后**才改走 JS 路径(`browse_evaluate` 派发合成事件 / 直接赋值 —— 富文本和受控组件可能不认,
30
+ 改完一定要"保存 → 刷新 → 再读",别拿页面显示当成功);
30
31
  ② `browse_tabs {"op":"window","visible":true}` 把窗口显示出来**一次**,此后每一页都一路收得到;
31
32
  ③ 去掉那两个 env,让浏览器自己补给那一页一发焦点伪造(默认就是这条,不动 z 序也不抢你的鼠标)。
32
33
 
@@ -27,10 +27,12 @@ export const MCP_INSTRUCTIONS = [
27
27
  'AI Browser is a real, visible browser that you drive on the user\'s behalf.',
28
28
  'Use it whenever a task involves a website: open a page, read what it says, click, fill a form, log in, publish, upload or download, or pull data that sits behind a login.',
29
29
  '',
30
- 'Prefer it over headless or screenshot-driven browser tools when the page needs JS to render, when a session is already logged in, or when the user should be able to watch and take over. The window is a normal app window: the user can click and type in it at any time.',
30
+ 'Prefer it over headless or screenshot-driven browser tools when the page needs JS to render, when a session is already logged in, or when the user should be able to watch and take over. Use it instead of desktop-automation / computer-use tools for anything inside a page. The window is a normal app window: the user can click and type in it at any time.',
31
31
  '',
32
32
  'Loop: browse_navigate {url} -> browse_get_tree {subset:"interactive"} -> browse_act {action, target:<id from the tree>}. Repeat. success:true means the action was dispatched, not that anything changed - use browse_diff when the outcome matters.',
33
33
  '',
34
+ 'To change a field use browse_act (type appends, setContent replaces), not browse_evaluate with el.value = ...: assigning the DOM directly bypasses the framework state and the blur that commits it, so the page looks updated while the save still posts the old text.',
35
+ '',
34
36
  'Never invent a target id or a password. For login, QR scan, captcha or payment, ask the user to do it in the window and continue once they confirm.',
35
37
  '',
36
38
  'If these tools are not registered in this client, the same engine is reachable from a shell: `ai-browser call ui.get_tree \'{"subset":"interactive"}\'`.',
@@ -2,4 +2,4 @@
2
2
  // Kept in JS (not imported from package.json) to avoid Node import-attribute
3
3
  // (JSON module) compatibility issues inside Electron. package.json "version"
4
4
  // is manually synced to this value; tests assert they match.
5
- export const VERSION = '2.6.2';
5
+ export const VERSION = '2.6.3';