cdp-tunnel 3.0.6 → 3.0.8

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.6",
4
+ "version": "3.0.8",
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.6",
3
+ "version": "3.0.8",
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",
@@ -65,26 +65,18 @@ class PortPoolManager {
65
65
  this.portSessions[portIndex] = session;
66
66
 
67
67
  const server = http.createServer();
68
- const wss = new WebSocket.Server({ noServer: true });
69
- this.createWss[portIndex] = wss;
70
-
71
- // HTTP 请求(非 upgrade)
72
- server.on('request', (req, res) => {
73
- this._handleHttp(req, res, session);
74
- });
68
+ this.createServers[portIndex] = server;
75
69
 
76
- // WebSocket upgrade
70
+ // 端口池端口复用主 proxy 的 wss——通过 localPort 区分
77
71
  server.on('upgrade', (req, socket, head) => {
78
- const url = new URL(req.url, `http://localhost:${port}`);
79
- const path = url.pathname;
80
- if (path !== '/client' && !path.startsWith('/client/') &&
81
- !path.startsWith('/devtools/browser/') && !path.startsWith('/devtools/page/')) {
82
- socket.destroy();
83
- return;
84
- }
85
- wss.handleUpgrade(req, socket, head, (ws) => {
86
- this._handleClientConnect(ws, req, session);
72
+ req._poolPortIndex = portIndex;
73
+ req._poolPort = port;
74
+ // 转发给主 proxy wss 处理
75
+ this.mainProxy.handlePoolUpgrade(req, socket, head, portIndex, port);
87
76
  });
77
+
78
+ server.on('request', (req, res) => {
79
+ this._handleHttp(req, res, session);
88
80
  });
89
81
 
90
82
  server.on('error', (err) => {
@@ -100,7 +92,6 @@ class PortPoolManager {
100
92
  });
101
93
 
102
94
  this.createServers[portIndex] = server;
103
- this.createWss[portIndex] = wss;
104
95
  }
105
96
 
106
97
  _startTakeoverPort() {
@@ -181,6 +172,13 @@ class PortPoolManager {
181
172
  return;
182
173
  }
183
174
 
175
+ // 通知扩展有 client 连接(扩展需要 hasConnectedClient=true 才转发 debugger 事件)
176
+ const poolClientId = `pool_${session.portIndex}_${Date.now()}`;
177
+ pluginWs.send(JSON.stringify({
178
+ type: 'client-connected',
179
+ clientId: poolClientId
180
+ }));
181
+
184
182
  // 合成输入命令需要 ensureVisible(和 forward.js 的逻辑一致)
185
183
  const SYNTHETIC_INPUT = ['Input.dispatchKeyEvent', 'Input.dispatchMouseEvent'];
186
184
 
@@ -195,6 +193,10 @@ class PortPoolManager {
195
193
  await this._ensureVisible(session, pluginWs, msg.sessionId);
196
194
  }
197
195
 
196
+ if (msg.method === 'Network.enable' || msg.method === 'Page.startScreencast') {
197
+ // 已转发,继续
198
+ }
199
+
198
200
  // 命令:分配新 id,记录映射(含 method 名供响应后处理),转发给 plugin
199
201
  const newId = `pool${session.portIndex}_${msg.id}`;
200
202
  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
@@ -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 [];