cdp-tunnel 3.5.0 → 3.6.1
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.
- package/README.md +222 -133
- package/extension-new/background.js +6 -2
- package/extension-new/cdp/handler/forward.js +10 -1
- package/extension-new/cdp/handler/local.js +31 -6
- package/extension-new/cdp/handler/special.js +12 -12
- package/extension-new/cdp/index.js +1 -3
- package/extension-new/core/connection-state.js +9 -13
- package/extension-new/core/debugger.js +0 -5
- package/extension-new/core/state.js +0 -8
- package/extension-new/core/websocket.js +8 -18
- package/extension-new/manifest.json +1 -1
- package/extension-new/utils/config.js +1 -1
- package/extension-new/utils/helpers.js +9 -3
- package/package.json +1 -1
- package/server/admin-console.html +481 -0
- package/server/modules/port-pool.js +48 -6
- package/server/proxy-server.js +269 -99
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
function ConnectionState(connectionId, mode) {
|
|
2
2
|
this.connectionId = connectionId;
|
|
3
3
|
this.mode = mode || 'create';
|
|
4
|
-
this.connectionTag = null;
|
|
5
4
|
this.clientIdToTag = new Map();
|
|
6
5
|
this.ws = null;
|
|
7
6
|
this.reconnectTimer = null;
|
|
8
7
|
this._hasConnectedClient = false;
|
|
9
8
|
this.cdpClients = [];
|
|
10
9
|
this.currentTabId = null;
|
|
11
|
-
this.isAttached = false;
|
|
12
10
|
|
|
13
11
|
this.sessionIdToTabId = new Map();
|
|
14
12
|
this.sessionIdToTargetId = new Map();
|
|
@@ -308,6 +306,15 @@ ConnectionState.prototype.getTagForClient = function(clientId) {
|
|
|
308
306
|
return this.clientIdToTag.get(clientId) || null;
|
|
309
307
|
};
|
|
310
308
|
|
|
309
|
+
ConnectionState.prototype.setGroupNameForClient = function(clientId, groupName) {
|
|
310
|
+
if (!this.clientIdToGroupName) this.clientIdToGroupName = new Map();
|
|
311
|
+
if (clientId && groupName) this.clientIdToGroupName.set(clientId, groupName);
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
ConnectionState.prototype.getGroupNameForClient = function(clientId) {
|
|
315
|
+
return (this.clientIdToGroupName && this.clientIdToGroupName.get(clientId)) || null;
|
|
316
|
+
};
|
|
317
|
+
|
|
311
318
|
ConnectionState.prototype.addCDPClient = function(clientId, info) {
|
|
312
319
|
var exists = false;
|
|
313
320
|
for (var i = 0; i < this.cdpClients.length; i++) {
|
|
@@ -363,18 +370,7 @@ ConnectionState.prototype.clearAllState = function() {
|
|
|
363
370
|
|
|
364
371
|
ConnectionState.prototype.persist = function(tabId, attached) {
|
|
365
372
|
this.currentTabId = tabId;
|
|
366
|
-
this.isAttached = attached;
|
|
367
373
|
return new Promise(function(resolve) {
|
|
368
374
|
chrome.storage.local.set({ currentTabId: tabId, isAttached: attached }, resolve);
|
|
369
375
|
}.bind(this));
|
|
370
376
|
};
|
|
371
|
-
|
|
372
|
-
ConnectionState.prototype.loadPersisted = function() {
|
|
373
|
-
return new Promise(function(resolve) {
|
|
374
|
-
chrome.storage.local.get(['currentTabId', 'isAttached'], function(result) {
|
|
375
|
-
this.currentTabId = result.currentTabId || null;
|
|
376
|
-
this.isAttached = result.isAttached || false;
|
|
377
|
-
resolve(result);
|
|
378
|
-
}.bind(this));
|
|
379
|
-
}.bind(this));
|
|
380
|
-
};
|
|
@@ -187,10 +187,6 @@ var DebuggerManager = (function() {
|
|
|
187
187
|
});
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
-
function isAttached(tabId) {
|
|
191
|
-
return getActualAttachState(tabId);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
190
|
function getActualAttachState(tabId) {
|
|
195
191
|
return chrome.debugger.getTargets().then(function(targets) {
|
|
196
192
|
var target = targets.find(function(t) {
|
|
@@ -364,7 +360,6 @@ var DebuggerManager = (function() {
|
|
|
364
360
|
return {
|
|
365
361
|
attach: attach,
|
|
366
362
|
detach: detach,
|
|
367
|
-
isAttached: isAttached,
|
|
368
363
|
getActualAttachState: getActualAttachState,
|
|
369
364
|
handleDebuggerEvent: handleDebuggerEvent,
|
|
370
365
|
handleDetach: handleDetach
|
|
@@ -62,14 +62,6 @@ var State = (function() {
|
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
function persist(tabId, attached) {
|
|
66
|
-
_state.currentTabId = tabId;
|
|
67
|
-
_state.isAttached = attached;
|
|
68
|
-
return new Promise(function(resolve) {
|
|
69
|
-
chrome.storage.local.set({ currentTabId: tabId, isAttached: attached }, resolve);
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
65
|
function isTabAttached(tabId) {
|
|
74
66
|
var entry = ConnectionManager.getConnectionByTabId(tabId);
|
|
75
67
|
return entry ? entry.state.isTabAttached(tabId) : false;
|
|
@@ -244,7 +244,12 @@ var WebSocketConnection = (function() {
|
|
|
244
244
|
if (message.__connectionTag) {
|
|
245
245
|
self.state.setTagForClient(message.clientId, message.__connectionTag);
|
|
246
246
|
}
|
|
247
|
-
|
|
247
|
+
// 存 groupName,供 doGroup 等后续分组操作使用
|
|
248
|
+
if (message.__groupName) {
|
|
249
|
+
self.state.setGroupNameForClient(message.clientId, message.__groupName);
|
|
250
|
+
}
|
|
251
|
+
// __groupName 来自 API Key 名称,用作 Chrome 分组名(一眼看出是谁的浏览器)
|
|
252
|
+
self._createGroupForClient(message.clientId, message.__mode, message.__groupName);
|
|
248
253
|
self._broadcastStateUpdate();
|
|
249
254
|
break;
|
|
250
255
|
|
|
@@ -338,21 +343,6 @@ var WebSocketConnection = (function() {
|
|
|
338
343
|
self._handleServerRestart();
|
|
339
344
|
break;
|
|
340
345
|
|
|
341
|
-
case 'cdp':
|
|
342
|
-
if (method) {
|
|
343
|
-
routeCDPCommand({
|
|
344
|
-
id: id,
|
|
345
|
-
method: method,
|
|
346
|
-
params: params,
|
|
347
|
-
tabId: tabId,
|
|
348
|
-
sessionId: sessionId,
|
|
349
|
-
clientId: message.__clientId,
|
|
350
|
-
mode: message.__mode,
|
|
351
|
-
connectionId: self.connectionId
|
|
352
|
-
}, self.state, self);
|
|
353
|
-
}
|
|
354
|
-
break;
|
|
355
|
-
|
|
356
346
|
default:
|
|
357
347
|
if (method) {
|
|
358
348
|
routeCDPCommand({
|
|
@@ -555,7 +545,7 @@ var WebSocketConnection = (function() {
|
|
|
555
545
|
});
|
|
556
546
|
};
|
|
557
547
|
|
|
558
|
-
WebSocketConnection.prototype._createGroupForClient = function(clientId, mode) {
|
|
548
|
+
WebSocketConnection.prototype._createGroupForClient = function(clientId, mode, groupName) {
|
|
559
549
|
var self = this;
|
|
560
550
|
if (!clientId || !chrome.tabGroups) return;
|
|
561
551
|
if (mode === 'takeover') {
|
|
@@ -581,7 +571,7 @@ var WebSocketConnection = (function() {
|
|
|
581
571
|
self.state.setGroupCreationPromise(clientId, readyPromise);
|
|
582
572
|
|
|
583
573
|
var tag = (self.state.getTagForClient ? self.state.getTagForClient(clientId) : null) || (self.config ? self.config.tag : null);
|
|
584
|
-
var baseName = CDPUtils.getGroupBaseName(clientId, tag, mode);
|
|
574
|
+
var baseName = CDPUtils.getGroupBaseName(clientId, tag, mode, groupName);
|
|
585
575
|
chrome.tabs.query({ currentWindow: true }, function(tabs) {
|
|
586
576
|
if (!tabs || tabs.length === 0) {
|
|
587
577
|
Logger.warn('[WS:' + self.connectionId + '] No tabs found for group creation');
|
|
@@ -42,8 +42,14 @@ var CDPUtils = (function() {
|
|
|
42
42
|
return 0;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
function buildGroupName(clientId, connectionTag, mode) {
|
|
45
|
+
function buildGroupName(clientId, connectionTag, mode, groupName) {
|
|
46
46
|
if (!clientId) return 'CDP';
|
|
47
|
+
// 如果传了 groupName(来自 API Key 的名称),直接用它作为分组名
|
|
48
|
+
// Chrome 分组显示为 "CDP-张三的浏览器",一眼看出是谁的浏览器
|
|
49
|
+
if (groupName) {
|
|
50
|
+
var prefixG = (mode === 'takeover') ? 'TAKE-' : 'CDP-';
|
|
51
|
+
return prefixG + groupName;
|
|
52
|
+
}
|
|
47
53
|
var hash = 0;
|
|
48
54
|
for (var i = 0; i < clientId.length; i++) {
|
|
49
55
|
var chr = clientId.charCodeAt(i);
|
|
@@ -56,8 +62,8 @@ var CDPUtils = (function() {
|
|
|
56
62
|
return prefix + tag + suffix;
|
|
57
63
|
}
|
|
58
64
|
|
|
59
|
-
function getGroupBaseName(clientId, connectionTag, mode) {
|
|
60
|
-
return buildGroupName(clientId, connectionTag, mode);
|
|
65
|
+
function getGroupBaseName(clientId, connectionTag, mode, groupName) {
|
|
66
|
+
return buildGroupName(clientId, connectionTag, mode, groupName);
|
|
61
67
|
}
|
|
62
68
|
|
|
63
69
|
function findGroupByName(allGroups, baseName) {
|
package/package.json
CHANGED