ghost-bridge 0.4.0 → 0.5.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/LICENSE +21 -0
- package/README.md +160 -133
- package/dist/cli.js +649 -448
- package/dist/server.js +136 -42
- package/extension/background.js +257 -51
- package/extension/icon-128.png +0 -0
- package/extension/icon-16.png +0 -0
- package/extension/icon-48.png +0 -0
- package/extension/manifest.json +2 -2
- package/extension/offscreen.js +1 -1
- package/extension/popup.html +388 -86
- package/extension/popup.js +128 -53
- package/package.json +25 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 <Author>
|
|
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.md
CHANGED
|
@@ -1,156 +1,183 @@
|
|
|
1
|
-
# Ghost Bridge
|
|
1
|
+
# 👻 Ghost Bridge
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/ghost-bridge)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
> **Zero-restart Chrome AI Copilot** — Subvert your workflow. Allow AI to seamlessly take over the browser you're already using, enabling real-time debugging, visual observation, and interactive manipulation without launching a new Chrome instance.
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
- 🔍 **无 sourcemap 调试** — 片段截取、字符串搜索、覆盖率分析,在压缩代码中定位问题
|
|
9
|
-
- 🌐 **网络请求分析** — 完整记录请求/响应,支持多维度过滤和响应体查看
|
|
10
|
-
- 📸 **页面截图与内容提取** — 视觉分析 + 结构化数据提取
|
|
11
|
-
- 🎯 **DOM 交互操控** — AI 可直接点击按钮、填写表单、按键提交,使用 CDP 物理级模拟,兼容 React/Vue/Angular
|
|
12
|
-
- 📊 **性能诊断** — JS 堆内存、DOM 规模、Layout 开销、Web Vitals、资源加载分析
|
|
13
|
-
- 🔄 **多实例支持** — 自动单例管理,多个 MCP 客户端共享同一 Chrome 连接
|
|
8
|
+
---
|
|
14
9
|
|
|
15
|
-
##
|
|
10
|
+
## ✨ Why Ghost Bridge?
|
|
16
11
|
|
|
17
|
-
|
|
12
|
+
- 🔌 **Zero-Config Attach** — Bypasses the need for `--remote-debugging-port`. Captures Chrome's native DevTools Protocol directly via an extension.
|
|
13
|
+
- 🔍 **No-Sourcemap Debugging** — Slice code fragments, perform string searches, and analyze coverage to pinpoint bugs straight in minified production code.
|
|
14
|
+
- 🌐 **Deep Network Analysis** — Comprehensive capture of requests/responses with multi-dimensional filtering and response body inspection.
|
|
15
|
+
- 📸 **Visual & Structural Perception** — Full-page or clipped high-fidelity screenshots paired with structural data extraction (titles, links, forms, buttons).
|
|
16
|
+
- 🎯 **DOM Physical Manipulation** — Empowers AI to click, type, and form-submit with CDP-level physical simulation. Fully compatible with complex SPAs (React/Vue/Angular/Svelte).
|
|
17
|
+
- 📊 **Performance Diagnostics** — Get granular engine metrics: JS Heap, Layout recalculations, Web Vitals (TTFB/FCP/LCP), and resource loading speeds.
|
|
18
|
+
- 🔄 **Multi-Client Mastery** — Built-in singleton manager automatically coordinates multiple MCP clients sharing a single Chrome transport.
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
# 全局安装
|
|
21
|
-
npm install -g ghost-bridge
|
|
22
|
-
|
|
23
|
-
# 自动配置 Claude MCP 并准备扩展
|
|
24
|
-
ghost-bridge init
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
### 2. 加载 Chrome 扩展
|
|
28
|
-
|
|
29
|
-
1. 打开 Chrome,访问 `chrome://extensions`
|
|
30
|
-
2. 开启右上角的 **开发者模式**
|
|
31
|
-
3. 点击 **加载已解压的扩展程序**
|
|
32
|
-
4. 选择目录:`~/.ghost-bridge/extension`
|
|
33
|
-
|
|
34
|
-
> 💡 运行 `ghost-bridge extension --open` 可直接打开该目录
|
|
35
|
-
|
|
36
|
-
### 3. 连接并使用
|
|
37
|
-
|
|
38
|
-
1. 点击浏览器工具栏中的 Ghost Bridge 图标
|
|
39
|
-
2. 点击 **连接**,等待状态变为 ✅ 已连接
|
|
40
|
-
3. 打开 Claude Desktop 或 Claude CLI,即可使用所有调试工具
|
|
41
|
-
|
|
42
|
-
## CLI 命令
|
|
43
|
-
|
|
44
|
-
| 命令 | 说明 |
|
|
45
|
-
|------|------|
|
|
46
|
-
| `ghost-bridge init` | 配置 MCP 并复制扩展文件 |
|
|
47
|
-
| `ghost-bridge status` | 检查配置状态 |
|
|
48
|
-
| `ghost-bridge extension` | 显示扩展安装路径(`--open` 打开目录) |
|
|
49
|
-
| `ghost-bridge start` | 手动启动 MCP 服务(通常不需要) |
|
|
50
|
-
|
|
51
|
-
## 工具一览
|
|
52
|
-
|
|
53
|
-
### 🔍 基础调试
|
|
54
|
-
|
|
55
|
-
| 工具 | 说明 |
|
|
56
|
-
|------|------|
|
|
57
|
-
| `get_server_info` | 获取服务器状态(端口、连接状态、角色) |
|
|
58
|
-
| `get_last_error` | 汇总最近的异常 / console 错误 / 网络报错,附行列与脚本标识 |
|
|
59
|
-
| `get_script_source` | 抓取目标脚本源码,支持按 URL 片段筛选、指定行列定位、beautify |
|
|
60
|
-
| `coverage_snapshot` | 启动执行覆盖率采集(默认 1.5s),返回最活跃的脚本列表 |
|
|
61
|
-
| `find_by_string` | 在页面脚本源码中按关键词搜索,返回 200 字符上下文窗口 |
|
|
62
|
-
| `symbolic_hints` | 采集资源列表、全局变量 key、localStorage key、UA 与 URL |
|
|
63
|
-
| `eval_script` | 在页面执行 JS 表达式(谨慎使用) |
|
|
64
|
-
|
|
65
|
-
### � 网络请求分析
|
|
20
|
+
---
|
|
66
21
|
|
|
67
|
-
|
|
68
|
-
|------|------|
|
|
69
|
-
| `list_network_requests` | 列出捕获的网络请求,支持按 URL / 方法 / 状态 / 资源类型过滤 |
|
|
70
|
-
| `get_network_detail` | 获取单个请求的详细信息(请求头、响应头、timing),可选获取响应体 |
|
|
71
|
-
| `clear_network_requests` | 清空已捕获的网络请求记录 |
|
|
22
|
+
## 🚀 Quick Start
|
|
72
23
|
|
|
73
|
-
###
|
|
24
|
+
### 1. Install & Initialize
|
|
74
25
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
| `get_page_content` | 提取页面内容:纯文本 / HTML / 结构化数据(标题、链接、按钮、表单) |
|
|
79
|
-
|
|
80
|
-
### 🎯 页面交互(DOM 操作)
|
|
81
|
-
|
|
82
|
-
| 工具 | 说明 |
|
|
83
|
-
|------|------|
|
|
84
|
-
| `get_interactive_snapshot` | 扫描页面所有可见可交互元素,返回带 ref 短标识(e1, e2...)的精简列表,支持 Shadow DOM 穿透 |
|
|
85
|
-
| `dispatch_action` | 对目标元素执行动作(click / fill / press / scroll / select / hover / focus),使用 CDP 物理级模拟 |
|
|
86
|
-
|
|
87
|
-
**交互工作流示例:**
|
|
26
|
+
```bash
|
|
27
|
+
# Install globally
|
|
28
|
+
npm install -g ghost-bridge
|
|
88
29
|
|
|
30
|
+
# Auto-configure MCP (Claude Code, Codex, Cursor, Antigravity) and prepare the extension directory
|
|
31
|
+
ghost-bridge init
|
|
89
32
|
```
|
|
90
|
-
1. AI 调用 get_interactive_snapshot
|
|
91
|
-
→ 返回: [{ref:"e1", tag:"input", placeholder:"Search..."}, {ref:"e2", tag:"button", text:"Login"}]
|
|
92
33
|
|
|
93
|
-
|
|
94
|
-
|
|
34
|
+
> `ghost-bridge init` currently writes:
|
|
35
|
+
> - Claude Code: `~/.claude/settings.json` or legacy `~/.claude.json`
|
|
36
|
+
> - Codex: `~/.codex/config.toml`
|
|
37
|
+
> - Cursor: `~/.cursor/mcp.json`
|
|
38
|
+
> - Antigravity: `~/.gemini/antigravity/mcp.json`
|
|
39
|
+
>
|
|
40
|
+
> **Note on other MCP clients (Windsurf, Roo, others):**
|
|
41
|
+
> `ghost-bridge init` attempts to auto-configure supported clients. If your client isn't auto-detected, add one of the following snippets to the appropriate MCP configuration file:
|
|
42
|
+
>
|
|
43
|
+
> JSON-style MCP configs (`mcp.json`, Claude JSON config, Cursor):
|
|
44
|
+
> ```json
|
|
45
|
+
> {
|
|
46
|
+
> "mcpServers": {
|
|
47
|
+
> "ghost-bridge": {
|
|
48
|
+
> "command": "/absolute/path/to/node",
|
|
49
|
+
> "args": ["/absolute/path/to/global/node_modules/ghost-bridge/dist/server.js"]
|
|
50
|
+
> }
|
|
51
|
+
> }
|
|
52
|
+
> }
|
|
53
|
+
> ```
|
|
54
|
+
>
|
|
55
|
+
> Codex TOML config (`~/.codex/config.toml`):
|
|
56
|
+
> ```toml
|
|
57
|
+
> [mcp_servers.ghost-bridge]
|
|
58
|
+
> type = "stdio"
|
|
59
|
+
> command = "/absolute/path/to/node"
|
|
60
|
+
> args = ["/absolute/path/to/global/node_modules/ghost-bridge/dist/server.js"]
|
|
61
|
+
> ```
|
|
62
|
+
|
|
63
|
+
### 2. Load the Chrome Extension
|
|
64
|
+
|
|
65
|
+
1. Open Chrome and navigate to `chrome://extensions`
|
|
66
|
+
2. Toggle **Developer mode** in the top right corner.
|
|
67
|
+
3. Click **Load unpacked**
|
|
68
|
+
4. Select the directory: `~/.ghost-bridge/extension`
|
|
69
|
+
|
|
70
|
+
> 💡 *Tip: Run `ghost-bridge extension --open` to reveal the directory directly.*
|
|
71
|
+
|
|
72
|
+
### 3. Connect & Command
|
|
73
|
+
|
|
74
|
+
1. Click the **Ghost Bridge** ghost icon in your browser toolbar.
|
|
75
|
+
2. Click **Connect** and wait for the status to turn to ✅ **ON**.
|
|
76
|
+
3. Open Claude Desktop or your Claude CLI. All tools are now primed and ready!
|
|
77
|
+
|
|
78
|
+
**Prompting tips:**
|
|
79
|
+
- You usually do not need to say "please use ghost-bridge". Direct requests like `分析当前页面`、`看看这个网站的 DOM 结构`、`帮我检查这个页面为什么布局错了`、`帮我点击登录按钮并提交表单` should be enough.
|
|
80
|
+
- `inspect_page` is the default entry tool for generic page analysis.
|
|
81
|
+
- For visual/UI issues, the model should prefer `capture_screenshot`.
|
|
82
|
+
- For text/DOM extraction, the model should prefer `get_page_content`.
|
|
83
|
+
- For page actions, the model should start with `get_interactive_snapshot` and then call `dispatch_action`.
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## 🛠️ Tool Arsenal
|
|
88
|
+
|
|
89
|
+
### 🔍 Core Debugging
|
|
90
|
+
|
|
91
|
+
| Tool | Capability |
|
|
92
|
+
|------|------------|
|
|
93
|
+
| `inspect_page` | Best default entry for page analysis. Returns metadata, structured content, and an interactive-elements overview. |
|
|
94
|
+
| `get_server_info` | Retrieves server instance status, WebSocket ports, and client roles. |
|
|
95
|
+
| `get_last_error` | Aggregates recent exceptions, console errors, and failed network requests with mapped locators. |
|
|
96
|
+
| `get_script_source` | Pulls raw script definitions. Supports URL-fragment filtering, specific line targeting, and beautification. |
|
|
97
|
+
| `coverage_snapshot` | Triggers a quick coverage trace (1.5s default) to identify the most active scripts on the page. |
|
|
98
|
+
| `find_by_string` | Scans page script sources for keywords, returning a 200-character context window. |
|
|
99
|
+
| `symbolic_hints` | Gathers context clues: Resource lists, Global Variable keys, LocalStorage schema, and UA strings. |
|
|
100
|
+
| `eval_script` | Executes raw JavaScript expressions in the page context. *(Use with caution)* |
|
|
101
|
+
|
|
102
|
+
### 🌍 Network Intelligence
|
|
103
|
+
|
|
104
|
+
| Tool | Capability |
|
|
105
|
+
|------|------------|
|
|
106
|
+
| `list_network_requests` | Lists captured network traffic. Supports filtering by URL, Method, Status Code, or Resource Type. |
|
|
107
|
+
| `get_network_detail` | Dives deep into a specific request's Headers, Timing, and optional Response Body extraction. |
|
|
108
|
+
| `clear_network_requests` | Wipes the current network capture buffer. |
|
|
109
|
+
|
|
110
|
+
### 📸 Page Perception
|
|
111
|
+
|
|
112
|
+
| Tool | Capability |
|
|
113
|
+
|------|------------|
|
|
114
|
+
| `capture_screenshot` | Captures the viewport or emulates full-page scrolling screenshots. |
|
|
115
|
+
| `get_page_content` | Extracts raw text, sanitized HTML, or structured actionable data representations. |
|
|
116
|
+
|
|
117
|
+
### 🎯 Interactive Automation (DOM)
|
|
118
|
+
|
|
119
|
+
| Tool | Capability |
|
|
120
|
+
|------|------------|
|
|
121
|
+
| `get_interactive_snapshot` | Scans for visible interactive elements, returning a concise map `[e1, e2...]`. Pierces open Shadow DOMs. |
|
|
122
|
+
| `dispatch_action` | Dispatches physical UI actions (click, fill, press, hover) against targeted element references (e.g., `e1`). |
|
|
123
|
+
|
|
124
|
+
**Example Agent Workflow:**
|
|
125
|
+
1. AI: `get_interactive_snapshot` ➝ `[{ref:"e1", tag:"input", placeholder:"Search..."}, {ref:"e2", tag:"button", text:"Login"}]`
|
|
126
|
+
2. AI: `dispatch_action({ref: "e1", action: "fill", value: "hello"})`
|
|
127
|
+
3. AI: `dispatch_action({ref: "e2", action: "click"})`
|
|
128
|
+
4. AI: `capture_screenshot` to verify state changes.
|
|
129
|
+
|
|
130
|
+
### 📊 Performance Profiling
|
|
131
|
+
|
|
132
|
+
| Tool | Capability |
|
|
133
|
+
|------|------------|
|
|
134
|
+
| `perf_metrics` | Collects layered performance data (Engine Metrics, Web Vitals, and Resource Load Summaries). |
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## ⚙️ Configuration
|
|
139
|
+
|
|
140
|
+
| Setting | Default | Description |
|
|
141
|
+
|---------|---------|-------------|
|
|
142
|
+
| **Base Port** | `33333` | WS port. Auto-increments if occupied. |
|
|
143
|
+
| **Token** | *Monthly UUID* | Local WS auth token, auto-rotates on the 1st of every month. |
|
|
144
|
+
| **Auto Detach** | `false` | Keeps debugger attached to actively buffer invisible exceptions and network calls. |
|
|
145
|
+
|
|
146
|
+
**Environment Variables:**
|
|
147
|
+
- `GHOST_BRIDGE_PORT` — Override base port.
|
|
148
|
+
- `GHOST_BRIDGE_TOKEN` — Override connection token.
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## 🏗️ Architecture
|
|
95
153
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
154
|
+
```mermaid
|
|
155
|
+
graph LR
|
|
156
|
+
A[Claude CLI/Desktop] <-->|stdio| B(MCP Server\nserver.js)
|
|
157
|
+
B <-->|WebSocket| C(Chrome Extension\nbackground.js)
|
|
158
|
+
C <-->|CDP| D[Browser Tab\nTarget Context]
|
|
100
159
|
```
|
|
101
160
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|------|------|
|
|
106
|
-
| `perf_metrics` | 获取页面性能指标,包含三层数据:|
|
|
161
|
+
- **MCP Server**: Spawned by Claude via standard I/O streams. Orchestrates WS connections.
|
|
162
|
+
- **Chrome Extension (MV3)**: Taps into `chrome.debugger` API. Utilizes an Offscreen Document to prevent WS hibernation.
|
|
163
|
+
- **Singleton Design**: If multiple agents spawn servers, the first becomes the master bridge while subsequent instances chain transparently as clients.
|
|
107
164
|
|
|
108
|
-
|
|
165
|
+
---
|
|
109
166
|
|
|
110
|
-
|
|
111
|
-
- **Web Vitals** — Navigation Timing 各阶段(DNS / TTFB / DOM Interactive / Load)、FP、FCP、Long Tasks 统计
|
|
112
|
-
- **资源加载摘要** — 按类型分组统计(count / size / avgDuration)、最慢资源识别
|
|
167
|
+
## ⚠️ Known Limitations
|
|
113
168
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
| 端口 | `33333` | WebSocket 服务端口,自动递增寻找可用端口 |
|
|
119
|
-
| Token | 当月自动生成 | 本机 WS 校验,基于当月 1 号时间戳 |
|
|
120
|
-
| 自动 Detach | `false` | 保持附加,便于持续捕获异常和网络请求 |
|
|
121
|
-
|
|
122
|
-
环境变量:
|
|
123
|
-
|
|
124
|
-
- `GHOST_BRIDGE_PORT` — 自定义基础端口
|
|
125
|
-
- `GHOST_BRIDGE_TOKEN` — 自定义 token
|
|
126
|
-
|
|
127
|
-
## 架构
|
|
128
|
-
|
|
129
|
-
```
|
|
130
|
-
┌──────────────┐ stdio ┌──────────────┐ WebSocket ┌──────────────┐
|
|
131
|
-
│ Claude CLI │ ◄────────────► │ MCP Server │ ◄──────────────►│Chrome Extension│
|
|
132
|
-
│ / Desktop │ │ (server.js) │ │(background.js)│
|
|
133
|
-
└──────────────┘ └──────────────┘ └──────┬───────┘
|
|
134
|
-
│ CDP
|
|
135
|
-
┌─────▼──────┐
|
|
136
|
-
│ 浏览器页面 │
|
|
137
|
-
└────────────┘
|
|
138
|
-
```
|
|
169
|
+
- **Service Workers Suspending**: MV3 background workers may suspend. We've built robust auto-reconnection logic, but prolonged inactivity might require re-toggling.
|
|
170
|
+
- **DevTools Conflict**: If you manually open Chrome DevTools (F12) on the target tab, `chrome.debugger.attach` may be rejected.
|
|
171
|
+
- **Beautify Overhead**: Beautifying massive single-line bundles is expensive; the server will auto-truncate overly large scripts.
|
|
172
|
+
- **Cross-Origin OOPIF**: Elements and errors deeply embedded in strict Cross-Origin Iframes might evade the primary debugger hook without further multi-target attach logic.
|
|
139
173
|
|
|
140
|
-
|
|
141
|
-
- **Chrome Extension (MV3)** — 使用 `chrome.debugger` API 附加页面,Offscreen Document 维持 WebSocket 长连接
|
|
142
|
-
- **单例模式** — 多个 MCP 客户端自动协调,首个实例为主服务,后续实例作为客户端连接
|
|
174
|
+
---
|
|
143
175
|
|
|
144
|
-
##
|
|
176
|
+
## 🤝 Contributing
|
|
145
177
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
- 大体积单行 bundle beautify 可能耗时,服务端对超长源码会截取片段
|
|
149
|
-
- 跨月时 token 会自动更新,扩展和服务端需在同月内启动
|
|
150
|
-
- DOM 交互:SPA 路由变化后 ref 标识会失效,需重新调用 `get_interactive_snapshot`
|
|
151
|
-
- DOM 交互:跨域 iframe 内的元素暂不支持细粒度操作
|
|
152
|
-
- DOM 交互:Shadow DOM 内的元素可以被扫描到,但部分封闭模式的 Shadow Root 可能无法穿透
|
|
178
|
+
Contributions, issues, and feature requests are welcome!
|
|
179
|
+
Check out our [Contributing Guide](CONTRIBUTING.md) to get started building tools or improving the bridge.
|
|
153
180
|
|
|
154
|
-
## License
|
|
181
|
+
## 📄 License
|
|
155
182
|
|
|
156
|
-
MIT
|
|
183
|
+
This project is [MIT](LICENSE) licensed.
|