cdp-tunnel 3.3.3 → 3.3.5
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
|
@@ -146,7 +146,7 @@ class PortPoolManager {
|
|
|
146
146
|
Browser: 'Chrome/131.0.6778.86 (cdp-tunnel)',
|
|
147
147
|
'Protocol-Version': '1.3',
|
|
148
148
|
'User-Agent': 'cdp-tunnel/3.0',
|
|
149
|
-
'webSocketDebuggerUrl': `ws://localhost:${session.port}/
|
|
149
|
+
'webSocketDebuggerUrl': `ws://localhost:${session.port}/client`
|
|
150
150
|
}));
|
|
151
151
|
return;
|
|
152
152
|
}
|
|
@@ -191,6 +191,22 @@ class PortPoolManager {
|
|
|
191
191
|
return;
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
+
// SW 冷启动 warmup:第一个 client 连接时创建一个临时 tab 再关闭
|
|
195
|
+
// 确保 chrome.debugger API 完全初始化,避免第一批并发请求失败
|
|
196
|
+
if (!session.warmedUp) {
|
|
197
|
+
session.warmedUp = true;
|
|
198
|
+
const warmupId = `pool${session.portIndex}_internal_warmup`;
|
|
199
|
+
pluginWs.send(JSON.stringify({
|
|
200
|
+
id: warmupId,
|
|
201
|
+
method: 'Target.createTarget',
|
|
202
|
+
params: { url: 'about:blank' },
|
|
203
|
+
__portIndex: session.portIndex,
|
|
204
|
+
__clientId: `pool_${session.port}`
|
|
205
|
+
}));
|
|
206
|
+
// 响应回来后在 handlePluginMessage 里丢弃(_internal 前缀)
|
|
207
|
+
// tab 会在 Browser.close 或断开时清理
|
|
208
|
+
}
|
|
209
|
+
|
|
194
210
|
// 通知扩展有 client 连接(带端口号作为分组标识)
|
|
195
211
|
// clientId 固定为 pool_{port},让扩展为每个端口建一个独立分组
|
|
196
212
|
const poolClientId = `pool_${session.port}`;
|
|
@@ -374,14 +390,32 @@ class PortPoolManager {
|
|
|
374
390
|
}
|
|
375
391
|
}
|
|
376
392
|
|
|
377
|
-
// sessionId 路由(Network/Screencast/Input 等 session 事件)
|
|
393
|
+
// sessionId 路由(Network/Screencast/Input/Page 等 session 事件)
|
|
378
394
|
if (msg.sessionId) {
|
|
379
395
|
const portIndex = this.sessionToPort.get(msg.sessionId);
|
|
380
396
|
if (portIndex !== undefined) {
|
|
381
397
|
this._broadcastToPort(portIndex, msg);
|
|
382
398
|
return true;
|
|
383
399
|
}
|
|
400
|
+
// 竞态兜底:sessionId 还没注册(attachToTarget 响应未到)
|
|
401
|
+
// 但事件已经来了。广播给所有端口池 client,确保不丢。
|
|
402
|
+
// 对齐直连 Chrome——所有 session 事件都广播给所有连接。
|
|
403
|
+
for (let pi = 0; pi < this.portSessions.length; pi++) {
|
|
404
|
+
if (this.portSessions[pi]) {
|
|
405
|
+
this._broadcastToPort(pi, msg);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return true;
|
|
384
409
|
}
|
|
410
|
+
|
|
411
|
+
// 兜底:有 method 但没有 targetId 也没有 sessionId 的事件
|
|
412
|
+
// 也广播,确保不丢(如 Target.targetDestroyed 等)
|
|
413
|
+
for (let pi = 0; pi < this.portSessions.length; pi++) {
|
|
414
|
+
if (this.portSessions[pi]) {
|
|
415
|
+
this._broadcastToPort(pi, msg);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return true;
|
|
385
419
|
}
|
|
386
420
|
|
|
387
421
|
return false; // 不是端口池的消息
|