cdp-tunnel 3.3.8 → 3.3.9
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
|
@@ -45,6 +45,7 @@ class PortPoolManager {
|
|
|
45
45
|
this.cdpIdCounter = 1; // CDP 命令 id 计数器
|
|
46
46
|
this.pendingRequests = new Map(); // id → {clientWs, resolve, reject}
|
|
47
47
|
this.targetToClient = new Map(); // targetId → clientWs(attachToTarget 时绑定)
|
|
48
|
+
this.sessionToClient = new Map(); // sessionId → clientWs(事件精确路由用)
|
|
48
49
|
this.browserWsUrl = null; // /json/version 返回的 webSocketDebuggerUrl
|
|
49
50
|
}
|
|
50
51
|
};
|
|
@@ -339,9 +340,11 @@ class PortPoolManager {
|
|
|
339
340
|
}
|
|
340
341
|
}
|
|
341
342
|
|
|
342
|
-
// 如果是 attachToTarget 响应,记录 sessionId → portIndex
|
|
343
|
+
// 如果是 attachToTarget 响应,记录 sessionId → portIndex + 发起请求的 client
|
|
343
344
|
if (msg.result && msg.result.sessionId) {
|
|
344
345
|
this.sessionToPort.set(msg.result.sessionId, portIndex);
|
|
346
|
+
// 记录 sessionId → 哪个 client 发起的(用于精确路由事件)
|
|
347
|
+
session.sessionToClient.set(msg.result.sessionId, pending ? pending.clientWs : null);
|
|
345
348
|
}
|
|
346
349
|
|
|
347
350
|
// 如果是 getTargets 响应,按 portIndex 过滤 targetInfos
|
|
@@ -403,8 +406,15 @@ class PortPoolManager {
|
|
|
403
406
|
if (msg.sessionId) {
|
|
404
407
|
const portIndex = this.sessionToPort.get(msg.sessionId);
|
|
405
408
|
if (portIndex !== undefined) {
|
|
406
|
-
this.
|
|
407
|
-
|
|
409
|
+
const sess = this.portSessions[portIndex];
|
|
410
|
+
if (sess) {
|
|
411
|
+
// 精确路由:只发给持有这个 sessionId 的 client(不广播)
|
|
412
|
+
const ownerWs = sess.sessionToClient.get(msg.sessionId);
|
|
413
|
+
if (ownerWs && ownerWs.readyState === WebSocket.OPEN) {
|
|
414
|
+
ownerWs.send(JSON.stringify(msg));
|
|
415
|
+
}
|
|
416
|
+
return true;
|
|
417
|
+
}
|
|
408
418
|
}
|
|
409
419
|
// sessionId 未注册——交给主 proxy 处理(不吞掉)
|
|
410
420
|
}
|