@xbrowser/cli 1.35.0 → 1.36.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.
Files changed (35) hide show
  1. package/README.md +137 -80
  2. package/dist/{browser-MLKP72XP.js → browser-IEZOLTHA.js} +1 -1
  3. package/dist/{browser-KY7AIRAB.js → browser-NHQDQRXB.js} +1 -1
  4. package/dist/{browser-RZ7DPBI3.js → browser-XELRNYBL.js} +1 -1
  5. package/dist/{chunk-EGOWDZXP.js → chunk-2IOFJ6A3.js} +2 -2
  6. package/dist/{chunk-VYTQLZAX.js → chunk-5UXRFNXG.js} +28 -2
  7. package/dist/{chunk-QRFM4NOV.js → chunk-7KVH6MQG.js} +78 -6
  8. package/dist/{chunk-BLCBCESM.js → chunk-ENTENDF5.js} +1 -1
  9. package/dist/{chunk-Y2GRCINH.js → chunk-GVJ2UY65.js} +78 -6
  10. package/dist/{chunk-GNLZWHSP.js → chunk-KSB4PMCY.js} +1 -1
  11. package/dist/{chunk-RMYKVZIZ.js → chunk-L6QJUB33.js} +28 -2
  12. package/dist/{chunk-43U5VDLB.js → chunk-PGEZJ6V3.js} +1 -1
  13. package/dist/{chunk-53VZHESL.js → chunk-RL5FFY2Q.js} +2 -2
  14. package/dist/{chunk-WGS3Y6ZV.js → chunk-SBMVECDS.js} +1 -1
  15. package/dist/{chunk-C5ZPXPD7.js → chunk-WGWPWNIA.js} +53 -16
  16. package/dist/chunk-YW4BIJQL.js +489 -0
  17. package/dist/{chunk-JYYKMSFH.js → chunk-ZR4NHTUV.js} +1 -1
  18. package/dist/cli.js +69 -51
  19. package/dist/convert-JNOM6H6A.js +490 -0
  20. package/dist/{convert-R3XXYKC6.js → convert-K6TLQEPX.js} +5 -3
  21. package/dist/{daemon-client-OXKRGLPQ.js → daemon-client-AKQK5IIB.js} +53 -16
  22. package/dist/{daemon-client-Z3NKNZRL.js → daemon-client-BBPQWLUX.js} +3 -1
  23. package/dist/daemon-main.js +101 -15
  24. package/dist/index.d.ts +26 -3
  25. package/dist/index.js +68 -50
  26. package/dist/{run-routes-TFNV5BBR.js → run-routes-64IBBVOX.js} +4 -4
  27. package/dist/{run-routes-SJKVZ34L.js → run-routes-FG4LIACU.js} +4 -4
  28. package/dist/{server-HUSX7EFE.js → server-K22LJBO2.js} +2 -2
  29. package/dist/{server-KSP5H4HD.js → server-ZHZDJJMG.js} +2 -2
  30. package/dist/{session-recorder-RUNQOJ7T.js → session-recorder-CNTY5KXF.js} +1 -1
  31. package/dist/{session-recorder-N7VEKJVW.js → session-recorder-KMKSQWEP.js} +1 -1
  32. package/dist/{viewer-routes-YOS5GTCV.js → viewer-routes-CEO7HWCB.js} +2 -2
  33. package/package.json +3 -2
  34. package/dist/chunk-ETCO4SNK.js +0 -206
  35. package/dist/convert-LB3GJTLR.js +0 -207
package/README.md CHANGED
@@ -1,33 +1,74 @@
1
1
  # xbrowser
2
2
 
3
- > **Browser automation CLI** for web scraping, headless browsing, SEO analysis, and AI agent workflows. 57 commands, 132 plugins. A command-line alternative to Playwright, Puppeteer, and Selenium — **no code required**.
3
+ > **Scraping a page, filling in a form, or grabbing a screenshot shouldn't take a Playwright project — environment setup, a script, and selectors to maintain.**
4
+ > **xbrowser turns each one into a single command line.** No code to write: run it in your terminal, chain steps together, or let your AI agent call it.
5
+ >
6
+ > **抓取一个页面、填写一张表单、截一张图,不该为此搭一个 Playwright 工程——配环境、写脚本,还要长期维护选择器。**
7
+ > **xbrowser 把每一件事都变成一行命令。** 不用写代码:终端里直接跑,多步用命令链串起来,也可以让 AI Agent 直接调用。
4
8
 
