cdp-tunnel 2.7.8 → 2.7.9
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.
|
@@ -142,10 +142,57 @@ importScripts('features/automation-badge.js');
|
|
|
142
142
|
State.removeTabIdToClientId(tabId);
|
|
143
143
|
});
|
|
144
144
|
|
|
145
|
+
if (chrome.tabGroups) {
|
|
146
|
+
chrome.tabGroups.onRemoved.addListener(function(group) {
|
|
147
|
+
if (!group) return;
|
|
148
|
+
var removedGroupId = group.id;
|
|
149
|
+
Logger.info('[TabGroups] Group removed:', removedGroupId);
|
|
150
|
+
|
|
151
|
+
var clients = State.getCDPClients() || [];
|
|
152
|
+
for (var i = 0; i < clients.length; i++) {
|
|
153
|
+
var clientId = clients[i].id;
|
|
154
|
+
if (State.getGroupIdForClient(clientId) === removedGroupId) {
|
|
155
|
+
Logger.info('[TabGroups] Clearing cached groupId for client:', clientId);
|
|
156
|
+
State.setGroupIdForClient(clientId, null);
|
|
157
|
+
|
|
158
|
+
var attached = State.getAttachedTabIds();
|
|
159
|
+
attached.forEach(function(tid) {
|
|
160
|
+
if (State.getClientIdByTabId(tid) === clientId && !State.isPreExistingTab(tid)) {
|
|
161
|
+
Logger.info('[TabGroups] Re-grouping tab', tid, 'for client:', clientId);
|
|
162
|
+
SpecialHandler.addTabToAutomationGroup(tid, clientId);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
145
171
|
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
|
|
146
172
|
if (changeInfo.status === 'complete' && State.isTabAttached(tabId)) {
|
|
147
173
|
// 不再注入自动化标识,改为通过标签分组区分
|
|
148
174
|
}
|
|
175
|
+
|
|
176
|
+
if (changeInfo.groupId !== undefined && changeInfo.groupId === -1) {
|
|
177
|
+
if (State.isTabAttached(tabId) && !State.isPreExistingTab(tabId)) {
|
|
178
|
+
var clientId = State.getClientIdByTabId(tabId);
|
|
179
|
+
if (clientId) {
|
|
180
|
+
var cachedGroupId = State.getGroupIdForClient(clientId);
|
|
181
|
+
if (cachedGroupId) {
|
|
182
|
+
Logger.info('[Tabs] Tab', tabId, 'left group, re-adding to cached group:', cachedGroupId);
|
|
183
|
+
chrome.tabs.group({ tabIds: tabId, groupId: cachedGroupId }, function() {
|
|
184
|
+
if (chrome.runtime.lastError) {
|
|
185
|
+
Logger.warn('[Tabs] Failed to re-add tab to group:', chrome.runtime.lastError.message);
|
|
186
|
+
SpecialHandler.addTabToAutomationGroup(tabId, clientId);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
} else {
|
|
190
|
+
Logger.info('[Tabs] Tab', tabId, 'left group, no cached groupId — delegating to addTabToAutomationGroup');
|
|
191
|
+
SpecialHandler.addTabToAutomationGroup(tabId, clientId);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
149
196
|
});
|
|
150
197
|
|
|
151
198
|
chrome.tabs.onCreated.addListener(function(tab) {
|
|
@@ -165,8 +165,13 @@ var SpecialHandler = (function() {
|
|
|
165
165
|
var prev = _groupQueue.get(key) || Promise.resolve();
|
|
166
166
|
|
|
167
167
|
var next = prev.then(function() {
|
|
168
|
-
return new Promise(function(resolve) {
|
|
168
|
+
return new Promise(function(resolve, reject) {
|
|
169
|
+
var timeoutId = setTimeout(function() {
|
|
170
|
+
reject(new Error('addTabToAutomationGroup timeout after 10s'));
|
|
171
|
+
}, 10000);
|
|
172
|
+
|
|
169
173
|
_addTabToAutomationGroupInner(tabId, clientId, function(success) {
|
|
174
|
+
clearTimeout(timeoutId);
|
|
170
175
|
resolve(success);
|
|
171
176
|
});
|
|
172
177
|
});
|
|
@@ -251,7 +256,16 @@ var SpecialHandler = (function() {
|
|
|
251
256
|
Logger.error('[TabGroup] tabGroups.query failed:', chrome.runtime.lastError.message);
|
|
252
257
|
EventBuilder.send('CDPTunnel.debug', { source: 'doGroup', phase: 'query', error: chrome.runtime.lastError.message });
|
|
253
258
|
}
|
|
254
|
-
|
|
259
|
+
if (!allGroups) {
|
|
260
|
+
Logger.error('[TabGroup] tabGroups.query returned null');
|
|
261
|
+
if (retries < 3) {
|
|
262
|
+
setTimeout(function() { doGroup(tabId, clientId, baseName, retries + 1, callback); }, 500);
|
|
263
|
+
} else {
|
|
264
|
+
if (callback) callback(false);
|
|
265
|
+
}
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
Logger.info('[TabGroup] query result: ' + allGroups.length + ' groups');
|
|
255
269
|
var existing = CDPUtils.findGroupByName(allGroups, baseName);
|
|
256
270
|
if (existing) {
|
|
257
271
|
Logger.info('[TabGroup] Found existing group:', existing.id, 'title:', existing.title);
|
|
@@ -197,7 +197,7 @@ var WebSocketManager = (function() {
|
|
|
197
197
|
Logger.info('[WS] Client connected, resuming event forwarding');
|
|
198
198
|
State.setHasConnectedClient(true);
|
|
199
199
|
State.addCDPClient(message.clientId, message.clientId);
|
|
200
|
-
|
|
200
|
+
createGroupForClient(message.clientId);
|
|
201
201
|
broadcastStateUpdate();
|
|
202
202
|
break;
|
|
203
203
|
|
|
@@ -221,7 +221,6 @@ var WebSocketManager = (function() {
|
|
|
221
221
|
State.removeCDPClient(discClientId);
|
|
222
222
|
if (State.getCDPClients().length === 0) {
|
|
223
223
|
State.setHasConnectedClient(false);
|
|
224
|
-
stopGroupMonitor();
|
|
225
224
|
}
|
|
226
225
|
broadcastStateUpdate();
|
|
227
226
|
});
|
|
@@ -231,11 +230,6 @@ var WebSocketManager = (function() {
|
|
|
231
230
|
Logger.info('[WS] Received client list:', message.clients);
|
|
232
231
|
State.setCDPClients(message.clients || []);
|
|
233
232
|
State.setHasConnectedClient((message.clients || []).length > 0);
|
|
234
|
-
if ((message.clients || []).length > 0) {
|
|
235
|
-
startGroupMonitor();
|
|
236
|
-
} else {
|
|
237
|
-
stopGroupMonitor();
|
|
238
|
-
}
|
|
239
233
|
broadcastStateUpdate();
|
|
240
234
|
break;
|
|
241
235
|
|
|
@@ -459,57 +453,40 @@ var WebSocketManager = (function() {
|
|
|
459
453
|
});
|
|
460
454
|
}
|
|
461
455
|
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
if (
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
456
|
+
function createGroupForClient(clientId) {
|
|
457
|
+
if (!clientId || !chrome.tabGroups) return;
|
|
458
|
+
|
|
459
|
+
var existingGroupId = State.getGroupIdForClient(clientId);
|
|
460
|
+
if (existingGroupId) {
|
|
461
|
+
Logger.info('[WS] Group already cached for client:', clientId, 'groupId:', existingGroupId);
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
var baseName = CDPUtils.getGroupBaseName(clientId);
|
|
466
|
+
chrome.tabs.query({ currentWindow: true }, function(tabs) {
|
|
467
|
+
if (!tabs || tabs.length === 0) {
|
|
468
|
+
Logger.warn('[WS] No tabs found for group creation');
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
var windowId = tabs[0].windowId;
|
|
472
|
+
chrome.tabs.group({ createProperties: { windowId: windowId } }, function(groupId) {
|
|
473
|
+
if (chrome.runtime.lastError) {
|
|
474
|
+
Logger.warn('[WS] Failed to create group on connect:', chrome.runtime.lastError.message);
|
|
478
475
|
return;
|
|
479
476
|
}
|
|
480
|
-
chrome.
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
if (tab.groupId > -1) return;
|
|
488
|
-
Logger.info('[Monitor] Tab', tabId, 'escaped! Forcing regroup for client:', clientId);
|
|
489
|
-
if (groupId) {
|
|
490
|
-
chrome.tabs.group({ tabIds: tabId, groupId: groupId }, function() {
|
|
491
|
-
if (chrome.runtime.lastError) {
|
|
492
|
-
Logger.error('[Monitor] Failed to re-add tab', tabId, 'to group', groupId, ':', chrome.runtime.lastError?.message);
|
|
493
|
-
State.removeGroupForClient(clientId);
|
|
494
|
-
SpecialHandler.addTabToAutomationGroup(tabId, clientId);
|
|
495
|
-
} else {
|
|
496
|
-
Logger.info('[Monitor] Re-added tab', tabId, 'to existing group:', groupId);
|
|
497
|
-
}
|
|
498
|
-
});
|
|
499
|
-
} else {
|
|
500
|
-
Logger.info('[Monitor] No cached groupId for client', clientId, '— delegating to addTabToAutomationGroup for tab', tabId);
|
|
501
|
-
SpecialHandler.addTabToAutomationGroup(tabId, clientId);
|
|
477
|
+
chrome.tabGroups.update(groupId, {
|
|
478
|
+
title: baseName,
|
|
479
|
+
color: CDPUtils.getGroupColorForClient(clientId),
|
|
480
|
+
collapsed: true
|
|
481
|
+
}, function() {
|
|
482
|
+
if (chrome.runtime.lastError) {
|
|
483
|
+
Logger.warn('[WS] Failed to set group title:', chrome.runtime.lastError.message);
|
|
502
484
|
}
|
|
503
485
|
});
|
|
486
|
+
State.setGroupIdForClient(clientId, groupId);
|
|
487
|
+
Logger.info('[WS] Created group for client:', clientId, 'groupId:', groupId, 'title:', baseName);
|
|
504
488
|
});
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
function stopGroupMonitor() {
|
|
509
|
-
if (_groupMonitorTimer) {
|
|
510
|
-
clearInterval(_groupMonitorTimer);
|
|
511
|
-
_groupMonitorTimer = null;
|
|
512
|
-
}
|
|
489
|
+
});
|
|
513
490
|
}
|
|
514
491
|
|
|
515
492
|
function handleServerRestart() {
|
package/package.json
CHANGED