cdp-tunnel 2.10.0 → 2.10.2

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.
@@ -183,7 +183,7 @@ importScripts('features/automation-badge.js');
183
183
  attached.forEach(function(tid) {
184
184
  if (state.getClientIdByTabId(tid) === clientId && !state.isPreExistingTab(tid)) {
185
185
  Logger.info('[TabGroups] Re-grouping tab', tid, 'for client:', clientId);
186
- var ctx = { _state: state, _wsManager: wsManager, clientId: clientId };
186
+ var ctx = { _state: state, _wsManager: wsManager, clientId: clientId, mode: state.mode };
187
187
  SpecialHandler.addTabToAutomationGroup(tid, clientId, null, ctx);
188
188
  }
189
189
  });
@@ -210,17 +210,17 @@ importScripts('features/automation-badge.js');
210
210
  if (clientId) {
211
211
  var cachedGroupId = state.getGroupIdForClient(clientId);
212
212
  if (cachedGroupId) {
213
- Logger.info('[Tabs] Tab', tabId, 'left group, re-adding to cached group:', cachedGroupId);
214
- chrome.tabs.group({ tabIds: tabId, groupId: cachedGroupId }, function() {
215
- if (chrome.runtime.lastError) {
216
- Logger.warn('[Tabs] Failed to re-add tab to group:', chrome.runtime.lastError.message);
217
- var ctx = { _state: state, _wsManager: wsManager, clientId: clientId };
218
- SpecialHandler.addTabToAutomationGroup(tabId, clientId, null, ctx);
213
+ Logger.info('[Tabs] Tab', tabId, 'left group, re-adding to cached group:', cachedGroupId);
214
+ chrome.tabs.group({ tabIds: tabId, groupId: cachedGroupId }, function() {
215
+ if (chrome.runtime.lastError) {
216
+ Logger.warn('[Tabs] Failed to re-add tab to group:', chrome.runtime.lastError.message);
217
+ var ctx = { _state: state, _wsManager: wsManager, clientId: clientId, mode: state.mode };
218
+ SpecialHandler.addTabToAutomationGroup(tabId, clientId, null, ctx);
219
219
  }
220
220
  });
221
221
  } else {
222
222
  Logger.info('[Tabs] Tab', tabId, 'left group, no cached groupId — delegating to addTabToAutomationGroup');
223
- var ctx = { _state: state, _wsManager: wsManager, clientId: clientId };
223
+ var ctx = { _state: state, _wsManager: wsManager, clientId: clientId, mode: state.mode };
224
224
  SpecialHandler.addTabToAutomationGroup(tabId, clientId, null, ctx);
225
225
  }
226
226
  }
@@ -319,7 +319,7 @@ importScripts('features/automation-badge.js');
319
319
  }
320
320
  });
321
321
 
322
- var ctx = { _state: state, _wsManager: wsManager, clientId: openerClientId };
322
+ var ctx = { _state: state, _wsManager: wsManager, clientId: openerClientId, mode: state.mode };
323
323
  SpecialHandler.addTabToAutomationGroup(tabId, openerClientId, null, ctx);
324
324
 
325
325
  Logger.info('[Tabs] Sending Target.attachedToTarget event');
@@ -212,6 +212,13 @@ var SpecialHandler = (function() {
212
212
  function _addTabToAutomationGroupInner(tabId, clientId, callback, context) {
213
213
  var state = context ? _getState(context) : null;
214
214
  var wsManager = context ? _getWSManager(context) : null;
215
+ var mode = context ? (context.mode || (state ? state.mode : null)) : null;
216
+
217
+ if (mode === 'takeover') {
218
+ Logger.info('[TabGroup] Skipping group for takeover tab:', tabId);
219
+ if (callback) callback(false);
220
+ return;
221
+ }
215
222
 
216
223
  Logger.info('[TabGroup] Starting addTabToAutomationGroup for tabId:', tabId, 'clientId:', clientId);
217
224
 
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "CDP Bridge",
4
- "version": "2.10.0",
4
+ "version": "2.10.2",
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": "2.10.0",
3
+ "version": "2.10.2",
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",
@@ -1165,6 +1165,16 @@ function forwardToPlugin(clientWs, data, clientId) {
1165
1165
  * 处理 CDP 客户端连接 (Playwright/Puppeteer)
1166
1166
  */
1167
1167
  function handleClientConnection(ws, clientInfo, customClientId = null, targetPluginId = null, mode = 'create') {
1168
+ if (mode === 'takeover') {
1169
+ for (const client of clientConnections) {
1170
+ if (client.mode === 'takeover' && client.readyState === WebSocket.OPEN) {
1171
+ console.log('[TAKEOVER] Rejected: takeover mode already has a connected client');
1172
+ ws.close(1008, 'Takeover mode already in use. Only one client allowed.');
1173
+ return;
1174
+ }
1175
+ }
1176
+ }
1177
+
1168
1178
  clientConnections.add(ws);
1169
1179
  const id = customClientId || generateId('client');
1170
1180
  ws.mode = mode;