cdp-tunnel 3.0.5 → 3.0.7

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "CDP Bridge",
4
- "version": "3.0.5",
4
+ "version": "3.0.7",
5
5
  "description": "Chrome DevTools Protocol Bridge for Playwright/Puppeteer automation",
6
6
  "permissions": [
7
7
  "debugger",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cdp-tunnel",
3
- "version": "3.0.5",
3
+ "version": "3.0.7",
4
4
  "description": "Bridge Chrome's debugger API to WebSocket — control your existing browser with Playwright/Puppeteer via CDP",
5
5
  "main": "server/proxy-server.js",
6
6
  "bin": "./cli/index.js",
@@ -64,28 +64,19 @@ class PortPoolManager {
64
64
  const session = new PortPoolManager.PortSession(portIndex, port);
65
65
  this.portSessions[portIndex] = session;
66
66
 
67
- const server = http.createServer((req, res) => {
68
- this._handleHttp(req, res, session);
69
- });
70
-
71
- // 每个 create 端口用独立的 wss(不复用主 proxy 的 wss)
72
- const wss = new WebSocket.Server({ noServer: true });
73
- this.createWss[portIndex] = wss;
67
+ const server = http.createServer();
68
+ this.createServers[portIndex] = server;
74
69
 
70
+ // 端口池端口复用主 proxy 的 wss——通过 localPort 区分
75
71
  server.on('upgrade', (req, socket, head) => {
76
- const url = new URL(req.url, `http://localhost:${port}`);
77
- const path = url.pathname;
78
-
79
- // 只允许 client 连接(plugin 连的是主 proxy 的 9221)
80
- if (path !== '/client' && !path.startsWith('/client/') &&
81
- !path.startsWith('/devtools/browser/') && !path.startsWith('/devtools/page/')) {
82
- socket.destroy();
83
- return;
84
- }
72
+ req._poolPortIndex = portIndex;
73
+ req._poolPort = port;
74
+ // 转发给主 proxy 的 wss 处理
75
+ this.mainProxy.handlePoolUpgrade(req, socket, head, portIndex, port);
76
+ });
85
77
 
86
- wss.handleUpgrade(req, socket, head, (ws) => {
87
- this._handleClientConnect(ws, req, session);
88
- });
78
+ server.on('request', (req, res) => {
79
+ this._handleHttp(req, res, session);
89
80
  });
90
81
 
91
82
  server.on('error', (err) => {
@@ -101,7 +92,6 @@ class PortPoolManager {
101
92
  });
102
93
 
103
94
  this.createServers[portIndex] = server;
104
- this.createWss[portIndex] = wss;
105
95
  }
106
96
 
107
97
  _startTakeoverPort() {
@@ -174,7 +164,6 @@ class PortPoolManager {
174
164
  */
175
165
  _handleClientConnect(ws, req, session) {
176
166
  session.clients.add(ws);
177
- console.log(`[PORT ${session.port}] Client connected (total: ${session.clients.size})`);
178
167
 
179
168
  // 找到 plugin 连接(从主 proxy 获取)
180
169
  const pluginWs = this.mainProxy.getPluginConnection();
@@ -197,6 +186,10 @@ class PortPoolManager {
197
186
  await this._ensureVisible(session, pluginWs, msg.sessionId);
198
187
  }
199
188
 
189
+ if (msg.method === 'Network.enable' || msg.method === 'Page.startScreencast') {
190
+ // 已转发,继续
191
+ }
192
+
200
193
  // 命令:分配新 id,记录映射(含 method 名供响应后处理),转发给 plugin
201
194
  const newId = `pool${session.portIndex}_${msg.id}`;
202
195
  session.pendingRequests.set(newId, {
@@ -456,6 +456,15 @@ wss.on('connection', (ws, req) => {
456
456
  const path = url.pathname;
457
457
  const pathParts = path.split('/').filter(Boolean);
458
458
 
459
+ // v3.0 端口池连接:走 PortPoolManager 的隔离逻辑
460
+ if (req._poolPortIndex !== undefined && portPool) {
461
+ const session = portPool.portSessions[req._poolPortIndex];
462
+ if (session) {
463
+ portPool._handleClientConnect(ws, req, session);
464
+ return;
465
+ }
466
+ }
467
+
459
468
  const clientInfo = {
460
469
  ip: req.socket.remoteAddress,
461
470
  port: req.socket.remotePort
@@ -812,7 +821,7 @@ function handlePluginConnection(ws, clientInfo, request) {
812
821
 
813
822
  // v3.0 端口池 hook:先让 PortPoolManager 处理端口池的消息
814
823
  if (parsed && portPool && portPool.handlePluginMessage(parsed, ws)) {
815
- return; // 已被端口池处理
824
+ return;
816
825
  }
817
826
 
818
827
  // 处理 keepalive 消息
@@ -2130,6 +2139,12 @@ portPool = new PortPoolManager({
2130
2139
  for (const ws of pluginConnections) return ws;
2131
2140
  return null;
2132
2141
  },
2142
+ handlePoolUpgrade: (req, socket, head, portIndex, port) => {
2143
+ req._poolPortIndex = portIndex;
2144
+ wss.handleUpgrade(req, socket, head, (ws) => {
2145
+ wss.emit('connection', ws, req);
2146
+ });
2147
+ },
2133
2148
  getAllTargets: async (portIndex) => {
2134
2149
  const session = portPool.portSessions[portIndex];
2135
2150
  if (!session) return [];