cdp-tunnel 1.0.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 (46) hide show
  1. package/.github/workflows/publish.yml +92 -0
  2. package/.github/workflows/release-assets.yml +50 -0
  3. package/LICENSE +81 -0
  4. package/PUBLISH.md +65 -0
  5. package/README.md +228 -0
  6. package/cli/guide.html +753 -0
  7. package/cli/icon.svg +13 -0
  8. package/cli/icon128.png +0 -0
  9. package/cli/index.js +357 -0
  10. package/docs/README_CN.md +204 -0
  11. package/docs/config-page-screenshot.png +0 -0
  12. package/extension-new/background.js +294 -0
  13. package/extension-new/cdp/handler/forward.js +44 -0
  14. package/extension-new/cdp/handler/local.js +233 -0
  15. package/extension-new/cdp/handler/special.js +442 -0
  16. package/extension-new/cdp/index.js +104 -0
  17. package/extension-new/cdp/response.js +49 -0
  18. package/extension-new/config-page-preview.html +769 -0
  19. package/extension-new/config-page.js +318 -0
  20. package/extension-new/core/debugger.js +310 -0
  21. package/extension-new/core/state.js +384 -0
  22. package/extension-new/core/websocket.js +326 -0
  23. package/extension-new/features/automation-badge.js +113 -0
  24. package/extension-new/features/screencast.js +221 -0
  25. package/extension-new/icons/icon128.png +0 -0
  26. package/extension-new/icons/icon16.png +0 -0
  27. package/extension-new/icons/icon48.png +0 -0
  28. package/extension-new/manifest.json +39 -0
  29. package/extension-new/popup.html +72 -0
  30. package/extension-new/popup.js +34 -0
  31. package/extension-new/utils/config.js +20 -0
  32. package/extension-new/utils/diagnostics.js +560 -0
  33. package/extension-new/utils/helpers.js +25 -0
  34. package/extension-new/utils/logger.js +64 -0
  35. package/package.json +42 -0
  36. package/server/modules/config.js +28 -0
  37. package/server/modules/logger.js +197 -0
  38. package/server/proxy-server.js +1431 -0
  39. package/tests/playwright-demo.js +45 -0
  40. package/tests/playwright-interactive.js +261 -0
  41. package/tests/playwright-multi-demo.js +60 -0
  42. package/tests/playwright-multi.js +85 -0
  43. package/tests/playwright-single.js +41 -0
  44. package/tests/screenshot-config.js +35 -0
  45. package/tests/test-client.js +89 -0
  46. package/tests/test-multi-client.js +129 -0
