cdp-tunnel 2.5.19 → 2.5.21
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.
|
@@ -162,6 +162,8 @@ var SpecialHandler = (function() {
|
|
|
162
162
|
function addTabToAutomationGroup(tabId, clientId) {
|
|
163
163
|
Logger.info('[TabGroup] Starting addTabToAutomationGroup for tabId:', tabId, 'clientId:', clientId);
|
|
164
164
|
|
|
165
|
+
WebSocketManager.send({ type: 'tabgroup-debug', tabId: tabId, clientId: clientId, phase: 'start' });
|
|
166
|
+
|
|
165
167
|
setTimeout(function() {
|
|
166
168
|
muteTabIfNeeded(tabId);
|
|
167
169
|
}, 200);
|
|
@@ -185,12 +187,20 @@ var SpecialHandler = (function() {
|
|
|
185
187
|
|
|
186
188
|
function doGroup(tabId, clientId, baseName, retries) {
|
|
187
189
|
retries = retries || 0;
|
|
190
|
+
Logger.info('[TabGroup] doGroup: tabId=' + tabId + ' clientId=' + (clientId || 'none') + ' baseName=' + baseName + ' retry=' + retries);
|
|
188
191
|
chrome.tabGroups.query({}, function(allGroups) {
|
|
192
|
+
if (chrome.runtime.lastError) {
|
|
193
|
+
Logger.error('[TabGroup] tabGroups.query failed:', chrome.runtime.lastError.message);
|
|
194
|
+
EventBuilder.send('CDPTunnel.debug', { source: 'doGroup', phase: 'query', error: chrome.runtime.lastError.message });
|
|
195
|
+
}
|
|
196
|
+
Logger.info('[TabGroup] query result: ' + (allGroups ? allGroups.length : 'null') + ' groups');
|
|
189
197
|
var existing = CDPUtils.findGroupByName(allGroups, baseName);
|
|
190
198
|
if (existing) {
|
|
199
|
+
Logger.info('[TabGroup] Found existing group:', existing.id, 'title:', existing.title);
|
|
191
200
|
chrome.tabs.group({ tabIds: tabId, groupId: existing.id }, function(result) {
|
|
192
201
|
if (chrome.runtime.lastError) {
|
|
193
202
|
Logger.error('[TabGroup] Failed to add tab to group:', chrome.runtime.lastError.message, 'retries:', retries);
|
|
203
|
+
EventBuilder.send('CDPTunnel.debug', { source: 'doGroup', phase: 'addToExisting', error: chrome.runtime.lastError.message, tabId: tabId, groupId: existing.id });
|
|
194
204
|
if (retries < 3) {
|
|
195
205
|
setTimeout(function() { doGroup(tabId, clientId, baseName, retries + 1); }, 500);
|
|
196
206
|
}
|
|
@@ -201,14 +211,18 @@ var SpecialHandler = (function() {
|
|
|
201
211
|
}
|
|
202
212
|
});
|
|
203
213
|
} else {
|
|
214
|
+
Logger.info('[TabGroup] No existing group, creating new one for tab:', tabId);
|
|
204
215
|
chrome.tabs.group({ tabIds: tabId }, function(groupId) {
|
|
205
216
|
if (chrome.runtime.lastError) {
|
|
206
217
|
Logger.error('[TabGroup] Failed to create group:', chrome.runtime.lastError.message, 'retries:', retries);
|
|
218
|
+
EventBuilder.send('CDPTunnel.debug', { source: 'doGroup', phase: 'createGroup', error: chrome.runtime.lastError.message, tabId: tabId });
|
|
207
219
|
if (retries < 3) {
|
|
208
220
|
setTimeout(function() { doGroup(tabId, clientId, baseName, retries + 1); }, 500);
|
|
209
221
|
}
|
|
210
222
|
return;
|
|
211
223
|
}
|
|
224
|
+
Logger.info('[TabGroup] chrome.tabs.group returned groupId:', groupId);
|
|
225
|
+
EventBuilder.send('CDPTunnel.debug', { source: 'doGroup', phase: 'groupCreated', tabId: tabId, groupId: groupId });
|
|
212
226
|
if (groupId) {
|
|
213
227
|
chrome.tabGroups.update(groupId, {
|
|
214
228
|
title: baseName,
|
|
@@ -217,12 +231,15 @@ var SpecialHandler = (function() {
|
|
|
217
231
|
}, function() {
|
|
218
232
|
if (chrome.runtime.lastError) {
|
|
219
233
|
Logger.error('[TabGroup] Failed to update group:', chrome.runtime.lastError.message);
|
|
234
|
+
EventBuilder.send('CDPTunnel.debug', { source: 'doGroup', phase: 'updateGroup', error: chrome.runtime.lastError.message, groupId: groupId });
|
|
220
235
|
} else {
|
|
221
236
|
State.setGroupIdForClient(clientId, groupId);
|
|
222
237
|
updateTabGroupName(clientId);
|
|
223
238
|
Logger.info('[TabGroup] Created new group:', groupId, 'with tab:', tabId);
|
|
224
239
|
}
|
|
225
240
|
});
|
|
241
|
+
} else {
|
|
242
|
+
Logger.error('[TabGroup] chrome.tabs.group returned null groupId');
|
|
226
243
|
}
|
|
227
244
|
});
|
|
228
245
|
}
|
|
@@ -263,6 +263,10 @@ var State = (function() {
|
|
|
263
263
|
return _state.cdpCreatedTabIds.has(tabId);
|
|
264
264
|
}
|
|
265
265
|
|
|
266
|
+
function getCDPCreatedTabIds() {
|
|
267
|
+
return Array.from(_state.cdpCreatedTabIds);
|
|
268
|
+
}
|
|
269
|
+
|
|
266
270
|
function clearAllState() {
|
|
267
271
|
clearSessionState();
|
|
268
272
|
_state.attachedTabIds.clear();
|
|
@@ -506,6 +510,7 @@ var State = (function() {
|
|
|
506
510
|
removePreExistingTab: removePreExistingTab,
|
|
507
511
|
clearPreExistingTabsForClient: clearPreExistingTabsForClient,
|
|
508
512
|
addCDPCreatedTab: addCDPCreatedTab,
|
|
509
|
-
isCDPCreatedTab: isCDPCreatedTab
|
|
513
|
+
isCDPCreatedTab: isCDPCreatedTab,
|
|
514
|
+
getCDPCreatedTabIds: getCDPCreatedTabIds
|
|
510
515
|
};
|
|
511
516
|
})();
|
|
@@ -339,23 +339,40 @@ var WebSocketManager = (function() {
|
|
|
339
339
|
|
|
340
340
|
function closeTabsByClientId(clientId, resolve) {
|
|
341
341
|
var attachedTabs = State.getAttachedTabIds();
|
|
342
|
+
var cdpCreatedTabs = State.getCDPCreatedTabIds();
|
|
342
343
|
var tabsToClose = [];
|
|
344
|
+
var tabsToCloseSet = new Set();
|
|
345
|
+
|
|
346
|
+
Logger.info('[WS] closeTabsByClientId: clientId=' + clientId + ' attachedTabs=' + JSON.stringify(attachedTabs) + ' cdpCreatedTabs=' + JSON.stringify(cdpCreatedTabs));
|
|
343
347
|
|
|
344
|
-
Logger.info('[WS] closeTabsByClientId: clientId=' + clientId + ' attachedTabs=' + JSON.stringify(attachedTabs));
|
|
345
348
|
attachedTabs.forEach(function(tabId) {
|
|
346
349
|
var tabClientId = State.getClientIdByTabId(tabId);
|
|
347
350
|
var isPre = State.isPreExistingTab(tabId);
|
|
348
351
|
var isCDP = State.isCDPCreatedTab(tabId);
|
|
349
|
-
Logger.info('[WS] tabId=' + tabId + ' clientId=' + tabClientId + ' isPre=' + isPre + ' isCDP=' + isCDP);
|
|
352
|
+
Logger.info('[WS] [attached] tabId=' + tabId + ' clientId=' + tabClientId + ' isPre=' + isPre + ' isCDP=' + isCDP);
|
|
350
353
|
if (tabClientId === clientId && !isPre) {
|
|
351
|
-
|
|
354
|
+
tabsToCloseSet.add(tabId);
|
|
352
355
|
}
|
|
353
356
|
});
|
|
354
357
|
|
|
358
|
+
cdpCreatedTabs.forEach(function(tabId) {
|
|
359
|
+
if (tabsToCloseSet.has(tabId)) return;
|
|
360
|
+
|
|
361
|
+
var tabClientId = State.getClientIdByTabId(tabId);
|
|
362
|
+
var isPre = State.isPreExistingTab(tabId);
|
|
363
|
+
Logger.info('[WS] [cdpCreated] tabId=' + tabId + ' clientId=' + tabClientId + ' isPre=' + isPre + ' isAttached=' + attachedTabs.includes(tabId));
|
|
364
|
+
if (tabClientId === clientId && !isPre && !attachedTabs.includes(tabId)) {
|
|
365
|
+
tabsToCloseSet.add(tabId);
|
|
366
|
+
Logger.info('[WS] -> Added to close list (not yet attached)');
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
tabsToClose = Array.from(tabsToCloseSet);
|
|
371
|
+
|
|
355
372
|
Logger.info('[WS] closeTabsByClientId: will close ' + tabsToClose.length + ' tabs');
|
|
356
373
|
|
|
357
374
|
if (tabsToClose.length === 0) {
|
|
358
|
-
Logger.info('[WS] No
|
|
375
|
+
Logger.info('[WS] No tabs found for clientId:', clientId);
|
|
359
376
|
resolve();
|
|
360
377
|
return;
|
|
361
378
|
}
|
package/package.json
CHANGED
package/server/proxy-server.js
CHANGED
|
@@ -633,11 +633,18 @@ function handlePluginConnection(ws, clientInfo) {
|
|
|
633
633
|
|
|
634
634
|
console.log(`[PLUGIN MSG] id=${parsed?.id} method=${parsed?.method || 'none'} type=${parsed?.type || 'none'} sessionId=${parsed?.sessionId?.substring(0,8) || 'none'}`);
|
|
635
635
|
|
|
636
|
+
if (parsed?.type === 'tabgroup-debug') {
|
|
637
|
+
console.log(`[TABGROUP DEBUG] ${JSON.stringify(parsed)}`);
|
|
638
|
+
}
|
|
639
|
+
|
|
636
640
|
// 记录所有 PLUGIN -> CLIENT 消息到日志文件
|
|
637
641
|
logCDP('PLUGIN -> CLIENT', data.toString().substring(0, CONFIG.LOG_MESSAGE_PREVIEW_LENGTH), parsed?.sessionId, ws.pluginType);
|
|
638
642
|
|
|
639
643
|
// 处理 type: 'event' 消息(来自 background.js 的 screencast 等事件)
|
|
640
644
|
if (parsed && parsed.type === 'event' && parsed.method) {
|
|
645
|
+
if (parsed.method.startsWith('CDPTunnel.')) {
|
|
646
|
+
console.log(`[EXT DEBUG] ${parsed.method}: ${JSON.stringify(parsed.params)}`);
|
|
647
|
+
}
|
|
641
648
|
// 对于 Target 事件,始终广播给所有客户端
|
|
642
649
|
const targetEvents = ['Target.targetCreated', 'Target.attachedToTarget', 'Target.targetDestroyed', 'Target.targetInfoChanged'];
|
|
643
650
|
if (targetEvents.includes(parsed.method)) {
|