cdp-tunnel 3.0.4 → 3.0.6

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.4",
4
+ "version": "3.0.6",
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.4",
3
+ "version": "3.0.6",
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,26 +64,27 @@ 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) => {
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) => {
68
73
  this._handleHttp(req, res, session);
69
74
  });
70
75
 
71
- const wss = new WebSocket.Server({ noServer: true });
72
-
76
+ // WebSocket upgrade
73
77
  server.on('upgrade', (req, socket, head) => {
74
78
  const url = new URL(req.url, `http://localhost:${port}`);
75
79
  const path = url.pathname;
76
-
77
- // 只允许 client 连接(plugin 连的是 9221)
78
80
  if (path !== '/client' && !path.startsWith('/client/') &&
79
81
  !path.startsWith('/devtools/browser/') && !path.startsWith('/devtools/page/')) {
80
82
  socket.destroy();
81
83
  return;
82
84
  }
83
-
84
- wss.handleUpgrade(req, socket, head, (ws) => {
85
- this._handleClientConnect(ws, req, session);
86
- });
85
+ wss.handleUpgrade(req, socket, head, (ws) => {
86
+ this._handleClientConnect(ws, req, session);
87
+ });
87
88
  });
88
89
 
89
90
  server.on('error', (err) => {
@@ -172,7 +173,6 @@ class PortPoolManager {
172
173
  */
173
174
  _handleClientConnect(ws, req, session) {
174
175
  session.clients.add(ws);
175
- console.log(`[PORT ${session.port}] Client connected (total: ${session.clients.size})`);
176
176
 
177
177
  // 找到 plugin 连接(从主 proxy 获取)
178
178
  const pluginWs = this.mainProxy.getPluginConnection();
@@ -256,7 +256,6 @@ class PortPoolManager {
256
256
  // 如果是 attachToTarget 响应,记录 sessionId → portIndex
257
257
  if (msg.result && msg.result.sessionId) {
258
258
  this.sessionToPort.set(msg.result.sessionId, portIndex);
259
- console.log(`[PORT POOL] sessionId=${msg.result.sessionId.slice(0,12)} → port ${session.port}`);
260
259
  }
261
260
 
262
261
  // 如果是 getTargets 响应,按 portIndex 过滤 targetInfos
@@ -276,9 +275,9 @@ class PortPoolManager {
276
275
  return true;
277
276
  }
278
277
 
279
- // 2. 事件消息(无 id):按 targetId 路由
278
+ // 2. 事件消息(无 id):按 targetId 或 sessionId 路由
280
279
  if (msg.method && msg.params) {
281
- // 从事件参数里提取 targetId
280
+ // 诊断:打印所有未匹配到的事件
282
281
  let targetId = null;
283
282
  if (msg.params.targetId) targetId = msg.params.targetId;
284
283
  else if (msg.params.targetInfo && msg.params.targetInfo.targetId) targetId = msg.params.targetInfo.targetId;
@@ -294,7 +293,7 @@ class PortPoolManager {
294
293
  }
295
294
  }
296
295
 
297
- // sessionId 路由(attachedToTarget 后的 session 事件)
296
+ // sessionId 路由(Network/Screencast/Input session 事件)
298
297
  if (msg.sessionId) {
299
298
  const portIndex = this.sessionToPort.get(msg.sessionId);
300
299
  if (portIndex !== undefined) {
@@ -812,7 +812,7 @@ function handlePluginConnection(ws, clientInfo, request) {
812
812
 
813
813
  // v3.0 端口池 hook:先让 PortPoolManager 处理端口池的消息
814
814
  if (parsed && portPool && portPool.handlePluginMessage(parsed, ws)) {
815
- return; // 已被端口池处理
815
+ return;
816
816
  }
817
817
 
818
818
  // 处理 keepalive 消息