cdp-tunnel 3.3.1 → 3.3.3
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
|
@@ -210,10 +210,11 @@ class PortPoolManager {
|
|
|
210
210
|
try { msg = JSON.parse(data.toString()); } catch { return; }
|
|
211
211
|
|
|
212
212
|
if (msg.id !== undefined) {
|
|
213
|
-
// createTarget
|
|
213
|
+
// createTarget 串行化 + 标记 pending
|
|
214
214
|
if (msg.method === 'Target.createTarget') {
|
|
215
215
|
while (session.createTargetLock) { await session.createTargetLock; }
|
|
216
216
|
session.createTargetLock = new Promise(r => { session._releaseCreateTarget = r; });
|
|
217
|
+
session.pendingCreate = true; // 标记:下一个 targetCreated 事件归属这个端口
|
|
217
218
|
}
|
|
218
219
|
|
|
219
220
|
// 合成输入命令:先 bringToFront + 等待,再发原命令
|
|
@@ -348,6 +349,29 @@ class PortPoolManager {
|
|
|
348
349
|
return true;
|
|
349
350
|
}
|
|
350
351
|
}
|
|
352
|
+
// 竞态处理:targetCreated/attachedToTarget 在 createTarget 响应之前到达
|
|
353
|
+
// targetToPort 还没记录。检查 pendingCreate。
|
|
354
|
+
// 同时也对 attachedToTarget 放行(它的 targetId 和 targetCreated 一样)
|
|
355
|
+
if (msg.method === 'Target.targetCreated' || msg.method === 'Target.attachedToTarget') {
|
|
356
|
+
for (let pi = 0; pi < this.portSessions.length; pi++) {
|
|
357
|
+
const sess = this.portSessions[pi];
|
|
358
|
+
if (sess && sess.pendingCreate) {
|
|
359
|
+
// 提前注册
|
|
360
|
+
sess.targetIds.add(targetId);
|
|
361
|
+
sess.targetUrls.set(targetId, 'about:blank');
|
|
362
|
+
this.targetToPort.set(targetId, pi);
|
|
363
|
+
if (msg.method === 'Target.attachedToTarget') sess.pendingCreate = false;
|
|
364
|
+
this._broadcastToPort(pi, msg);
|
|
365
|
+
return true;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
// 没有 pendingCreate——广播给所有端口(对齐直连 Chrome 的广播行为)
|
|
369
|
+
// 这样即使竞态导致没匹配到,客户端也能收到事件
|
|
370
|
+
for (let pi = 0; pi < this.portSessions.length; pi++) {
|
|
371
|
+
this._broadcastToPort(pi, msg);
|
|
372
|
+
}
|
|
373
|
+
return true;
|
|
374
|
+
}
|
|
351
375
|
}
|
|
352
376
|
|
|
353
377
|
// sessionId 路由(Network/Screencast/Input 等 session 事件)
|