cdp-tunnel 3.3.0 → 3.3.1
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.
|
@@ -161,11 +161,24 @@ var SpecialHandler = (function() {
|
|
|
161
161
|
var needsNavigate = url !== 'about:blank' && url !== '';
|
|
162
162
|
|
|
163
163
|
return new Promise(function(resolve, reject) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
164
|
+
var retryCount = 0;
|
|
165
|
+
var maxRetries = 3;
|
|
166
|
+
|
|
167
|
+
function doCreate() {
|
|
168
|
+
chrome.tabs.create({ url: 'about:blank', active: false }, function(tab) {
|
|
169
|
+
if (!tab || !tab.id) {
|
|
170
|
+
retryCount++;
|
|
171
|
+
if (retryCount <= maxRetries) {
|
|
172
|
+
Logger.warn('[CreateTarget] Empty tab (tab=' + (!!tab) + '), retry ' + retryCount);
|
|
173
|
+
setTimeout(doCreate, 100 * retryCount);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
Logger.error('[CreateTarget] Failed after ' + maxRetries + ' retries');
|
|
177
|
+
reject(new Error('Failed to create tab after ' + maxRetries + ' retries'));
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
Logger.info('[CreateTarget] tab created: ' + tab.id);
|
|
169
182
|
|
|
170
183
|
if (clientId) {
|
|
171
184
|
state.setTabIdToClientId(tab.id, clientId);
|
|
@@ -189,7 +202,10 @@ var SpecialHandler = (function() {
|
|
|
189
202
|
Logger.error('[CreateTarget] Error:', err.message || err);
|
|
190
203
|
reject(err);
|
|
191
204
|
});
|
|
192
|
-
|
|
205
|
+
}); // chrome.tabs.create callback end
|
|
206
|
+
} // doCreate end
|
|
207
|
+
|
|
208
|
+
doCreate();
|
|
193
209
|
});
|
|
194
210
|
}
|
|
195
211
|
|
package/package.json
CHANGED
|
@@ -20,7 +20,8 @@ const { CONFIG } = require('./config');
|
|
|
20
20
|
|
|
21
21
|
class PortPoolManager {
|
|
22
22
|
constructor(mainProxy) {
|
|
23
|
-
this.mainProxy = mainProxy;
|
|
23
|
+
this.mainProxy = mainProxy;
|
|
24
|
+
this.idCounter = 0; // 全局唯一 id 计数器 // 现有 proxy 的引用(拿 plugin 连接)
|
|
24
25
|
this.createServers = []; // [http.Server] 每个 create 端口一个
|
|
25
26
|
this.createWss = []; // [WebSocket.Server] 每个 create 端口一个
|
|
26
27
|
this.portSessions = []; // [PortSession] 每个 create 端口一个
|
|
@@ -220,8 +221,12 @@ class PortPoolManager {
|
|
|
220
221
|
await this._ensureVisible(session, pluginWs, msg.sessionId);
|
|
221
222
|
}
|
|
222
223
|
|
|
223
|
-
//
|
|
224
|
-
const
|
|
224
|
+
// 命令:分配全局唯一 id(避免不同 client 的 msg.id 冲突)
|
|
225
|
+
const uniqueId = ++this.idCounter;
|
|
226
|
+
const newId = `pool${session.portIndex}_${uniqueId}`;
|
|
227
|
+
// 记录 originalId(用于响应时恢复)
|
|
228
|
+
if (!ws._origIds) ws._origIds = new Map();
|
|
229
|
+
ws._origIds.set(uniqueId, msg.id);
|
|
225
230
|
session.pendingRequests.set(newId, {
|
|
226
231
|
originalId: msg.id,
|
|
227
232
|
method: msg.method,
|
|
@@ -273,7 +278,10 @@ class PortPoolManager {
|
|
|
273
278
|
const pending = session.pendingRequests.get(msg.id);
|
|
274
279
|
session.pendingRequests.delete(msg.id);
|
|
275
280
|
|
|
276
|
-
// 如果是 createTarget
|
|
281
|
+
// 如果是 createTarget 响应
|
|
282
|
+
if (pending && pending.method === 'Target.createTarget') {
|
|
283
|
+
console.log('[PORT POOL] createTarget resp: ' + JSON.stringify(msg.result).slice(0, 80) + ' pending=' + !!pending);
|
|
284
|
+
}
|
|
277
285
|
if (msg.result && msg.result.targetId) {
|
|
278
286
|
const tid = msg.result.targetId;
|
|
279
287
|
session.targetIds.add(tid);
|
|
@@ -311,7 +319,7 @@ class PortPoolManager {
|
|
|
311
319
|
}
|
|
312
320
|
|
|
313
321
|
// 恢复原始 id,发给发起请求的 client
|
|
314
|
-
const response = { ...msg, id: this._parseOriginalId(originalId) };
|
|
322
|
+
const response = { ...msg, id: pending ? pending.originalId : this._parseOriginalId(originalId) };
|
|
315
323
|
delete response.__portIndex;
|
|
316
324
|
delete response.__clientId;
|
|
317
325
|
delete response.type;
|