cdp-tunnel 3.0.9 → 3.1.0

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.
@@ -11,6 +11,9 @@ var SpecialHandler = (function() {
11
11
 
12
12
  function _getConnectionTag(ctx) {
13
13
  var wm = ctx._wsManager;
14
+ var state = ctx._state;
15
+ // 优先从 state.connectionTag 读(端口池设置的端口号)
16
+ if (state && state.connectionTag) return state.connectionTag;
14
17
  return (wm && wm.config && wm.config.tag) || null;
15
18
  }
16
19
 
@@ -1,6 +1,7 @@
1
1
  function ConnectionState(connectionId, mode) {
2
2
  this.connectionId = connectionId;
3
3
  this.mode = mode || 'create';
4
+ this.connectionTag = null;
4
5
  this.ws = null;
5
6
  this.reconnectTimer = null;
6
7
  this._hasConnectedClient = false;
@@ -241,6 +241,9 @@ var WebSocketConnection = (function() {
241
241
  Logger.info('[WS:' + self.connectionId + '] Client connected, resuming event forwarding');
242
242
  self.state.setHasConnectedClient(true);
243
243
  self.state.addCDPClient(message.clientId, message.clientId);
244
+ if (message.__connectionTag) {
245
+ self.state.connectionTag = message.__connectionTag;
246
+ }
244
247
  self._createGroupForClient(message.clientId, message.__mode);
245
248
  self._broadcastStateUpdate();
246
249
  break;
@@ -577,7 +580,8 @@ var WebSocketConnection = (function() {
577
580
  var readyPromise = new Promise(function(resolve) { resolveGroupReady = resolve; });
578
581
  self.state.setGroupCreationPromise(clientId, readyPromise);
579
582
 
580
- var baseName = CDPUtils.getGroupBaseName(clientId, self.config ? self.config.tag : null, mode);
583
+ var tag = self.state.connectionTag || (self.config ? self.config.tag : null);
584
+ var baseName = CDPUtils.getGroupBaseName(clientId, tag, mode);
581
585
  chrome.tabs.query({ currentWindow: true }, function(tabs) {
582
586
  if (!tabs || tabs.length === 0) {
583
587
  Logger.warn('[WS:' + self.connectionId + '] No tabs found for group creation');
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "CDP Bridge",
4
- "version": "3.0.9",
4
+ "version": "3.1.0",
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.0.9",
3
+ "version": "3.1.0",
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",
@@ -165,18 +165,20 @@ class PortPoolManager {
165
165
  _handleClientConnect(ws, req, session) {
166
166
  session.clients.add(ws);
167
167
 
168
- // 找到 plugin 连接(从主 proxy 获取)
169
168
  const pluginWs = this.mainProxy.getPluginConnection();
170
169
  if (!pluginWs) {
171
170
  ws.close(1011, 'No extension connected');
172
171
  return;
173
172
  }
174
173
 
175
- // 通知扩展有 client 连接(扩展需要 hasConnectedClient=true 才转发 debugger 事件)
176
- const poolClientId = `pool_${session.portIndex}_${Date.now()}`;
174
+ // 通知扩展有 client 连接(带端口号作为分组标识)
175
+ // clientId 固定为 pool_{port},让扩展为每个端口建一个独立分组
176
+ const poolClientId = `pool_${session.port}`;
177
177
  pluginWs.send(JSON.stringify({
178
178
  type: 'client-connected',
179
- clientId: poolClientId
179
+ clientId: poolClientId,
180
+ __mode: 'create',
181
+ __connectionTag: String(session.port)
180
182
  }));
181
183
 
182
184
  // 合成输入命令需要 ensureVisible(和 forward.js 的逻辑一致)
@@ -205,7 +207,7 @@ class PortPoolManager {
205
207
  clientWs: ws
206
208
  });
207
209
 
208
- const forwarded = { ...msg, id: newId, __portIndex: session.portIndex };
210
+ const forwarded = { ...msg, id: newId, __portIndex: session.portIndex, __clientId: `pool_${session.port}` };
209
211
  pluginWs.send(JSON.stringify(forwarded));
210
212
  } else {
211
213
  // 无 id 的消息(事件),直接转发
@@ -2139,6 +2139,7 @@ portPool = new PortPoolManager({
2139
2139
  for (const ws of pluginConnections) return ws;
2140
2140
  return null;
2141
2141
  },
2142
+ handleHttpRequest: (req, res) => handleHttpRequest(req, res),
2142
2143
  handlePoolUpgrade: (req, socket, head, portIndex, port) => {
2143
2144
  req._poolPortIndex = portIndex;
2144
2145
  wss.handleUpgrade(req, socket, head, (ws) => {