@jackwener/opencli 0.4.2 → 0.4.4

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 (65) hide show
  1. package/{CLI-CREATOR.md → CLI-EXPLORER.md} +15 -11
  2. package/CLI-ONESHOT.md +216 -0
  3. package/LICENSE +28 -0
  4. package/README.md +114 -63
  5. package/README.zh-CN.md +115 -63
  6. package/SKILL.md +25 -6
  7. package/dist/browser.d.ts +53 -10
  8. package/dist/browser.js +491 -111
  9. package/dist/browser.test.d.ts +1 -0
  10. package/dist/browser.test.js +56 -0
  11. package/dist/build-manifest.js +4 -0
  12. package/dist/cli-manifest.json +279 -3
  13. package/dist/clis/boss/search.js +186 -30
  14. package/dist/clis/twitter/delete.d.ts +1 -0
  15. package/dist/clis/twitter/delete.js +73 -0
  16. package/dist/clis/twitter/followers.d.ts +1 -0
  17. package/dist/clis/twitter/followers.js +104 -0
  18. package/dist/clis/twitter/following.d.ts +1 -0
  19. package/dist/clis/twitter/following.js +90 -0
  20. package/dist/clis/twitter/like.d.ts +1 -0
  21. package/dist/clis/twitter/like.js +69 -0
  22. package/dist/clis/twitter/notifications.d.ts +1 -0
  23. package/dist/clis/twitter/notifications.js +109 -0
  24. package/dist/clis/twitter/post.d.ts +1 -0
  25. package/dist/clis/twitter/post.js +63 -0
  26. package/dist/clis/twitter/reply.d.ts +1 -0
  27. package/dist/clis/twitter/reply.js +57 -0
  28. package/dist/clis/v2ex/daily.d.ts +1 -0
  29. package/dist/clis/v2ex/daily.js +98 -0
  30. package/dist/clis/v2ex/me.d.ts +1 -0
  31. package/dist/clis/v2ex/me.js +99 -0
  32. package/dist/clis/v2ex/notifications.d.ts +1 -0
  33. package/dist/clis/v2ex/notifications.js +72 -0
  34. package/dist/doctor.d.ts +50 -0
  35. package/dist/doctor.js +372 -0
  36. package/dist/doctor.test.d.ts +1 -0
  37. package/dist/doctor.test.js +114 -0
  38. package/dist/main.js +47 -5
  39. package/dist/output.test.d.ts +1 -0
  40. package/dist/output.test.js +20 -0
  41. package/dist/registry.d.ts +4 -0
  42. package/dist/registry.js +1 -0
  43. package/dist/runtime.d.ts +3 -1
  44. package/dist/runtime.js +2 -2
  45. package/package.json +2 -2
  46. package/src/browser.test.ts +77 -0
  47. package/src/browser.ts +541 -99
  48. package/src/build-manifest.ts +4 -0
  49. package/src/clis/boss/search.ts +196 -29
  50. package/src/clis/twitter/delete.ts +78 -0
  51. package/src/clis/twitter/followers.ts +119 -0
  52. package/src/clis/twitter/following.ts +105 -0
  53. package/src/clis/twitter/like.ts +74 -0
  54. package/src/clis/twitter/notifications.ts +119 -0
  55. package/src/clis/twitter/post.ts +68 -0
  56. package/src/clis/twitter/reply.ts +62 -0
  57. package/src/clis/v2ex/daily.ts +105 -0
  58. package/src/clis/v2ex/me.ts +103 -0
  59. package/src/clis/v2ex/notifications.ts +77 -0
  60. package/src/doctor.test.ts +133 -0
  61. package/src/doctor.ts +424 -0
  62. package/src/main.ts +47 -4
  63. package/src/output.test.ts +27 -0
  64. package/src/registry.ts +5 -0
  65. package/src/runtime.ts +2 -1
package/README.zh-CN.md CHANGED
@@ -5,21 +5,84 @@
5
5
 
6
6
  [English](./README.md)
7
7
 