5
9
  [![CI Status](https://github.com/dyyz1993/xbrowser/workflows/CI/badge.svg)](https://github.com/dyyz1993/xbrowser/actions)
6
10
  [![codecov](https://codecov.io/gh/dyyz1993/xbrowser/branch/master/graph/badge.svg)](https://codecov.io/gh/dyyz1993/xbrowser)
7
11
  [![npm version](https://img.shields.io/npm/v/@xbrowser/cli.svg)](https://www.npmjs.com/package/@xbrowser/cli)
8
12
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
9
13
 
14
+ ## Features
15
+
16
+ - **One command instead of a script** — 59 built-in commands (`scrape`, `click`, `fill`, `search`, `screenshot`, …), each a one-liner
17
+ - **Command chains** — string steps together with `&&`, `->`, `,`, `+`, `||`, or pipe and heredoc a whole workflow
18
+ - **Record & replay** — record a flow once to YAML, replay it in CI or export it as a standalone Playwright script; stale selectors re-resolve themselves ([self-healing replay](docs/recording.md))
19
+ - **126 site plugins** — publish, search, and collect on real sites (Dev.to, Juejin, CSDN, GitHub, …), one plugin per site: `xbrowser plugin install <name>`, or scaffold your own with `xbrowser create my-plugin`
20
+ - **Built for AI agents** — built-in MCP server (`xbrowser mcp`), `--json` output, token-friendly page snapshots
21
+ - **Use the browser you already have** — attach to a running Chrome over CDP and keep your logins; multi-session, daemon mode, and a [stealth layer](docs/stealth.md)
22
+
10
23
  ## 特性
11
24
 
12
- - **57 浏览器命令** — 导航、交互、查询、存储、截图,覆盖常见自动化场景
13
- - **命令链** — 用 `&&`、`,`、`+`、`->`、`;` 串联多个命令,一行搞定复杂流程
14
- - **管道 & Heredoc** — 支持 stdin 管道和 heredoc 批量执行
15
- - **录制 / 回放** — 录制浏览器操作为 YAML,随时回放,可转换为 JS/Python/Bash 脚本
16
- - **插件系统** — 基于 `@dyyz1993/xcli-core`,用 TypeScript 编写站点插件。快速开始:`xbrowser create my-plugin --template static`
17
- - **CDP 连接** — 连接已运行的 Chrome/Chromium,无需重新启动浏览器
18
- - **会话管理** — 多会话并行,独立上下文
19
- - **Daemon 模式** — 后台常驻,快速响应
20
- - **Stealth 伪装层** — UA-CH 档案驱动垫片 + 可配置 stealthConfig(详见 [docs/stealth.md](docs/stealth.md))
25
+ - **一条命令替代一个脚本** — 59 个内置命令(`scrape`、`click`、`fill`、`search`、`screenshot` 等),每个都是一行
26
+ - **命令链** — 用 `&&`、`->`、`,`、`+`、`||` 串联多步,整条流程也可以走管道和 Heredoc
27
+ - **录制 / 回放** — 录一次存成 YAML,CI 里随时回放,也可导出成独立的 Playwright 脚本;选择器失效会自动重新定位([自愈回放](docs/recording.md))
28
+ - **126 个站点插件** — 在真实站点上发布、搜索、采集(Dev.to、掘金、CSDN、GitHub 等),一个站点一个插件:`xbrowser plugin install <name>` 安装,或用 `xbrowser create my-plugin` 脚手架写自己的
29
+ - **为 AI Agent 而生** — 内置 MCP Server(`xbrowser mcp`)、`--json` 输出、对 token 友好的页面快照
30
+ - **复用你已有的浏览器** — 通过 CDP 连接正在运行的 Chrome、保留登录态;多会话并行、Daemon 常驻、[Stealth 伪装层](docs/stealth.md)
31
+
32
+ ## Quick start
33
+
34
+ ```bash
35
+ # Install — needs Node.js >= 18 and a local Chrome or Chromium (auto-detected on macOS/Linux)
36
+ npm install -g @xbrowser/cli
37
+
38
+ # Three steps, one line, zero scripts
39
+ xbrowser "goto https://example.com && title && screenshot"
40
+ ```
41
+
42
+ ```text
43
+ [OK] goto https://example.com
44
+ url: https://example.com
45
+ status: 200
46
+ [OK] title
47
+ title: Example Domain
48
+ [OK] screenshot
49
+ output: …/xbrowser/screenshots/screenshot-….png
50
+ ```
51
+
52
+ Want your AI agent to drive the browser instead?
53
+
54
+ ```bash
55
+ claude mcp add xbrowser -- xbrowser mcp
56
+ ```
57
+
58
+ Full guide: [快速开始](#快速开始) · More recipes: [Use Cases](#use-cases)
21
59
 
22
60
  ## Use Cases
23
61
 
24
62
  **Web Scraping & Data Extraction**
25
63
  ```bash
26
64
  # Scrape any page to Markdown — no Playwright scripts needed
27
- xbrowser scrape https://news.ycombinator.com --mode smart --output markdown
65
+ xbrowser scrape https://news.ycombinator.com --format markdown
66
+
67
+ # Or pull the tables out as structured data
68
+ xbrowser scrape https://news.ycombinator.com --mode smart
28
69
 
29
70
  # Crawl an entire site
30
- xbrowser crawl https://example.com --max-depth 3 --output json
71
+ xbrowser crawl https://example.com --maxDepth 3 --format markdown
31
72
  ```
32
73
 
33
74
  **Search Engine Automation**
@@ -36,24 +77,26 @@ xbrowser crawl https://example.com --max-depth 3 --output json
36
77
  xbrowser search "best headless browser CLI" --engine google --limit 10 --json
37
78
 
38
79
  # Time-filtered search
39
- xbrowser search "playwright alternative 2025" --engine bing --time-filter month
80
+ xbrowser search "playwright alternative 2025" --engine bing --recency month
40
81
  ```
41
82
 
42
83
  **Browser Automation for AI Agents**
43
84
  ```bash
44
85
  # Record browser actions, replay in CI/CD
45
- xbrowser record --output workflow.yaml
86
+ xbrowser record start --url https://example.com --name my-flow
87
+ # …click through the flow in the browser, then:
88
+ xbrowser record stop --output workflow.yaml
46
89
  xbrowser replay workflow.yaml
47
90
 
48
91
  # Chain commands for complex workflows
49
- xbrowser "goto https://example.com && wait .content && text --selector .content"
92
+ xbrowser "goto https://news.ycombinator.com && wait .titleline && text --selector '.titleline > a'"
50
93
  ```
51
94
 
52
95
  **SEO & Backlink Automation**
53
96
  ```bash
54
97
  # Publish articles to SEO platforms via site plugins
55
- xbrowser devto publish --file article.md
56
- xbrowser juejin publish --file article.md
98
+ xbrowser devto publish --title "My article" --file article.md
99
+ xbrowser juejin publish --title "My article" --file article.md
57
100
  # (Each platform has its own plugin — run `xbrowser plugin list` to see available)
58
101
  ```
59
102
 
@@ -68,8 +111,8 @@ xbrowser content draft --case self-healing-replay --lang zh
68
111
  # Render an OG cover image with the browser itself — zero imaging libraries
69
112
  xbrowser "set-viewport 1200 630 && content cover --title 'Self-Healing Replay' --output cover.png"
70
113
 
71
- # Publish through any of the 18 platform plugins
72
- xbrowser devto publish --file output/content/self-healing-replay-en.md --tags "typescript,automation"
114
+ # Publish through a platform plugin
115
+ xbrowser devto publish --title "Self-Healing Replay" --file output/content/self-healing-replay-en.md --tags "typescript,automation"
73
116
  ```
74
117
  The full write → cover → publish loop that promotes xbrowser is itself built on xbrowser commands.
75
118
 
@@ -86,7 +129,7 @@ npm install -g @xbrowser/cli
86
129
  ### 最低要求
87
130
 
88
131
  - Node.js >= 18
89
- - Chromium 浏览器(默认路径 `/Applications/Chromium.app/Contents/MacOS/Chromium`,可通过环境变量 `XBROWSER_CHROMIUM_PATH` 自定义)
132
+ - Chromium 或 Google Chrome(自动探测 macOS / Linux 常见路径,优先 `/Applications/Chromium.app/Contents/MacOS/Chromium`;其它路径用环境变量 `XBROWSER_CHROMIUM_PATH` 指定)
90
133
 
91
134
  ### 第一次使用
92
135
 
@@ -96,12 +139,12 @@ xbrowser goto https://example.com
96
139
 
97
140
  # 获取页面标题
98
141
  xbrowser title
99
- # 输出: Example Domain
142
+ # 输出: title: Example Domain
100
143
 
101
144
  # 获取页面文本
102
145
  xbrowser text
103
146
 
104
- # 截图(保存到当前目录)
147
+ # 截图(默认存到系统临时目录 …/xbrowser/screenshots,用 --output 指定路径)
105
148
  xbrowser screenshot
106
149
 
107
150
  # 关闭会话
@@ -171,8 +214,8 @@ xbrowser -e "goto https://example.com" -e "title"
171
214
  ### CDP 连接(连接已运行的浏览器)
172
215
 
173
216
  ```bash
174
- # 通过 WebSocket URL 连接
175
- xbrowser --cdp ws://localhost:9222 "goto https://example.com , title"
217
+ # 通过 WebSocket URL 连接(<id> 取自 http://localhost:9222/json/version)
218
+ xbrowser --cdp ws://localhost:9222/devtools/browser/<id> "goto https://example.com , title"
176
219
 
177
220
  # 通过端口号连接
178
221
  xbrowser --cdp 9222 "goto https://example.com , title"
@@ -303,7 +346,6 @@ xbrowser --cdp auto "goto https://example.com , title"
303
346
  |------|------|------|
304
347
  | `eval <expression>` | 执行 JS 表达式 | `xbrowser eval "document.title"` |
305
348
  | `eval "1 + 2"` | 计算表达式 | `xbrowser eval "1 + 2"` |
306
- | `eval "(a, b) => a + b" --args 1 2` | 执行带参数的函数 | `xbrowser eval "(a, b) => a + b" --args 1 2` |
307
349
 
308
350
  ### 存储
309
351
 
@@ -357,12 +399,10 @@ xbrowser --cdp auto "goto https://example.com , title"
357
399
 
358
400
  | 命令 | 说明 | 示例 |
359
401
  |------|------|------|
360
- | `convert <rec.yaml> <output>` | 转换录制为脚本 | `xbrowser convert recording.yaml out.js` |
361
- | `convert <rec.yaml> <output.py>` | 生成 Python 脚本 | `xbrowser convert recording.yaml replay.py` |
362
- | `convert <rec.yaml> <output.sh>` | 生成 Bash 脚本 | `xbrowser convert recording.yaml replay.sh` |
402
+ | `convert <rec.yaml> <output.py>` | 转换为 Python + Playwright 脚本 | `xbrowser convert recording.yaml replay.py` |
363
403
  | `extract <rec.yaml>` | 提取 LLM 摘要 | `xbrowser extract recording.yaml` |
364
404
  | `filter <in.yaml> <out.yaml>` | 过滤录制事件 | `xbrowser filter raw.yaml clean.yaml` |
365
- | `filter <in.yaml> <out.yaml> --exclude scroll,navigate` | 排除事件类型 | `xbrowser filter raw.yaml clean.yaml --exclude scroll,navigate` |
405
+ | `filter <in.yaml> <out.yaml> --exclude scroll,navigation` | 排除事件类型 | `xbrowser filter raw.yaml clean.yaml --exclude scroll,navigation` |
366
406
 
367
407
  ### 插件管理
368
408
 
@@ -439,8 +479,8 @@ xbrowser create my-plugin --template static --force
439
479
 
440
480
  **注意**:
441
481
  - 命令链中如果包含特殊字符(如 `#`、`>`),需要用引号包裹整个命令链或对单个参数加引号。
442
- - `->` 和 `+` 分隔符要求两边有空格(`goto url -> title` ✅,`goto url->title` ❌)。
443
- - `,` 和 `;` 不要求空格。
482
+ - `,`、`+`、`->`、`&&`、`||` 两边都要有空格(`goto url -> title` ✅,`goto url->title` ❌);`;` 只要求后面有空格(`goto url; title` ✅,`goto url;title` ❌)。
483
+ - 只在分隔符前面留空格(如 `title ,url`)不会被识别成命令链:整串按单条命令执行,后面的命令被静默忽略。
444
484
 
445
485
  ```bash
446
486
  # 正确 — 整体引号
@@ -565,22 +605,22 @@ export default function (xcli: XCLIAPI): void {
565
605
  }
566
606
  ```
567
607
 
568
- ### 内置插件
608
+ ### 常用插件
569
609
 
570
- xbrowser 自带以下插件:
610
+ 插件不随 npm 包分发,按需安装:`xbrowser plugin install <name>`(npm 优先,未命中时回退 xbrowser.dev 市场)。几个例子:
571
611
 
572
612
  | 插件 | 命令 | 说明 |
573
613
  |------|------|------|
574
614
  | **baidu** | `search`, `hotsearch`, `suggest`, `news` | 百度搜索、热搜、建议词、新闻 |
575
- | **douyin** | `ai-summary`, `user-info`, `video-info` | 抖音视频信息提取 |
576
- | **github** | `update-profile`, `add-social-link`, `create-gist`, `get-profile` | GitHub 个人资料管理 |
577
- | **web-automation** | `extract`, `paginate`, `fill-and-submit`, `screenshot` | 通用 Web 自动化工具 |
615
+ | **douyin** | `videos`, `profile`, `detail`, `comments`, `search`, `download`, `ai-subtitle` | 抖音数据采集:作品、资料、评论、下载、AI 字幕 |
616
+ | **github** | `update-profile`, `add-social-link`, `create-gist`, `get-profile`, `create-repo`, `edit-readme` | GitHub 个人资料与仓库管理 |
578
617
  | **content** | `cases`, `draft`, `cover` | 内容营销:内置推广 case 渲染成文 + 浏览器自渲染封面 |
579
618
 
580
619
  使用插件命令:
581
620
 
582
621
  ```bash
583
- # 百度搜索
622
+ # 安装并使用百度搜索插件
623
+ xbrowser plugin install baidu
584
624
  xbrowser goto https://www.baidu.com
585
625
  xbrowser baidu search --query "AI 编程"
586
626
 
@@ -609,32 +649,44 @@ xbrowser record start --url https://example.com
609
649
  xbrowser record stop --output recordings/my-session.yaml
610
650
  ```
611
651
 
612
- 录制文件格式(YAML):
652
+ 录制文件格式(YAML)——由 `xbrowser record stop` 生成,下面是删减后的真实样例:
613
653
 
614
654
  ```yaml
615
- id: "abc-123"
616
- name: "my-session"
617
- startUrl: "https://example.com"
618
- startTime: "2025-01-01T00:00:00.000Z"
619
- duration: 15000
620
- events:
621
- - type: click
622
- selector: "#button"
623
- tagName: "button"
624
- timestamp: 1000
625
- pageState:
626
- url: "https://example.com"
627
- title: "Example"
628
- - type: input
629
- selector: "#search"
630
- data:
631
- value: "hello world"
632
- timestamp: 3000
633
- - type: scroll
634
- data:
635
- x: 0
636
- y: 500
637
- timestamp: 5000
655
+ startUrl: https://example.com
656
+ sessionName: my-session
657
+ startedAt: "2026-11-23T14:36:13.891Z"
658
+ actions:
659
+ - id: 1
660
+ type: navigation
661
+ timestamp: 1795444573943
662
+ url: https://example.com
663
+ pageTitle: Example Domain
664
+ - id: 2
665
+ type: cdp-fill # 经 CLI 下发的 fill;页面里的手动操作记为 input / click
666
+ timestamp: 1795444586890
667
+ url: https://example.com
668
+ element:
669
+ tag: input
670
+ selector: "#name"
671
+ strategy: id
672
+ confidence: high
673
+ value: Alice
674
+ snapshots:
675
+ png: .tmp/snapshots/step-002-after.png
676
+ aria: "input: | button: Submit"
677
+ - id: 3
678
+ type: click
679
+ timestamp: 1795444589184
680
+ url: https://example.com
681
+ element:
682
+ tag: button
683
+ selector: "#submit"
684
+ strategy: id
685
+ confidence: high
686
+ x: 224.4
687
+ y: 119.4
688
+ network: [] # 每个请求一条:method / url / status / resourceType
689
+ contextChanges: [] # 导航、弹窗等上下文变化
638
690
  ```
639
691
 
640
692
  ### 回放
@@ -649,22 +701,26 @@ xbrowser replay recordings/my-session.yaml --slow-mo 100
649
701
 
650
702
  ### 转换为脚本
651
703
 
652
- 录制文件可转换为独立的 JS/Python/Bash 脚本:
704
+ 录制文件可转换为三种独立运行的脚本,回放的步骤相同:
653
705
 
654
706
  ```bash
655
- # 生成 Node.js + Playwright 脚本
656
- xbrowser convert recordings/my-session.yaml replay.js
657
- node replay.js
658
-
659
- # 生成 Python + Playwright 脚本
707
+ # Python + Playwright
660
708
  xbrowser convert recordings/my-session.yaml replay.py
661
- python3 replay.py
709
+ python3 replay.py # 需要 pip install playwright && playwright install chromium
662
710
 
663
- # 生成 Bash + curl 脚本(基于 CDP)
711
+ # Node.js + Playwright
712
+ xbrowser convert recordings/my-session.yaml replay.js
713
+ node replay.js # 需要 npm install playwright && npx playwright install chromium
714
+
715
+ # Bash:通过 xbrowser CLI 在同一个会话里回放,任何一步失败都会停止并关闭会话
664
716
  xbrowser convert recordings/my-session.yaml replay.sh
665
717
  bash replay.sh
666
718
  ```
667
719
 
720
+ JS / Python 脚本设置 `XBROWSER_CHROMIUM_PATH` 可以直接复用已安装的 Chrome / Chromium,不必再下载 Playwright 自带的浏览器。
721
+
722
+ 转换时会把录制归一化成真正的操作步骤:同一个动作在录制里留下的多条记录(命令与页面信号各记一次、`fill` 的聚焦点击、由点击引起的跳转、滚动信号的命令回显)都只算一步。
723
+
668
724
  ### 提取摘要
669
725
 
670
726
  ```bash
@@ -696,11 +752,11 @@ Key operations:
696
752
  ### 过滤事件
697
753
 
698
754
  ```bash
699
- # 排除滚动和导航事件
700
- xbrowser filter raw.yaml clean.yaml --exclude scroll,navigate,page_load
755
+ # 排除滚动事件
756
+ xbrowser filter raw.yaml clean.yaml --exclude scroll
701
757
 
702
- # 排除悬停事件
703
- xbrowser filter raw.yaml clean.yaml --exclude hover_enter,hover_leave
758
+ # 排除滚动和导航事件
759
+ xbrowser filter raw.yaml clean.yaml --exclude scroll,navigation
704
760
  ```
705
761
 
706
762
  ## 配置
@@ -712,7 +768,7 @@ xbrowser filter raw.yaml clean.yaml --exclude hover_enter,hover_leave
712
768
  | 变量 | 说明 | 默认值 |
713
769
  |------|------|--------|
714
770
  | `XBROWSER_CHROMIUM_PATH` | Chromium 可执行文件路径 | `/Applications/Chromium.app/Contents/MacOS/Chromium` |
715
- | `XBROWSER_DAEMON_PORT` | Daemon 端口 | `9222` |
771
+ | `XBROWSER_DAEMON_PORT` | Daemon 端口 | `9224` |
716
772
  | `XBROWSER_CDP` | 默认 CDP 连接地址(可被 `--cdp` 覆盖) | — |
717
773
  | `XBROWSER_SESSION` | 默认会话名称(可被 `--session` 覆盖) | `default` |
718
774
 
@@ -876,7 +932,7 @@ npm run validate
876
932
  | 依赖 | 用途 |
877
933
  |------|------|
878
934
  | **@dyyz1993/xcli-core** | CLI 框架核心(命令注册、Scope、输出格式化、插件加载) |
879
- | **playwright** | 浏览器自动化引擎(含 CDP 连接) |
935
+ | **ws** | CDP WebSocket 连接(浏览器驱动是自研的 `src/cdp-driver/`,不依赖 Playwright) |
880
936
  | **zod** | 参数校验 Schema |
881
937
  | **yaml** | 录制文件读写 |
882
938
 
@@ -885,7 +941,7 @@ npm run validate
885
941
  ```
886
942
  xbrowser/
887
943
  ├── src/
888
- │ ├── commands/ # 51 个浏览器命令定义
944
+ │ ├── commands/ # 59 个浏览器命令定义
889
945
  │ ├── builtins/ # CLI 内置命令(config, plugin, session, create)
890
946
  │ ├── recorder/ # 录制引擎(录制器 + 回放器)
891
947
  │ ├── session/ # 会话管理
@@ -896,12 +952,13 @@ xbrowser/
896
952
  │ ├── executor.ts # 命令执行器
897
953
  │ ├── chain-parser.ts # 命令链解析器
898
954
  │ ├── browser.ts # 浏览器管理(启动、CDP 连接)
955
+ │ ├── cdp-driver/ # 自研 CDP 驱动(连接、输入、定位器,不依赖 Playwright)
899
956
  │ ├── context.ts # 命令上下文(BrowserCommandContext)
900
957
  │ ├── scope.ts # Scope 定义
901
958
  │ └── config.ts # 配置管理
902
959
  ├── bin/
903
960
  │ └── cli.ts # CLI 入口
904
- ├── .xcli/plugins/ # 内置插件(baidu, douyin, github, web-automation)
961
+ ├── .xcli/plugins/ # 站点插件(126 个)
905
962
  ├── tests/ # 测试
906
963
  └── docs/ # 文档
907
964
  ```
@@ -914,12 +971,12 @@ xbrowser/
914
971
  | **Setup** | `npm i -g` — 0 config | Install + browser download | Install + browser download | Install + WebDriver + drivers |
915
972
  | **Web Scraping** | Built-in (`scrape`, `crawl`, `map`) | Write custom scripts | Write custom scripts | Write custom scripts |
916
973
  | **Search** | Built-in multi-engine (`search`) | No | No | No |
917
- | **Plugin Ecosystem** | 132 plugins | Limited | Limited | No |
974
+ | **Plugin Ecosystem** | 126 plugins | Limited | Limited | No |
918
975
  | **No Code Required** | ✅ CLI commands | ❌ Must write JS/TS | ❌ Must write JS/TS | ❌ Must write code |
919
976
  | **Headless Mode** | ✅ Default | ✅ | ✅ | ✅ |
920
977
  | **Record/Replay** | ✅ Built-in (`record`/`replay`) | ✅ Codegen | ❌ | ❌ |
921
978
  | **Anti-Detection** | ✅ CDP firewall | ❌ | ❌ | ❌ |
922
- | **AI Agent Integration** | ✅ Built-in plugins | Manual integration | Manual integration | Manual integration |
979
+ | **AI Agent Integration** | ✅ Built-in MCP server + plugins | Manual integration | Manual integration | Manual integration |
923
980
 
924
981
  **When to use xbrowser:**
925
982
  - You want to **automate browsers from the command line** without writing code
@@ -938,7 +995,7 @@ xbrowser/
938
995
  |------|------|------|
939
996
  | **@dyyz1993/xcli-core** | 通用 CLI 框架 | xbrowser 依赖的核心框架 |
940
997
  | **@dyyz1993/xpage (mpage)** | 浏览器自动化引擎 | 独立项目,xbrowser **不依赖** mpage |
941
- | **xbrowser** | 浏览器自动化 CLI | 自包含,直接使用 Playwright |
998
+ | **xbrowser** | 浏览器自动化 CLI | 自包含,自带 CDP 驱动(不依赖 Playwright) |
942
999
 
943
1000
  ## 🔑 Keywords
944
1001
 
@@ -21,7 +21,7 @@ import {
21
21
  saveSessionDiskMeta,
22
22
  setActivePage,
23
23
  touchSession
24
- } from "./chunk-43U5VDLB.js";
24
+ } from "./chunk-PGEZJ6V3.js";
25
25
  import "./chunk-ZCZELQCS.js";
26
26
  import "./chunk-A7NEA4PA.js";
27
27
  import "./chunk-SMYSNO4M.js";
@@ -21,7 +21,7 @@ import {
21
21
  saveSessionDiskMeta,
22
22
  setActivePage,
23
23
  touchSession
24
- } from "./chunk-GNLZWHSP.js";
24
+ } from "./chunk-KSB4PMCY.js";
25
25
  import "./chunk-GYGVHWG3.js";
26
26
  import "./chunk-SMYSNO4M.js";
27
27
  import "./chunk-IYCB2KJL.js";
@@ -21,7 +21,7 @@ import {
21
21
  saveSessionDiskMeta,
22
22
  setActivePage,
23
23
  touchSession
24
- } from "./chunk-BLCBCESM.js";
24
+ } from "./chunk-ENTENDF5.js";
25
25
  import "./chunk-6DS3T6UK.js";
26
26
  import "./chunk-SMYSNO4M.js";
27
27
  import "./chunk-IYCB2KJL.js";
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  executeChain
3
- } from "./chunk-QRFM4NOV.js";
3
+ } from "./chunk-7KVH6MQG.js";
4
4
  import {
5
5
  outputEnvelope,
6
6
  outputError
7
7
  } from "./chunk-RGL2YTWQ.js";
8
8
  import {
9
9
  forwardManagedRun
10
- } from "./chunk-C5ZPXPD7.js";
10
+ } from "./chunk-WGWPWNIA.js";
11
11
  import {
12
12
  errMsg
13
13
  } from "./chunk-GDKLH7ZY.js";
@@ -3359,6 +3359,7 @@ var SessionRecorder = class _SessionRecorder {
3359
3359
  if (entry && entry.origin === "signal" && Date.now() < entry.expires) {
3360
3360
  return;
3361
3361
  }
3362
+ this.dedupMap.set(dedupFromAction, { expires: Date.now() + 4e3, origin: "command" });
3362
3363
  }
3363
3364
  this.actionCounter++;
3364
3365
  const ts = Date.now();
@@ -3400,6 +3401,28 @@ var SessionRecorder = class _SessionRecorder {
3400
3401
  this.lastKnownUrl = action.value;
3401
3402
  }
3402
3403
  }
3404
+ /**
3405
+ * Reserve the dedup entry for a command BEFORE it executes. Both sides used
3406
+ * to write their entry only after their awaited captures (element screenshot,
3407
+ * auto-snapshot, click context): a fast click's signal was flushed while the
3408
+ * command was still in flight, found no 'command' entry and recorded itself,
3409
+ * and the command then found no 'signal' entry and recorded again.
3410
+ * Returns an undo for commands that end up recording nothing (failed or
3411
+ * thrown) — a reservation left behind would swallow a later real action on
3412
+ * the same element. A live 'signal' entry is kept: the real action was
3413
+ * already recorded and must still suppress the duplicate command action.
3414
+ */
3415
+ reserveCommandAction(action) {
3416
+ const key = this.dedupKey(action.type, action.selector, void 0, action.value);
3417
+ const entry = this.dedupMap.get(key);
3418
+ if (entry && entry.origin === "signal" && Date.now() < entry.expires) return () => {
3419
+ };
3420
+ const reservation = { expires: Date.now() + 4e3, origin: "command" };
3421
+ this.dedupMap.set(key, reservation);
3422
+ return () => {
3423
+ if (this.dedupMap.get(key) === reservation) this.dedupMap.delete(key);
3424
+ };
3425
+ }
3403
3426
  /** Generate dedup key for an action (normalized type + selector/tag + value). */
3404
3427
  dedupKey(type, selector, tag, value) {
3405
3428
  const normType = type === "cdp-click" ? "click" : type === "cdp-fill" ? "input" : type === "cdp-eval" ? "eval" : type;
@@ -3994,8 +4017,11 @@ var SessionRecorder = class _SessionRecorder {
3994
4017
  this.lastActionTs = raw.ts;
3995
4018
  const dedupKey = this.dedupKey(raw.type, raw.element?.selector, raw.element?.tag, raw.value);
3996
4019
  if (dedupKey) {
3997
- this.dedupMap.set(dedupKey, { expires: Date.now() + 4e3, origin: "signal" });
3998
- this.dedupActionCount++;
4020
+ const current = this.dedupMap.get(dedupKey);
4021
+ if (!current || current.origin !== "command" || Date.now() >= current.expires) {
4022
+ this.dedupMap.set(dedupKey, { expires: Date.now() + 4e3, origin: "signal" });
4023
+ this.dedupActionCount++;
4024
+ }
3999
4025
  }
4000
4026
  const verifyTypes = /* @__PURE__ */ new Set(["click", "submit", "input", "change", "cdp-click", "cdp-fill"]);
4001
4027
  if (verifyTypes.has(raw.type)) {