cdp-tunnel 3.1.0 → 3.1.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.
@@ -12,8 +12,11 @@ var SpecialHandler = (function() {
12
12
  function _getConnectionTag(ctx) {
13
13
  var wm = ctx._wsManager;
14
14
  var state = ctx._state;
15
- // 优先从 state.connectionTag 读(端口池设置的端口号)
16
- if (state && state.connectionTag) return state.connectionTag;
15
+ // 端口池:按 clientId 查 connectionTag(端口号)
16
+ if (state && ctx.clientId && state.getTagForClient) {
17
+ var tag = state.getTagForClient(ctx.clientId);
18
+ if (tag) return tag;
19
+ }
17
20
  return (wm && wm.config && wm.config.tag) || null;
18
21
  }
19
22
 
@@ -2,6 +2,7 @@ function ConnectionState(connectionId, mode) {
2
2
  this.connectionId = connectionId;
3
3
  this.mode = mode || 'create';
4
4
  this.connectionTag = null;
5
+ this.clientIdToTag = new Map();
5
6
  this.ws = null;
6
7
  this.reconnectTimer = null;
7
8
  this._hasConnectedClient = false;
@@ -299,6 +300,14 @@ ConnectionState.prototype.clearPreExistingTabsForClient = function(clientId) {
299
300
  });
300
301
  };
301
302
 
303
+ ConnectionState.prototype.setTagForClient = function(clientId, tag) {
304
+ if (clientId && tag) this.clientIdToTag.set(clientId, tag);
305
+ };
306
+
307
+ ConnectionState.prototype.getTagForClient = function(clientId) {
308
+ return this.clientIdToTag.get(clientId) || null;
309
+ };
310
+
302
311
  ConnectionState.prototype.addCDPClient = function(clientId, info) {
303
312
  var exists = false;
304
313
  for (var i = 0; i < this.cdpClients.length; i++) {
@@ -242,7 +242,7 @@ var WebSocketConnection = (function() {
242
242
  self.state.setHasConnectedClient(true);
243
243
  self.state.addCDPClient(message.clientId, message.clientId);
244
244
  if (message.__connectionTag) {
245
- self.state.connectionTag = message.__connectionTag;
245
+ self.state.setTagForClient(message.clientId, message.__connectionTag);
246
246
  }
247
247
  self._createGroupForClient(message.clientId, message.__mode);
248
248
  self._broadcastStateUpdate();
@@ -580,7 +580,7 @@ var WebSocketConnection = (function() {
580
580
  var readyPromise = new Promise(function(resolve) { resolveGroupReady = resolve; });
581
581
  self.state.setGroupCreationPromise(clientId, readyPromise);
582
582
 
583
- var tag = self.state.connectionTag || (self.config ? self.config.tag : null);
583
+ var tag = (self.state.getTagForClient ? self.state.getTagForClient(clientId) : null) || (self.config ? self.config.tag : null);
584
584
  var baseName = CDPUtils.getGroupBaseName(clientId, tag, mode);
585
585
  chrome.tabs.query({ currentWindow: true }, function(tabs) {
586
586
  if (!tabs || tabs.length === 0) {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "CDP Bridge",
4
- "version": "3.1.0",
4
+ "version": "3.1.1",
5
5
  "description": "Chrome DevTools Protocol Bridge for Playwright/Puppeteer automation",
6
6
  "permissions": [
7
7
  "debugger",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cdp-tunnel",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "description": "Bridge Chrome's debugger API to WebSocket — control your existing browser with Playwright/Puppeteer via CDP",
5
5
  "main": "server/proxy-server.js",
6
6
  "bin": "./cli/index.js",