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.
package/package.json
CHANGED
|
@@ -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(
|
|
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
|
-
|
|
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
|
-
|
|
85
|
-
|
|
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
|
-
//
|
|
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 路由(
|
|
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) {
|
package/server/proxy-server.js
CHANGED
|
@@ -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 消息
|