cdp-tunnel 3.2.3 → 3.2.4
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
|
@@ -38,6 +38,7 @@ class PortPoolManager {
|
|
|
38
38
|
this.portIndex = portIndex;
|
|
39
39
|
this.port = port;
|
|
40
40
|
this.targetIds = new Set(); // 这个端口创建的所有 targetId
|
|
41
|
+
this.targetUrls = new Map(); // targetId → url(navigate 时更新)
|
|
41
42
|
this.tabIds = new Set(); // Chrome tabId(扩展端返回的)
|
|
42
43
|
this.clients = new Set(); // 连接到这个端口的 client WebSocket
|
|
43
44
|
this.cdpIdCounter = 1; // CDP 命令 id 计数器
|
|
@@ -157,7 +158,7 @@ class PortPoolManager {
|
|
|
157
158
|
targets.push({
|
|
158
159
|
id: targetId,
|
|
159
160
|
type: 'page',
|
|
160
|
-
url: 'about:blank',
|
|
161
|
+
url: session.targetUrls.get(targetId) || 'about:blank',
|
|
161
162
|
title: '',
|
|
162
163
|
webSocketDebuggerUrl: `ws://localhost:${session.port}/devtools/page/${targetId}`
|
|
163
164
|
});
|
|
@@ -222,7 +223,9 @@ class PortPoolManager {
|
|
|
222
223
|
session.pendingRequests.set(newId, {
|
|
223
224
|
originalId: msg.id,
|
|
224
225
|
method: msg.method,
|
|
225
|
-
clientWs: ws
|
|
226
|
+
clientWs: ws,
|
|
227
|
+
params: msg.params,
|
|
228
|
+
sessionId: msg.sessionId
|
|
226
229
|
});
|
|
227
230
|
|
|
228
231
|
const forwarded = { ...msg, id: newId, __portIndex: session.portIndex, __clientId: `pool_${session.port}` };
|
|
@@ -268,11 +271,25 @@ class PortPoolManager {
|
|
|
268
271
|
const pending = session.pendingRequests.get(msg.id);
|
|
269
272
|
session.pendingRequests.delete(msg.id);
|
|
270
273
|
|
|
271
|
-
// 如果是 createTarget 响应,记录 targetId → portIndex 归属
|
|
274
|
+
// 如果是 createTarget 响应,记录 targetId → portIndex 归属 + 初始 url
|
|
272
275
|
if (msg.result && msg.result.targetId) {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
+
const tid = msg.result.targetId;
|
|
277
|
+
session.targetIds.add(tid);
|
|
278
|
+
session.targetUrls.set(tid, pending?.params?.url || 'about:blank');
|
|
279
|
+
this.targetToPort.set(tid, portIndex);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// 如果是 Page.navigate 响应,更新 targetId 的 url
|
|
283
|
+
if (pending && pending.method === 'Page.navigate' && pending.sessionId && msg.result) {
|
|
284
|
+
// 找 sessionId 对应的 targetId
|
|
285
|
+
for (const [tid, pidx] of this.targetToPort.entries()) {
|
|
286
|
+
if (pidx === portIndex) {
|
|
287
|
+
// 用 pending.params.url 更新
|
|
288
|
+
if (pending.params?.url) {
|
|
289
|
+
session.targetUrls.set(tid, pending.params.url);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
276
293
|
}
|
|
277
294
|
|
|
278
295
|
// 如果是 attachToTarget 响应,记录 sessionId → portIndex
|