cdp-tunnel 2.10.5 → 2.10.7
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.
|
@@ -178,6 +178,7 @@ importScripts('features/automation-badge.js');
|
|
|
178
178
|
if (state.getGroupIdForClient(clientId) === removedGroupId) {
|
|
179
179
|
Logger.info('[TabGroups] Clearing cached groupId for client:', clientId);
|
|
180
180
|
state.setGroupIdForClient(clientId, null);
|
|
181
|
+
state.setGroupCreationPromise(clientId, null);
|
|
181
182
|
|
|
182
183
|
var attached = state.getAttachedTabIds();
|
|
183
184
|
attached.forEach(function(tid) {
|
|
@@ -209,19 +210,20 @@ importScripts('features/automation-badge.js');
|
|
|
209
210
|
var clientId = state.getClientIdByTabId(tabId);
|
|
210
211
|
if (clientId) {
|
|
211
212
|
var cachedGroupId = state.getGroupIdForClient(clientId);
|
|
213
|
+
var groupPromise = state.getGroupCreationPromise(clientId);
|
|
212
214
|
if (cachedGroupId) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
215
|
+
Logger.info('[Tabs] Tab', tabId, 'left group, re-adding to cached group:', cachedGroupId);
|
|
216
|
+
chrome.tabs.group({ tabIds: tabId, groupId: cachedGroupId }, function() {
|
|
217
|
+
if (chrome.runtime.lastError) {
|
|
218
|
+
Logger.warn('[Tabs] Failed to re-add tab to group:', chrome.runtime.lastError.message);
|
|
219
|
+
var ctx = { _state: state, _wsManager: wsManager, clientId: clientId, mode: state.mode };
|
|
220
|
+
SpecialHandler.addTabToAutomationGroup(tabId, clientId, null, ctx);
|
|
219
221
|
}
|
|
220
222
|
});
|
|
223
|
+
} else if (!groupPromise) {
|
|
224
|
+
Logger.info('[Tabs] Tab', tabId, 'left group, no cache and no pending creation — skipping (onRemoved handles re-group)');
|
|
221
225
|
} else {
|
|
222
|
-
Logger.info('[Tabs] Tab', tabId, 'left group,
|
|
223
|
-
var ctx = { _state: state, _wsManager: wsManager, clientId: clientId, mode: state.mode };
|
|
224
|
-
SpecialHandler.addTabToAutomationGroup(tabId, clientId, null, ctx);
|
|
226
|
+
Logger.info('[Tabs] Tab', tabId, 'left group, group creation pending — skipping');
|
|
225
227
|
}
|
|
226
228
|
}
|
|
227
229
|
}
|
|
@@ -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
|
|
|
@@ -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);
|
|
@@ -312,6 +314,7 @@ var WebSocketConnection = (function() {
|
|
|
312
314
|
if (self.state.getCDPClients().length === 0) {
|
|
313
315
|
self.state.setHasConnectedClient(false);
|
|
314
316
|
}
|
|
317
|
+
self._cleanupStaleState(discClientId);
|
|
315
318
|
self._broadcastStateUpdate();
|
|
316
319
|
});
|
|
317
320
|
break;
|
|
@@ -372,7 +375,6 @@ var WebSocketConnection = (function() {
|
|
|
372
375
|
return new Promise(function(resolve) {
|
|
373
376
|
var timeoutId = setTimeout(function() {
|
|
374
377
|
Logger.warn('[WS:' + self.connectionId + '] closeTabGroupByClientId timeout for client:', clientId, '— forcing cleanup');
|
|
375
|
-
self._cleanupStaleState(clientId);
|
|
376
378
|
resolve();
|
|
377
379
|
}, 5000);
|
|
378
380
|
|
|
@@ -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
|
+
if (!self.state.getGroupIdForClient(clientId)) {
|
|
600
|
+
self.state.setGroupIdForClient(clientId, groupId);
|
|
601
|
+
}
|
|
589
602
|
chrome.tabGroups.update(groupId, {
|
|
590
603
|
title: baseName,
|
|
591
604
|
color: CDPUtils.getGroupColorForClient(clientId),
|
|
@@ -594,9 +607,10 @@ var WebSocketConnection = (function() {
|
|
|
594
607
|
if (chrome.runtime.lastError) {
|
|
595
608
|
Logger.warn('[WS:' + self.connectionId + '] Failed to set group title:', chrome.runtime.lastError.message);
|
|
596
609
|
}
|
|
610
|
+
self.state.setGroupCreationPromise(clientId, null);
|
|
611
|
+
resolveGroupReady(groupId);
|
|
612
|
+
Logger.info('[WS:' + self.connectionId + '] Created group for client:', clientId, 'groupId:', groupId, 'title:', baseName);
|
|
597
613
|
});
|
|
598
|
-
self.state.setGroupIdForClient(clientId, groupId);
|
|
599
|
-
Logger.info('[WS:' + self.connectionId + '] Created group for client:', clientId, 'groupId:', groupId, 'title:', baseName);
|
|
600
614
|
});
|
|
601
615
|
});
|
|
602
616
|
};
|
package/package.json
CHANGED