8
- [![npm](https://img.shields.io/npm/v/@jackwener/opencli)](https://www.npmjs.com/package/@jackwener/opencli)
8
+ [![npm](https://img.shields.io/npm/v/@jackwener/opencli?style=flat-square)](https://www.npmjs.com/package/@jackwener/opencli)
9
+ [![Node.js Version](https://img.shields.io/node/v/@jackwener/opencli?style=flat-square)](https://nodejs.org)
10
+ [![License](https://img.shields.io/npm/l/@jackwener/opencli?style=flat-square)](./LICENSE)
9
11
 
10
- OpenCLI 通过 Chrome 浏览器 + [Playwright MCP Bridge](https://github.com/nichochar/playwright-mcp) 扩展,将任何网站变成命令行工具。不存密码、不泄 token,直接复用浏览器已登录状态。
12
+ OpenCLI 通过 Chrome 浏览器 + [Playwright MCP Bridge](https://github.com/nichochar/playwright-mcp) 扩展,将任何网站变成命令行工具。57个内置命令。不存密码、不泄 token,直接复用浏览器已登录状态。
11
13
 
12
- ## ✨ 亮点
14
+ ---
13
15
 
14
- - 🌐 **47 个命令,17 个站点** — B站、知乎、小红书、Twitter、Reddit、雪球(xueqiu)、GitHub、V2EX、Hacker News、BBC、微博、BOSS直聘、Yahoo Finance、路透社、什么值得买、携程、YouTube
15
- - 🔐 **零风控** — 复用 Chrome 登录态,无需存储任何凭证
16
- - 🤖 **AI 原生** — `explore` 自动发现 API,`synthesize` 生成适配器,`cascade` 探测认证策略
17
- - 🚀 **动态加载引擎** — 只需将 `.ts` 或 `.yaml` 适配器放入 `clis/` 文件夹即可自动注册生效
18
- - 📝 **双引擎架构设计**:
19
- - **YAML 声明式引擎**:大部分适配器只需极简的 ~30 行 YAML 声明
20
- - **原生浏览器注入引擎**:提供高级 TS API(`installInterceptor`、`autoScroll`)轻松实现 XHR 劫持、GraphQL 解包及状态库注入
16
+ ## 目录
21
17
 
22
- ## 🚀 快速开始
18
+ - [亮点](#亮点)
19
+ - [前置要求](#前置要求)
20
+ - [快速开始](#快速开始)
21
+ - [内置命令](#内置命令)
22
+ - [输出格式](#输出格式)
23
+ - [致 AI Agent(开发者指南)](#致-ai-agent开发者指南)
24
+ - [常见问题排查](#常见问题排查)
25
+ - [版本发布](#版本发布)
26
+ - [License](#license)
27
+
28
+ ---
29
+
30
+ ## 亮点
31
+
32
+ - **57 个命令,17 个站点** — B站、知乎、小红书、Twitter、Reddit、雪球(xueqiu)、GitHub、V2EX、Hacker News、BBC、微博、BOSS直聘、Yahoo Finance、路透社、什么值得买、携程、YouTube
33
+ - **零风控** — 复用 Chrome 登录态,无需存储任何凭证
34
+ - **AI 原生** — `explore` 自动发现 API,`synthesize` 生成适配器,`cascade` 探测认证策略
35
+ - **动态加载引擎** — 声明式的 `.yaml` 或者底层定制的 `.ts` 适配器,放入 `clis/` 文件夹即可自动注册生效
36
+
37
+ ## 前置要求
38
+
39
+ - **Node.js**: >= 18.0.0
40
+ - **Chrome** 浏览器正在运行,且**已登录目标网站**(如 bilibili.com、zhihu.com、xiaohongshu.com)
41
+
42
+ > **⚠️ 重要**:大多数命令复用你的 Chrome 登录状态。运行命令前,你必须已在 Chrome 中打开目标网站并完成登录。如果获取到空数据或报错,请先检查你的浏览器登录状态。
43
+
44
+ 为了让 OpenCLI 能够联通你的浏览器,你需要配置连接方式。**强烈建议以下两种方式都配置上**,互为后备:
45
+
46
+ ### 连接方式 A:Playwright MCP Bridge 扩展(首选)
47
+
48
+ 1. 安装 **[Playwright MCP Bridge](https://chromewebstore.google.com/detail/playwright-mcp-bridge/mmlmfjhmonkocbjadbfplnigmagldckm)** 扩展
49
+ 2. 在浏览器插件栏点击该插件,或者在插件设置页获取你的 Extension Token。
50
+
51
+ **你必须将这个 Token 同时配置到你的 MCP 配置文件 AND 环境变量中。**
52
+
53
+ 首先,配置你的 MCP 客户端(如 Claude/Cursor 等):
54
+
55
+ ```json
56
+ {
57
+ "mcpServers": {
58
+ "playwright": {
59
+ "command": "npx",
60
+ "args": ["-y", "@playwright/mcp@latest", "--extension"],
61
+ "env": {
62
+ "PLAYWRIGHT_MCP_EXTENSION_TOKEN": "<你的-token>"
63
+ }
64
+ }
65
+ }
66
+ }
67
+ ```
68
+
69
+ 并且,为了让 `opencli` 命令行也能直接使用它,你必须在你的终端系统环境变量中导出它(建议写进 `~/.zshrc` 或 `~/.bashrc`):
70
+
71
+ ```bash
72
+ export PLAYWRIGHT_MCP_EXTENSION_TOKEN="<你的-token>"
73
+ ```
74
+
75
+ ### 连接方式 B:Chrome 144+ CDP 自动发现(备选)
76
+
77
+ 无需安装任何扩展。只需开启 Chrome 内置的远程调试:
78
+
79
+ 1. 在 Chrome 中打开 `chrome://inspect#remote-debugging`
80
+ 2. 勾选 **"允许对此浏览器实例进行远程调试" (Allow remote debugging for this browser instance)**
81
+ 3. 运行时设置环境变量 `OPENCLI_USE_CDP=1`
82
+
83
+ *也可通过 `OPENCLI_CDP_ENDPOINT` 环境变量手动指定 CDP endpoint 地址。*
84
+
85
+ ## 快速开始
23
86
 
24
87
  ### npm 全局安装(推荐)
25
88
 
@@ -31,63 +94,39 @@ npm install -g @jackwener/opencli
31
94
 
32
95
  ```bash
33
96
  opencli list # 查看所有命令
97
+ opencli list -f yaml # 以 YAML 列出所有命令
34
98
  opencli hackernews top --limit 5 # 公共 API,无需浏览器
35
99
  opencli bilibili hot --limit 5 # 浏览器命令
36
100
  opencli zhihu hot -f json # JSON 输出
101
+ opencli zhihu hot -f yaml # YAML 输出
37
102
  ```
38
103
 
39
- ### 从源码安装
104
+ ### 从源码安装(面向开发者)
40
105
 
41
106
  ```bash
42
107
  git clone git@github.com:jackwener/opencli.git
43
- cd opencli && npm install
44
- npx tsx src/main.ts list
108
+ cd opencli
109
+ npm install
110
+ npm run build
111
+ npm link # 链接到全局环境
112
+ opencli list # 可以在任何地方使用了!
45
113
  ```
46
114
 
47
115
  ### 更新
48
116
 
49
117
  ```bash
50
- # npm 全局更新
51
- npm update -g @jackwener/opencli
52
-
53
- # 或直接安装最新版
54
118
  npm install -g @jackwener/opencli@latest
55
119
  ```
56
120
 
57
- ## 📋 前置要求
58
-
59
- 浏览器命令需要:
60
- 1. **Chrome** 浏览器正在运行,且**已登录目标网站**(如 bilibili.com、zhihu.com、xiaohongshu.com)
61
- 2. 安装 **[Playwright MCP Bridge](https://chromewebstore.google.com/detail/playwright-mcp-bridge/mmlmfjhmonkocbjadbfplnigmagldckm)** 扩展
62
- 3. 在 MCP 配置中设置 `PLAYWRIGHT_MCP_EXTENSION_TOKEN`(从扩展设置页获取):
63
-
64
- ```json
65
- {
66
- "mcpServers": {
67
- "playwright": {
68
- "command": "npx",
69
- "args": ["@playwright/mcp@latest", "--extension"],
70
- "env": {
71
- "PLAYWRIGHT_MCP_EXTENSION_TOKEN": "<your-token>"
72
- }
73
- }
74
- }
75
- }
76
- ```
77
-
78
- 公共 API 命令(`hackernews`、`github search`、`v2ex`)无需浏览器。
79
-
80
- > **⚠️ 重要**:浏览器命令复用你的 Chrome 登录状态。运行命令前,你必须已在 Chrome 中登录目标网站。如果获取到空数据或报错,请先检查登录状态。
81
-
82
- ## 📦 内置命令
121
+ ## 内置命令
83
122
 
84
123
  | 站点 | 命令 | 模式 |
85
124
  |------|------|------|
86
- | **bilibili** | `hot` `search` `me` `favorite` `history` `feed` `user-videos` `subtitle` `dynamic` `ranking` `following` | 🔐 浏览器 |
125
+ | **bilibili** | `hot` `search` `me` `favorite` ...(共11个) | 🔐 浏览器 |
87
126
  | **zhihu** | `hot` `search` `question` | 🔐 浏览器 |
88
127
  | **xiaohongshu** | `search` `notifications` `feed` `me` `user` | 🔐 浏览器 |
89
128
  | **xueqiu** | `feed` `hot-stock` `hot` `search` `stock` `watchlist` | 🔐 浏览器 |
90
- | **twitter** | `trending` `bookmarks` `profile` `search` `timeline` | 🔐 浏览器 |
129
+ | **twitter** | `trending` `bookmarks` `profile` `search` `timeline` `following` `followers` `notifications` `post` `reply` `delete` `like` | 🔐 浏览器 |
91
130
  | **reddit** | `hot` `frontpage` `search` `subreddit` | 🔐 浏览器 |
92
131
  | **weibo** | `hot` | 🔐 浏览器 |
93
132
  | **boss** | `search` | 🔐 浏览器 |
@@ -101,17 +140,28 @@ npm install -g @jackwener/opencli@latest
101
140
  | **hackernews** | `top` | 🌐 公共 API |
102
141
  | **bbc** | `news` | 🌐 公共 API |
103
142
 
104
- ## 🎨 输出格式
143
+ ## 输出格式
144
+
145
+ 所有内置命令都支持 `--format` / `-f`,可选值为 `table`、`json`、`yaml`、`md`、`csv`。
146
+ `list` 命令也支持同样的格式参数,同时继续兼容 `--json`。
105
147
 
106
148
  ```bash
107
- opencli bilibili hot -f table # 默认:表格
108
- opencli bilibili hot -f json # JSON(可 pipe 给 jq 或 AI agent)
149
+ opencli list -f yaml # 用 YAML 列出命令注册表
150
+ opencli bilibili hot -f table # 默认:富文本表格
151
+ opencli bilibili hot -f json # JSON(适合传给 jq 或者各类 AI Agent)
152
+ opencli bilibili hot -f yaml # YAML(更适合人类直接阅读)
109
153
  opencli bilibili hot -f md # Markdown
110
154
  opencli bilibili hot -f csv # CSV
111
- opencli bilibili hot -v # 详细模式:展示 pipeline 每步数据
155
+ opencli bilibili hot -v # 详细模式:展示管线执行步骤调试信息
112
156
  ```
113
157
 
114
- ## 🧠 AI Agent 工作流
158
+ ## AI Agent(开发者指南)
159
+
160
+ 如果你是一个被要求查阅代码并编写新 `opencli` 适配器的 AI,请遵守以下工作流。
161
+
162
+ > **快速模式**:只想为某个页面快速生成一个命令?看 [CLI-ONESHOT.md](./CLI-ONESHOT.md) — 给一个 URL + 一句话描述,4 步搞定。
163
+
164
+ > **完整模式**:在编写任何新代码前,先阅读 [CLI-EXPLORER.md](./CLI-EXPLORER.md)。它包含完整的适配器探索开发指南、API 探测流程、5级认证策略以及常见陷阱。
115
165
 
116
166
  ```bash
117
167
  # 1. Deep Explore — 网络拦截 → 响应分析 → 能力推理 → 框架检测
@@ -127,28 +177,30 @@ opencli generate https://example.com --goal "hot"
127
177
  opencli cascade https://api.example.com/data
128
178
  ```
129
179
 
130
- 探索结果输出到 `.opencli/explore/<site>/`:
131
- - `manifest.json` — 站点元数据、框架检测结果
132
- - `endpoints.json` — 评分排序的 API 端点,含响应 schema
133
- - `capabilities.json` — 推理出的能力及置信度
134
- - `auth.json` — 认证策略建议
180
+ 探索结果输出到 `.opencli/explore/<site>/`。
135
181
 
136
- ## 🔧 创建新命令
182
+ ## 常见问题排查
137
183
 
138
- 查看 **[CLI-CREATOR.md](./CLI-CREATOR.md)** 了解完整的适配器开发指南(YAML pipeline + TypeScript)。
184
+ - **"Failed to connect to Playwright MCP Bridge"** 报错
185
+ - 确保你当前的 Chrome 已安装且**开启了** Playwright MCP Bridge 浏览器插件。
186
+ - 如果是刚装完插件,需要重启 Chrome 浏览器。
187
+ - **"CDP command failed" / "被风控拦截"**
188
+ - 有些网站(例如 BOSS 直聘)会因为开了 DevTools 或者 CDP 端口拦截验证。OpenCLI 有 cookie 降级机制,通常不需要干预,不用去强行加上 CDP 标识参数即可。
189
+ - **返回空数据,或者报错 "Unauthorized"**
190
+ - Chrome 里的登录态可能已经过期(甚至被要求过滑动验证码)。请打开当前 Chrome 页面,在新标签页重新手工登录或刷新该页面。
191
+ - **Node API 错误 (如 parseArgs, fs 等)**
192
+ - 确保 Node.js 版本 `>= 18`。旧版不支持我们使用的现代核心库 API。
139
193
 
140
194
  ## 版本发布
141
195
 
142
196
  ```bash
143
- # 升级版本号
144
197
  npm version patch # 0.1.0 → 0.1.1
145
198
  npm version minor # 0.1.0 → 0.2.0
146
- npm version major # 0.1.0 → 1.0.0
147
199
 
148
- # 推送 tag,GitHub Actions 自动发 release 并发布到 npm
200
+ # 推送 tag,GitHub Actions 将自动执行发版和 npm 发布
149
201
  git push --follow-tags
150
202
  ```
151
203
 
152
- ## 📄 License
204
+ ## License
153
205
 
154
- MIT
206
+ [BSD-3-Clause](./LICENSE)
package/SKILL.md CHANGED
@@ -10,6 +10,11 @@ tags: [cli, browser, web, mcp, playwright, bilibili, zhihu, twitter, github, v2e
10
10
 
11
11
  > Make any website your CLI. Reuse Chrome login, zero risk, AI-powered discovery.
12
12
 
13
+ > [!CAUTION]
14
+ > **AI Agent 必读:创建或修改任何适配器之前,你必须先阅读 [CLI-EXPLORER.md](./CLI-EXPLORER.md)!**
15
+ > 该文档包含完整的 API 发现工作流(必须使用 Playwright MCP Bridge 浏览器探索)、5 级认证策略决策树、平台 SDK 速查表、`tap` 步骤调试流程、分页 API 模板、级联请求模式、以及常见陷阱。
16
+ > **本文件(SKILL.md)仅提供命令参考和简化模板,不足以正确开发适配器。**
17
+
13
18
  ## Install & Run
14
19
 
15
20
  ```bash
@@ -29,8 +34,8 @@ npm update -g @jackwener/opencli
29
34
 
30
35
  Browser commands require:
31
36
  1. Chrome browser running **(logged into target sites)**
32
- 2. [Playwright MCP Bridge](https://chromewebstore.google.com/detail/playwright-mcp-bridge/mmlmfjhmonkocbjadbfplnigmagldckm) extension
33
- 3. Configure `PLAYWRIGHT_MCP_EXTENSION_TOKEN` (from extension settings) in your MCP config
37
+ 2. [Playwright MCP Bridge](https://chromewebstore.google.com/detail/playwright-mcp-bridge/mmlmfjhmonkocbjadbfplnigmagldckm) extension (default connection mode)
38
+ 3. **Alternative**: Chrome 144+ CDP auto-discovery — set `OPENCLI_USE_CDP=1` (no extension needed)
34
39
 
35
40
  > **Note**: You must be logged into the target website in Chrome before running commands. Tabs opened during command execution are auto-closed afterwards.
36
41
 
@@ -129,6 +134,7 @@ opencli ctrip search --query "三亚" # 搜索目的地
129
134
  ```bash
130
135
  opencli list # List all commands
131
136
  opencli list --json # JSON output
137
+ opencli list -f yaml # YAML output
132
138
  opencli validate # Validate all CLI definitions
133
139
  opencli validate bilibili # Validate specific site
134
140
  ```
@@ -157,11 +163,14 @@ opencli verify <site/name> --smoke
157
163
 
158
164
  ## Output Formats
159
165
 
160
- All commands support `--format` / `-f`:
166
+ All built-in commands support `--format` / `-f` with `table`, `json`, `yaml`, `md`, and `csv`.
167
+ The `list` command supports the same formats and also keeps `--json` as a compatibility alias.
161
168
 
162
169
  ```bash
170
+ opencli list -f yaml # YAML command registry
163
171
  opencli bilibili hot -f table # Default: rich table
164
172
  opencli bilibili hot -f json # JSON (pipe to jq, feed to AI agent)
173
+ opencli bilibili hot -f yaml # YAML (readable structured output)
165
174
  opencli bilibili hot -f md # Markdown
166
175
  opencli bilibili hot -f csv # CSV
167
176
  ```
@@ -174,6 +183,15 @@ opencli bilibili hot -v # Show each pipeline step and data flow
174
183
 
175
184
  ## Creating Adapters
176
185
 
186
+ > [!TIP]
187
+ > **快速模式**:如果你只想为一个具体页面生成一个命令,直接看 [CLI-ONESHOT.md](./CLI-ONESHOT.md)。
188
+ > 只需要一个 URL + 一句话描述,4 步搞定。
189
+
190
+ > [!IMPORTANT]
191
+ > **完整模式 — 在写任何代码之前,先阅读 [CLI-EXPLORER.md](./CLI-EXPLORER.md)。**
192
+ > 它包含:① AI Agent 浏览器探索工作流(必须用 Playwright MCP 抓包验证 API)② 认证策略决策树 ③ 平台 SDK(如 Bilibili 的 `apiGet`/`fetchJson`)④ YAML vs TS 选择指南 ⑤ `tap` 步骤调试方法 ⑥ 级联请求模板 ⑦ 常见陷阱表。
193
+ > **下方仅为简化模板参考,直接使用极易踩坑。**
194
+
177
195
  ### YAML Pipeline (declarative, recommended)
178
196
 
179
197
  Create `src/clis/<site>/<name>.yaml`:
@@ -321,7 +339,9 @@ ${{ index + 1 }}
321
339
  | `OPENCLI_BROWSER_CONNECT_TIMEOUT` | 30 | Browser connection timeout (sec) |
322
340
  | `OPENCLI_BROWSER_COMMAND_TIMEOUT` | 45 | Command execution timeout (sec) |
323
341
  | `OPENCLI_BROWSER_EXPLORE_TIMEOUT` | 120 | Explore timeout (sec) |
324
- | `OPENCLI_EXTENSION_LOCK_TIMEOUT` | 120 | Extension lock timeout (sec) |
342
+ | `OPENCLI_CDP_ENDPOINT` | | Manual CDP WebSocket endpoint (overrides auto-discovery) |
343
+ | `OPENCLI_USE_CDP` | — | Set to `1` to use Chrome 144+ CDP auto-discovery instead of extension |
344
+ | `OPENCLI_FORCE_EXTENSION` | — | Set to `1` to skip CDP and force extension mode |
325
345
  | `PLAYWRIGHT_MCP_EXTENSION_TOKEN` | — | Auto-approve extension connection |
326
346
 
327
347
  ## Troubleshooting
@@ -329,7 +349,6 @@ ${{ index + 1 }}
329
349
  | Issue | Solution |
330
350
  |-------|----------|
331
351
  | `npx not found` | Install Node.js: `brew install node` |
332
- | `Timed out connecting to browser` | 1) Chrome must be open 2) Install MCP Bridge extension 3) Click to approve |
333
- | `Extension lock timed out` | Another opencli command is running; browser commands run serially |
352
+ | `Timed out connecting to browser` | 1) Chrome must be open 2) Enable remote debugging at `chrome://inspect#remote-debugging` or install MCP Bridge extension |
334
353
  | `Target page context` error | Add `navigate:` step before `evaluate:` in YAML |
335
354
  | Empty table data | Check if evaluate returns JSON string (MCP parsing) or data path is wrong |
package/dist/browser.d.ts CHANGED
@@ -1,15 +1,33 @@
1
1
  /**
2
- * Browser interaction via Playwright MCP Bridge extension.
3
- * Connects to an existing Chrome browser through the extension's stdio JSON-RPC.
2
+ * Browser interaction via Chrome DevTools Protocol.
3
+ * Connects to an existing Chrome browser through CDP auto-discovery or extension bridge.
4
4
  */
5
+ export declare function discoverChromeEndpoint(): Promise<string | null>;
6
+ type ConnectFailureKind = 'missing-token' | 'extension-timeout' | 'extension-not-installed' | 'cdp-timeout' | 'mcp-init' | 'process-exit' | 'unknown';
7
+ type PlaywrightMCPState = 'idle' | 'connecting' | 'connected' | 'closing' | 'closed';
8
+ type ConnectFailureInput = {
9
+ kind: ConnectFailureKind;
10
+ mode: 'extension' | 'cdp';
11
+ timeout: number;
12
+ hasExtensionToken: boolean;
13
+ tokenFingerprint?: string | null;
14
+ stderr?: string;
15
+ exitCode?: number | null;
16
+ rawMessage?: string;
17
+ };
18
+ export declare function getTokenFingerprint(token: string | undefined): string | null;
19
+ export declare function formatBrowserConnectError(input: ConnectFailureInput): Error;
20
+ declare function createJsonRpcRequest(method: string, params?: Record<string, any>): {
21
+ id: number;
22
+ message: string;
23
+ };
5
24
  import type { IPage } from './types.js';
6
25
  /**
7
26
  * Page abstraction wrapping JSON-RPC calls to Playwright MCP.
8
27
  */
9
28
  export declare class Page implements IPage {
10
- private _send;
11
- private _recv;
12
- constructor(_send: (msg: string) => void, _recv: () => Promise<any>);
29
+ private _request;
30
+ constructor(_request: (method: string, params?: Record<string, any>) => Promise<any>);
13
31
  call(method: string, params?: Record<string, any>): Promise<any>;
14
32
  goto(url: string): Promise<void>;
15
33
  evaluate(js: string): Promise<any>;
@@ -46,16 +64,41 @@ export declare class Page implements IPage {
46
64
  * Playwright MCP process manager.
47
65
  */
48
66
  export declare class PlaywrightMCP {
67
+ private static _activeInsts;
68
+ private static _cleanupRegistered;
69
+ private static _registerGlobalCleanup;
49
70
  private _proc;
50
71
  private _buffer;
51
- private _waiters;
52
- private _lockAcquired;
53
- private _initialTabCount;
72
+ private _pending;
73
+ private _initialTabIdentities;
74
+ private _closingPromise;
75
+ private _state;
54
76
  private _page;
77
+ get state(): PlaywrightMCPState;
78
+ private _sendRequest;
79
+ private _rejectPendingRequests;
80
+ private _resetAfterFailedConnect;
55
81
  connect(opts?: {
56
82
  timeout?: number;
83
+ forceExtension?: boolean;
57
84
  }): Promise<Page>;
58
85
  close(): Promise<void>;
59
- private _acquireLock;
60
- private _releaseLock;
61
86
  }
87
+ declare function extractTabEntries(raw: any): Array<{
88
+ index: number;
89
+ identity: string;
90
+ }>;
91
+ declare function diffTabIndexes(initialIdentities: string[], currentTabs: Array<{
92
+ index: number;
93
+ identity: string;
94
+ }>): number[];
95
+ declare function appendLimited(current: string, chunk: string, limit: number): string;
96
+ declare function withTimeout<T>(promise: Promise<T>, timeoutMs: number, message: string): Promise<T>;
97
+ export declare const __test__: {
98
+ createJsonRpcRequest: typeof createJsonRpcRequest;
99
+ extractTabEntries: typeof extractTabEntries;
100
+ diffTabIndexes: typeof diffTabIndexes;
101
+ appendLimited: typeof appendLimited;
102
+ withTimeout: typeof withTimeout;
103
+ };
104
+ export {};