@@ -0,0 +1,92 @@
1
+ name: Publish to npm
2
+
3
+ on:
4
+ # 当发布 release 时触发
5
+ release:
6
+ types: [published]
7
+
8
+ # push 到 main 分支时自动更新 patch 版本
9
+ push:
10
+ branches:
11
+ - main
12
+ paths-ignore:
13
+ - '**.md'
14
+ - '.github/**'
15
+
16
+ # 手动触发
17
+ workflow_dispatch:
18
+ inputs:
19
+ version_type:
20
+ description: '版本类型'
21
+ required: true
22
+ default: 'patch'
23
+ type: choice
24
+ options:
25
+ - patch
26
+ - minor
27
+ - major
28
+
29
+ jobs:
30
+ publish:
31
+ runs-on: ubuntu-latest
32
+ permissions:
33
+ contents: write
34
+
35
+ steps:
36
+ # 检出代码
37
+ - name: Checkout code
38
+ uses: actions/checkout@v4
39
+ with:
40
+ fetch-depth: 0
41
+ token: ${{ secrets.GITHUB_TOKEN }}
42
+
43
+ # 设置 Node.js
44
+ - name: Setup Node.js
45
+ uses: actions/setup-node@v4
46
+ with:
47
+ node-version: '20'
48
+ registry-url: 'https://registry.npmjs.org'
49
+
50
+ # 配置 Git
51
+ - name: Configure Git
52
+ run: |
53
+ git config user.name "github-actions[bot]"
54
+ git config user.email "github-actions[bot]@users.noreply.github.com"
55
+
56
+ # 从 Release 名称提取版本号,或使用手动输入
57
+ - name: Update version
58
+ run: |
59
+ if [ "${{ github.event_name }}" = "release" ]; then
60
+ # 从 release tag 提取版本号(去掉 v 前缀)
61
+ VERSION=${GITHUB_REF_NAME#v}
62
+ npm version $VERSION --no-git-tag-version
63
+ elif [ "${{ github.event_name }}" = "push" ]; then
64
+ # push 到 main,自动更新 patch 版本
65
+ npm version patch --no-git-tag-version
66
+ else
67
+ # 手动触发,使用选择的版本类型
68
+ npm version ${{ inputs.version_type }} --no-git-tag-version
69
+ fi
70
+ cat package.json | grep version
71
+
72
+ # 提交版本更新
73
+ - name: Commit version update
74
+ run: |
75
+ git add package.json package-lock.json
76
+ git commit -m "chore: bump version to $(cat package.json | grep '"version"' | head -1 | awk -F: '{ print $2 }' | sed 's/[",]//g' | tr -d ' ')"
77
+ git push
78
+
79
+ # 安装依赖
80
+ - name: Install dependencies
81
+ run: npm ci
82
+
83
+ # 运行测试(如果有)
84
+ - name: Run tests
85
+ run: npm test || echo "No tests found"
86
+ continue-on-error: true
87
+
88
+ # 发布到 npm
89
+ - name: Publish to npm
90
+ run: npm publish --access public
91
+ env:
92
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
@@ -0,0 +1,50 @@
1
+ name: Create Release Assets
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ build-assets:
9
+ runs-on: ubuntu-latest
10
+
11
+ steps:
12
+ # 检出代码
13
+ - name: Checkout code
14
+ uses: actions/checkout@v4
15
+
16
+ # 打包扩展
17
+ - name: Pack extension
18
+ run: |
19
+ cd extension-new
20
+ zip -r ../cdp-tunnel-extension.zip .
21
+ cd ..
22
+ ls -lh cdp-tunnel-extension.zip
23
+
24
+ # 上传扩展到 Release
25
+ - name: Upload extension to Release
26
+ uses: actions/upload-release-asset@v1
27
+ env:
28
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29
+ with:
30
+ upload_url: ${{ github.event.release.upload_url }}
31
+ asset_path: ./cdp-tunnel-extension.zip
32
+ asset_name: cdp-tunnel-extension.zip
33
+ asset_content_type: application/zip
34
+
35
+ # 打包完整项目
36
+ - name: Pack full project
37
+ run: |
38
+ zip -r cdp-tunnel-full.zip . -x "*.git*" -x "node_modules/*" -x "test/*"
39
+ ls -lh cdp-tunnel-full.zip
40
+
41
+ # 上传完整项目到 Release
42
+ - name: Upload full project to Release
43
+ uses: actions/upload-release-asset@v1
44
+ env:
45
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46
+ with:
47
+ upload_url: ${{ github.event.release.upload_url }}
48
+ asset_path: ./cdp-tunnel-full.zip
49
+ asset_name: cdp-tunnel-full.zip
50
+ asset_content_type: application/zip
package/LICENSE ADDED
@@ -0,0 +1,81 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity.
18
+
19
+ "You" (or "Your") shall mean an individual or Legal Entity
20
+ exercising permissions granted by this License.
21
+
22
+ 2. Grant of Copyright License.
23
+
24
+ Subject to the terms and conditions of this License, the Licensor
25
+ hereby grants to You a worldwide, royalty-free, non-exclusive,
26
+ perpetual, irrevocable copyright license to reproduce, prepare
27
+ derivative works of, publicly display, publicly perform, sublicense,
28
+ and distribute the Work and such derivative works in source and
29
+ object code form.
30
+
31
+ 3. Grant of Patent License.
32
+
33
+ Subject to the terms and conditions of this License, the Licensor
34
+ hereby grants to You a worldwide, royalty-free, non-exclusive,
35
+ perpetual, irrevocable patent license to make, have made, use,
36
+ offer to sell, sell, import, and otherwise transfer the Work,
37
+ where such license applies only to those patent claims licensable
38
+ by the Licensor that are necessarily infringed by their
39
+ contribution(s) alone or by combination of their contribution(s)
40
+ with the Work to which such contribution(s) was submitted.
41
+
42
+ 4. Attribution Requirement.
43
+
44
+ Any derivative works based on this Software must include clear
45
+ attribution to the original project:
46
+
47
+ - Project name: CDP Tunnel
48
+ - Author: dyyz1993
49
+ - Source: https://github.com/dyyz1993/cdp-tunnel
50
+
51
+ This attribution should appear in:
52
+ - Documentation or README files
53
+ - About/Info screens of the derivative software
54
+ - Source code comments (where practical)
55
+
56
+ 5. Disclaimer of Warranty.
57
+
58
+ Unless required by applicable law or agreed to in writing, Licensor
59
+ provides the Work (and each Contributor provides its Contributions)
60
+ on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
61
+ either express or implied, including, without limitation, any
62
+ warranties or conditions of TITLE, NON-INFRINGEMENT,
63
+ MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.
64
+
65
+ 6. Limitation of Liability.
66
+
67
+ In no event and under no legal theory, whether in tort (including
68
+ negligence), contract, or otherwise, unless required by applicable
69
+ law (such as deliberate and grossly negligent acts) or agreed to in
70
+ writing, shall any Contributor be liable to You for damages, including any
71
+ direct, indirect, special, incidental, or consequential damages of
72
+ any character arising as a result of this License or out of the use
73
+ or inability to use the Work (including but not limited to damages
74
+ for loss of goodwill, work stoppage, computer failure or malfunction,
75
+ or any and all other commercial damages or losses), even if such
76
+ Contributor has been advised of the possibility of such damages.
77
+
78
+ ================================================================================
79
+
80
+ Copyright (C) 2025 CDP Tunnel
81
+ https://github.com/dyyz1993/cdp-tunnel
package/PUBLISH.md ADDED
@@ -0,0 +1,65 @@
1
+ # 发布到 npm 指南
2
+
3
+ ## 自动发布(推荐)
4
+
5
+ 本项目已配置 GitHub Actions,支持自动发布到 npm。
6
+
7
+ ### 配置步骤
8
+
9
+ 1. **获取 npm Token**
10
+ - 登录 [npmjs.com](https://www.npmjs.com/)
11
+ - 进入 Account → Access Tokens
12
+ - 生成新的 **Automation** token
13
+ - 复制 token(以 `npm_` 开头)
14
+
15
+ 2. **添加到 GitHub Secrets**
16
+ - 打开 GitHub 仓库 → Settings → Secrets and variables → Actions
17
+ - 点击 "New repository secret"
18
+ - Name: `NPM_TOKEN`
19
+ - Value: 刚才复制的 npm token
20
+ - 点击 "Add secret"
21
+
22
+ 3. **发布新版本**
23
+ - 在 GitHub 上创建新的 Release
24
+ - 设置版本号(如 v1.0.1)
25
+ - 填写发布说明
26
+ - 点击 "Publish release"
27
+ - GitHub Actions 会自动发布到 npm
28
+
29
+ ### 手动触发
30
+
31
+ 也可以在 GitHub Actions 页面手动触发发布:
32
+ - 进入 Actions → Publish to npm
33
+ - 点击 "Run workflow"
34
+
35
+ ## 手动发布
36
+
37
+ 如果不想使用 GitHub Actions,也可以手动发布:
38
+
39
+ ```bash
40
+ # 1. 登录 npm
41
+ npm login
42
+
43
+ # 2. 更新版本号
44
+ npm version patch # 或 minor / major
45
+
46
+ # 3. 发布
47
+ npm publish --access public
48
+ ```
49
+
50
+ ## 版本号规则
51
+
52
+ - `patch`: 修复 bug(1.0.0 → 1.0.1)
53
+ - `minor`: 新增功能(1.0.0 → 1.1.0)
54
+ - `major`: 重大更新(1.0.0 → 2.0.0)
55
+
56
+ ## 验证发布
57
+
58
+ 发布后可以在 npm 上查看:
59
+ https://www.npmjs.com/package/cdp-tunnel
60
+
61
+ 安装测试:
62
+ ```bash
63
+ npm install -g cdp-tunnel
64
+ cdp-tunnel --version
65
+ ```
package/README.md ADDED
@@ -0,0 +1,228 @@
1
+ # CDP Tunnel
2
+
3
+ <p align="center">
4
+ <img src="extension-new/icons/icon128.png" alt="CDP Tunnel Logo" width="128" height="128">
5
+ </p>
6
+
7
+ <p align="center">
8
+ <strong>Chrome DevTools Protocol Bridge</strong>
9
+ </p>
10
+
11
+ <p align="center">
12
+ A Chrome extension that exposes your browser as a CDP endpoint,<br>
13
+ supporting multiple Playwright/Puppeteer clients to connect simultaneously.
14
+ </p>
15
+
16
+ <p align="center">
17
+ <a href="docs/README_CN.md">中文文档</a> |
18
+ <a href="https://github.com/dyyz1993/cdp-tunnel">GitHub</a>
19
+ </p>
20
+
21
+ <p align="center">
22
+ <img src="https://img.shields.io/github/stars/dyyz1993/cdp-tunnel?style=social" alt="GitHub stars">
23
+ <img src="https://img.shields.io/github/forks/dyyz1993/cdp-tunnel?style=social" alt="GitHub forks">
24
+ <img src="https://img.shields.io/github/watchers/dyyz1993/cdp-tunnel?style=social" alt="GitHub watchers">
25
+ </p>
26
+
27
+ ---
28
+
29
+ ## Architecture
30
+
31
+ ```
32
+ ┌─────────────────────────────────────────────────────────────────┐
33
+ │ Proxy Server │
34
+ │ (localhost:9221) │
35
+ │ │
36
+ │ /plugin ←─── Chrome Extension (WebSocket) │
37
+ │ HTTP ←─── Playwright/Puppeteer Clients │
38
+ └─────────────────────────────────────────────────────────────────┘
39
+ ↑ ↑ ↑
40
+ │ │ │
41
+ Client 1 Client 2 Client 3
42
+ (clientId_1) (clientId_2) (clientId_3)
43
+ ```
44
+
45
+ ## Features
46
+
47
+ - **Multi-client Support** - Multiple Playwright/Puppeteer clients can connect simultaneously
48
+ - **Message Isolation** - Pages created by each client are owned by that client
49
+ - **Configuration Page** - Visualize connection status, client list, and controlled pages
50
+ - **Auto Reconnect** - Extension automatically reconnects to the server
51
+
52
+ ## Screenshot
53
+
54
+ ![Config Page](docs/config-page-screenshot.png)
55
+
56
+ ## Quick Start
57
+
58
+ ### Option 1: Install via npm (Recommended)
59
+
60
+ ```bash
61
+ # Install globally
62
+ npm install -g cdp-tunnel
63
+
64
+ # Start server
65
+ cdp-tunnel start
66
+
67
+ # Check status
68
+ cdp-tunnel status
69
+
70
+ # Install Chrome extension (opens interactive guide)
71
+ cdp-tunnel extension
72
+ ```
73
+
74
+ ### Option 2: Download from GitHub Releases
75
+
76
+ 1. Go to [GitHub Releases](https://github.com/dyyz1993/cdp-tunnel/releases)
77
+ 2. Download `cdp-tunnel-extension.zip` from the latest release
78
+ 3. Unzip the file
79
+ 4. Open `chrome://extensions/` in Chrome
80
+ 5. Enable "Developer mode"
81
+ 6. Click "Load unpacked"
82
+ 7. Select the unzipped extension directory
83
+
84
+ ### Option 3: Manual Installation
85
+
86
+ #### 1. Start the Proxy Server
87
+
88
+ ```bash
89
+ cd server
90
+ npm install
91
+ node proxy-server.js
92
+ ```
93
+
94
+ The server will start on `localhost:9221`.
95
+
96
+ #### 2. Install Chrome Extension
97
+
98
+ 1. Open `chrome://extensions/`
99
+ 2. Enable "Developer mode"
100
+ 3. Click "Load unpacked"
101
+ 4. Select the `extension-new` directory
102
+
103
+ #### 3. Connect the Extension
104
+
105
+ Click the extension icon, enter the server address in the configuration page, and click "Save and Connect".
106
+
107
+ ### 3. Client Connection
108
+
109
+ ```javascript
110
+ // Playwright
111
+ const { chromium } = require('playwright');
112
+
113
+ const browser = await chromium.connectOverCDP('http://localhost:9221');
114
+ const context = browser.contexts()[0];
115
+ const page = await context.newPage();
116
+ await page.goto('https://example.com');
117
+
118
+ // Puppeteer
119
+ const puppeteer = require('puppeteer');
120
+
121
+ const browser = await puppeteer.connect({
122
+ browserWSEndpoint: 'ws://localhost:9221'
123
+ });
124
+ const page = await browser.newPage();
125
+ await page.goto('https://example.com');
126
+ ```
127
+
128
+ ### 4. Using with agent-browser
129
+
130
+ [agent-browser](https://github.com/nick1udwig/agent-browser) is a browser automation CLI that can connect to CDP Tunnel:
131
+
132
+ ```bash
133
+ # Install agent-browser
134
+ npm install -g agent-browser
135
+
136
+ # Connect to CDP Tunnel
137
+ agent-browser --cdp http://localhost:9221 open https://example.com
138
+
139
+ # Take a snapshot
140
+ agent-browser --cdp http://localhost:9221 snapshot -i
141
+
142
+ # Interact with elements
143
+ agent-browser --cdp http://localhost:9221 click @e1
144
+ agent-browser --cdp http://localhost:9221 fill @e2 "hello"
145
+
146
+ # Take screenshot
147
+ agent-browser --cdp http://localhost:9221 screenshot output.png
148
+ ```
149
+
150
+ This allows you to control the browser through CDP Tunnel using simple CLI commands.
151
+
152
+ ## Multi-client Usage
153
+
154
+ All clients connect to the same endpoint `http://localhost:9221`. The server automatically assigns a unique `clientId` to each connection.
155
+
156
+ ```javascript
157
+ // Multiple clients can connect simultaneously
158
+ const browser1 = await chromium.connectOverCDP('http://localhost:9221');
159
+ const browser2 = await chromium.connectOverCDP('http://localhost:9221');
160
+ const browser3 = await chromium.connectOverCDP('http://localhost:9221');
161
+
162
+ // Pages created by each client are independent
163
+ const page1 = await browser1.contexts()[0].newPage();
164
+ const page2 = await browser2.contexts()[0].newPage();
165
+ const page3 = await browser3.contexts()[0].newPage();
166
+ ```
167
+
168
+ ## Configuration Page
169
+
170
+ Click the extension icon to open the configuration page, where you can view:
171
+
172
+ - **CDP Client List** - Shows connected Playwright/Puppeteer clients
173
+ - **Controlled Pages List** - Shows controlled pages with click-to-navigate support
174
+ - **Activity Log** - Connection status change records
175
+
176
+ ## Project Structure
177
+
178
+ ```
179
+ cdp-tunnel/
180
+ ├── server/
181
+ │ └── proxy-server.js # Proxy server
182
+ ├── extension-new/
183
+ │ ├── background.js # Extension Service Worker
184
+ │ ├── config-page-preview.html # Configuration page
185
+ │ ├── config-page.js # Configuration page script
186
+ │ ├── core/
187
+ │ │ ├── state.js # State management
188
+ │ │ └── websocket.js # WebSocket connection management
189
+ │ └── features/
190
+ │ ├── cdp-router.js # CDP message routing
191
+ │ └── screencast.js # Screenshot functionality
192
+ └── tests/
193
+ ├── playwright-single.js # Single client test
194
+ ├── playwright-multi.js # Multi-client test
195
+ └── playwright-interactive.js # Interactive test
196
+ ```
197
+
198
+ ## Testing
199
+
200
+ ```bash
201
+ # Single client test
202
+ node tests/playwright-single.js
203
+
204
+ # Multi-client test
205
+ node tests/playwright-multi.js
206
+
207
+ # Interactive test
208
+ node tests/playwright-interactive.js
209
+ ```
210
+
211
+ ## Notes
212
+
213
+ 1. **Port Availability** - Ensure port 9221 is not in use
214
+ 2. **Extension Permissions** - The extension requires `debugger`, `tabs`, and other permissions
215
+ 3. **Browser Limitation** - Only one extension can control a browser via debugger at a time
216
+
217
+ ## License
218
+
219
+ This project is licensed under the Apache License 2.0 with Attribution Requirement.
220
+
221
+ See [LICENSE](LICENSE) for details.
222
+
223
+ ---
224
+
225
+ If you use this project in your work, please include attribution:
226
+ - Project: CDP Tunnel
227
+ - Author: dyyz1993
228
+ - Source: https://github.com/dyyz1993/cdp-tunnel