cdp-tunnel 2.5.5 → 2.5.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.
|
@@ -138,8 +138,14 @@ var SpecialHandler = (function() {
|
|
|
138
138
|
|
|
139
139
|
var groupClientId = clientId;
|
|
140
140
|
if (!groupClientId) {
|
|
141
|
-
|
|
142
|
-
|
|
141
|
+
var cdpClients = State.getCDPClients() || [];
|
|
142
|
+
if (cdpClients.length > 0 && cdpClients[0] && cdpClients[0].id) {
|
|
143
|
+
groupClientId = cdpClients[0].id;
|
|
144
|
+
Logger.warn('[TabGroup] No clientId for tab:', tabId, 'fallback to first client:', groupClientId);
|
|
145
|
+
} else {
|
|
146
|
+
Logger.warn('[TabGroup] No clientId for tab:', tabId, '— skipping group operation');
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
143
149
|
}
|
|
144
150
|
var baseName = CDPUtils.getGroupBaseName(groupClientId);
|
|
145
151
|
|
|
@@ -167,13 +173,17 @@ var SpecialHandler = (function() {
|
|
|
167
173
|
tryGroup();
|
|
168
174
|
}
|
|
169
175
|
|
|
170
|
-
function doGroup(tabId, clientId, baseName) {
|
|
176
|
+
function doGroup(tabId, clientId, baseName, retries) {
|
|
177
|
+
retries = retries || 0;
|
|
171
178
|
chrome.tabGroups.query({}, function(allGroups) {
|
|
172
179
|
var existing = CDPUtils.findGroupByName(allGroups, baseName);
|
|
173
180
|
if (existing) {
|
|
174
181
|
chrome.tabs.group({ tabIds: tabId, groupId: existing.id }, function(result) {
|
|
175
182
|
if (chrome.runtime.lastError) {
|
|
176
|
-
Logger.error('[TabGroup] Failed to add tab to group:', chrome.runtime.lastError.message);
|
|
183
|
+
Logger.error('[TabGroup] Failed to add tab to group:', chrome.runtime.lastError.message, 'retries:', retries);
|
|
184
|
+
if (retries < 3) {
|
|
185
|
+
setTimeout(function() { doGroup(tabId, clientId, baseName, retries + 1); }, 500);
|
|
186
|
+
}
|
|
177
187
|
} else {
|
|
178
188
|
State.setGroupIdForClient(clientId, existing.id);
|
|
179
189
|
updateTabGroupName(clientId);
|
|
@@ -183,7 +193,10 @@ var SpecialHandler = (function() {
|
|
|
183
193
|
} else {
|
|
184
194
|
chrome.tabs.group({ tabIds: tabId }, function(groupId) {
|
|
185
195
|
if (chrome.runtime.lastError) {
|
|
186
|
-
Logger.error('[TabGroup] Failed to create group:', chrome.runtime.lastError.message);
|
|
196
|
+
Logger.error('[TabGroup] Failed to create group:', chrome.runtime.lastError.message, 'retries:', retries);
|
|
197
|
+
if (retries < 3) {
|
|
198
|
+
setTimeout(function() { doGroup(tabId, clientId, baseName, retries + 1); }, 500);
|
|
199
|
+
}
|
|
187
200
|
return;
|
|
188
201
|
}
|
|
189
202
|
if (groupId) {
|
|
@@ -392,27 +392,44 @@ var WebSocketManager = (function() {
|
|
|
392
392
|
if (_groupMonitorTimer) clearInterval(_groupMonitorTimer);
|
|
393
393
|
_groupMonitorTimer = setInterval(function() {
|
|
394
394
|
var attached = State.getAttachedTabIds();
|
|
395
|
+
Logger.info('[Monitor] Checking ' + attached.length + ' attached tabs for grouping...');
|
|
395
396
|
attached.forEach(function(tabId) {
|
|
396
397
|
var clientId = State.getClientIdByTabId(tabId);
|
|
397
|
-
if (!clientId)
|
|
398
|
-
|
|
398
|
+
if (!clientId) {
|
|
399
|
+
Logger.warn('[Monitor] Tab', tabId, 'has no clientId mapping, cannot group');
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
if (State.isPreExistingTab(tabId)) {
|
|
403
|
+
Logger.info('[Monitor] Tab', tabId, 'is pre-existing, skipping');
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
399
406
|
chrome.tabs.get(tabId, function(tab) {
|
|
400
|
-
if (chrome.runtime.lastError || !tab)
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
407
|
+
if (chrome.runtime.lastError || !tab) {
|
|
408
|
+
Logger.error('[Monitor] Tab', tabId, 'not found:', chrome.runtime.lastError?.message);
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
404
411
|
var groupId = State.getGroupIdForClient(clientId);
|
|
412
|
+
Logger.info('[Monitor] Tab', tabId, 'groupId=' + (tab.groupId || 'none'), 'expectedGroup=' + (groupId || 'none'), 'clientId=' + (clientId || 'none'));
|
|
413
|
+
if (tab.groupId) return;
|
|
414
|
+
Logger.info('[Monitor] Tab', tabId, 'escaped! Forcing regroup for client:', clientId);
|
|
405
415
|
if (groupId) {
|
|
406
|
-
chrome.tabs.group({ tabIds: tabId, groupId: groupId }, function() {
|
|
416
|
+
chrome.tabs.group({ tabIds: tabId, groupId: groupId }, function() {
|
|
417
|
+
Logger.info('[Monitor] Re-added tab', tabId, 'to existing group:', groupId);
|
|
418
|
+
});
|
|
407
419
|
} else {
|
|
420
|
+
var baseName = CDPUtils.getGroupBaseName(clientId);
|
|
408
421
|
chrome.tabs.group({ tabIds: tabId }, function(newGroupId) {
|
|
409
|
-
if (chrome.runtime.lastError || !newGroupId)
|
|
422
|
+
if (chrome.runtime.lastError || !newGroupId) {
|
|
423
|
+
Logger.error('[Monitor] Failed to create group for tab', tabId, ':', chrome.runtime.lastError?.message);
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
410
426
|
chrome.tabGroups.update(newGroupId, {
|
|
411
427
|
title: baseName,
|
|
412
428
|
color: CDPUtils.getGroupColorForClient(clientId),
|
|
413
429
|
collapsed: true
|
|
414
430
|
}, function() {
|
|
415
431
|
State.setGroupIdForClient(clientId, newGroupId);
|
|
432
|
+
Logger.info('[Monitor] Created new group', newGroupId, 'for escaped tab', tabId);
|
|
416
433
|
});
|
|
417
434
|
});
|
|
418
435
|
}
|
|
@@ -420,6 +437,10 @@ var WebSocketManager = (function() {
|
|
|
420
437
|
});
|
|
421
438
|
}, 5000);
|
|
422
439
|
}
|
|
440
|
+
});
|
|
441
|
+
});
|
|
442
|
+
}, 5000);
|
|
443
|
+
}
|
|
423
444
|
|
|
424
445
|
function stopGroupMonitor() {
|
|
425
446
|
if (_groupMonitorTimer) {
|
package/package.json
CHANGED