cdp-tunnel 2.10.4 → 2.10.6
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.
|
@@ -278,6 +278,45 @@ var SpecialHandler = (function() {
|
|
|
278
278
|
});
|
|
279
279
|
return;
|
|
280
280
|
}
|
|
281
|
+
var groupPromise = state ? state.getGroupCreationPromise(clientId) : null;
|
|
282
|
+
if (groupPromise) {
|
|
283
|
+
Logger.info('[TabGroup] No cached groupId, waiting for _createGroupForClient promise for client:', clientId);
|
|
284
|
+
var waited = false;
|
|
285
|
+
var waitTimer = setTimeout(function() {
|
|
286
|
+
if (waited) return;
|
|
287
|
+
waited = true;
|
|
288
|
+
Logger.warn('[TabGroup] _createGroupForClient wait timed out (3s) for client:', clientId);
|
|
289
|
+
doGroupQuery(tabId, clientId, baseName, retries, callback, context);
|
|
290
|
+
}, 3000);
|
|
291
|
+
groupPromise.then(function(resolvedId) {
|
|
292
|
+
if (waited) return;
|
|
293
|
+
clearTimeout(waitTimer);
|
|
294
|
+
waited = true;
|
|
295
|
+
if (resolvedId) {
|
|
296
|
+
Logger.info('[TabGroup] _createGroupForClient resolved with groupId:', resolvedId);
|
|
297
|
+
chrome.tabs.group({ tabIds: tabId, groupId: resolvedId }, function() {
|
|
298
|
+
if (chrome.runtime.lastError) {
|
|
299
|
+
Logger.warn('[TabGroup] Failed to add tab to resolved group:', chrome.runtime.lastError.message);
|
|
300
|
+
doGroupQuery(tabId, clientId, baseName, retries, callback, context);
|
|
301
|
+
} else {
|
|
302
|
+
updateTabGroupName(clientId, state, wsManager, context ? context.mode : null);
|
|
303
|
+
Logger.info('[TabGroup] Tab', tabId, 'added to pre-created group:', resolvedId);
|
|
304
|
+
if (callback) callback(true);
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
} else {
|
|
308
|
+
Logger.warn('[TabGroup] _createGroupForClient resolved with null');
|
|
309
|
+
doGroupQuery(tabId, clientId, baseName, retries, callback, context);
|
|
310
|
+
}
|
|
311
|
+
}).catch(function(err) {
|
|
312
|
+
if (waited) return;
|
|
313
|
+
clearTimeout(waitTimer);
|
|
314
|
+
waited = true;
|
|
315
|
+
Logger.error('[TabGroup] _createGroupForClient promise rejected:', err);
|
|
316
|
+
doGroupQuery(tabId, clientId, baseName, retries, callback, context);
|
|
317
|
+
});
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
281
320
|
doGroupQuery(tabId, clientId, baseName, retries, callback, context);
|
|
282
321
|
}
|
|
283
322
|
|
|
@@ -334,6 +373,7 @@ var SpecialHandler = (function() {
|
|
|
334
373
|
Logger.info('[TabGroup] chrome.tabs.group returned groupId:', groupId);
|
|
335
374
|
EventBuilder.send('CDPTunnel.debug', { source: 'doGroup', phase: 'groupCreated', tabId: tabId, groupId: groupId }, null, wsManager);
|
|
336
375
|
if (groupId) {
|
|
376
|
+
if (state) state.setGroupIdForClient(clientId, groupId);
|
|
337
377
|
if (chrome.tabGroups) {
|
|
338
378
|
chrome.tabGroups.update(groupId, {
|
|
339
379
|
title: baseName,
|
|
@@ -344,14 +384,12 @@ var SpecialHandler = (function() {
|
|
|
344
384
|
Logger.error('[TabGroup] Failed to update group:', chrome.runtime.lastError.message);
|
|
345
385
|
EventBuilder.send('CDPTunnel.debug', { source: 'doGroup', phase: 'updateGroup', error: chrome.runtime.lastError.message, groupId: groupId }, null, wsManager);
|
|
346
386
|
} else {
|
|
347
|
-
if (state) state.setGroupIdForClient(clientId, groupId);
|
|
348
387
|
updateTabGroupName(clientId, state, wsManager, context ? context.mode : null);
|
|
349
388
|
Logger.info('[TabGroup] Group updated:', groupId, baseName);
|
|
350
389
|
}
|
|
351
390
|
if (callback) callback(true);
|
|
352
391
|
});
|
|
353
392
|
} else {
|
|
354
|
-
if (state) state.setGroupIdForClient(clientId, groupId);
|
|
355
393
|
Logger.info('[TabGroup] Group created but tabGroups.update unavailable (headless):', groupId);
|
|
356
394
|
if (callback) callback(true);
|
|
357
395
|
}
|
|
@@ -241,6 +241,7 @@ var WebSocketConnection = (function() {
|
|
|
241
241
|
Logger.info('[WS:' + self.connectionId + '] Client connected, resuming event forwarding');
|
|
242
242
|
self.state.setHasConnectedClient(true);
|
|
243
243
|
self.state.addCDPClient(message.clientId, message.clientId);
|
|
244
|
+
self._createGroupForClient(message.clientId, message.__mode);
|
|
244
245
|
self._broadcastStateUpdate();
|
|
245
246
|
break;
|
|
246
247
|
|
|
@@ -294,6 +295,7 @@ var WebSocketConnection = (function() {
|
|
|
294
295
|
Logger.info('[WS:' + self.connectionId + '] Client disconnected:', message.clientId);
|
|
295
296
|
var discClientId = message.clientId;
|
|
296
297
|
self._groupCreationPending.delete(discClientId);
|
|
298
|
+
self.state.setGroupCreationPromise(discClientId, null);
|
|
297
299
|
self._closeTabGroupByClientId(discClientId).then(function() {
|
|
298
300
|
return new Promise(function(resolve) {
|
|
299
301
|
self._closeTabsByClientId(discClientId, resolve);
|
|
@@ -571,11 +573,17 @@ var WebSocketConnection = (function() {
|
|
|
571
573
|
|
|
572
574
|
self._groupCreationPending.add(clientId);
|
|
573
575
|
|
|
576
|
+
var resolveGroupReady;
|
|
577
|
+
var readyPromise = new Promise(function(resolve) { resolveGroupReady = resolve; });
|
|
578
|
+
self.state.setGroupCreationPromise(clientId, readyPromise);
|
|
579
|
+
|
|
574
580
|
var baseName = CDPUtils.getGroupBaseName(clientId, self.config ? self.config.tag : null, mode);
|
|
575
581
|
chrome.tabs.query({ currentWindow: true }, function(tabs) {
|
|
576
582
|
if (!tabs || tabs.length === 0) {
|
|
577
583
|
Logger.warn('[WS:' + self.connectionId + '] No tabs found for group creation');
|
|
578
584
|
self._groupCreationPending.delete(clientId);
|
|
585
|
+
self.state.setGroupCreationPromise(clientId, null);
|
|
586
|
+
resolveGroupReady(null);
|
|
579
587
|
return;
|
|
580
588
|
}
|
|
581
589
|
var windowId = tabs[0].windowId;
|
|
@@ -583,9 +591,14 @@ var WebSocketConnection = (function() {
|
|
|
583
591
|
if (chrome.runtime.lastError) {
|
|
584
592
|
Logger.warn('[WS:' + self.connectionId + '] Failed to create group on connect:', chrome.runtime.lastError.message);
|
|
585
593
|
self._groupCreationPending.delete(clientId);
|
|
594
|
+
self.state.setGroupCreationPromise(clientId, null);
|
|
595
|
+
resolveGroupReady(null);
|
|
586
596
|
return;
|
|
587
597
|
}
|
|
588
598
|
self._groupCreationPending.delete(clientId);
|
|
599
|
+
self.state.setGroupIdForClient(clientId, groupId);
|
|
600
|
+
self.state.setGroupCreationPromise(clientId, null);
|
|
601
|
+
resolveGroupReady(groupId);
|
|
589
602
|
chrome.tabGroups.update(groupId, {
|
|
590
603
|
title: baseName,
|
|
591
604
|
color: CDPUtils.getGroupColorForClient(clientId),
|
|
@@ -595,7 +608,6 @@ var WebSocketConnection = (function() {
|
|
|
595
608
|
Logger.warn('[WS:' + self.connectionId + '] Failed to set group title:', chrome.runtime.lastError.message);
|
|
596
609
|
}
|
|
597
610
|
});
|
|
598
|
-
self.state.setGroupIdForClient(clientId, groupId);
|
|
599
611
|
Logger.info('[WS:' + self.connectionId + '] Created group for client:', clientId, 'groupId:', groupId, 'title:', baseName);
|
|
600
612
|
});
|
|
601
613
|
});
|
package/package.json
CHANGED