cdp-tunnel 2.7.4 → 2.7.5

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "CDP Bridge",
4
- "version": "2.7.4",
4
+ "version": "2.7.5",
5
5
  "description": "Chrome DevTools Protocol Bridge for Playwright/Puppeteer automation",
6
6
  "permissions": [
7
7
  "debugger",
@@ -1,5 +1,5 @@
1
1
  var Config = {
2
- WS_URL: 'ws://localhost:9221/plugin',
2
+ WS_URL: 'ws://localhost:58288/plugin',
3
3
  RECONNECT_DELAY: 3000,
4
4
  DEBUGGER_VERSION: '1.3',
5
5
  HEARTBEAT_INTERVAL: 25000,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cdp-tunnel",
3
- "version": "2.7.4",
3
+ "version": "2.7.5",
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",
@@ -797,25 +797,7 @@ function handlePluginConnection(ws, clientInfo, request) {
797
797
  pendingMap.set(targetId, { parsed: JSON.parse(JSON.stringify(parsed)), cdpData });
798
798
  console.log(`[TARGET EVENT PENDING] ${parsed.method} targetId=${targetId?.substring(0,8) || 'none'} (cached, waiting for createTarget response)`);
799
799
  } else {
800
- // Broadcast to discovering clients
801
- let routedToDiscoverer = false;
802
- if (ns.discoveringClientIds.size > 0) {
803
- for (const [discClientId, timestamp] of ns.discoveringClientIds) {
804
- if (Date.now() - timestamp < 30000) {
805
- const discWs = clientById.get(discClientId);
806
- if (discWs && discWs.readyState === WebSocket.OPEN) {
807
- discWs.send(cdpData);
808
- routedToDiscoverer = true;
809
- }
810
- } else {
811
- ns.discoveringClientIds.delete(discClientId);
812
- }
813
- }
814
- }
815
- if (!routedToDiscoverer) {
816
- pendingMap.set(targetId, { parsed: JSON.parse(JSON.stringify(parsed)), cdpData });
817
- console.log(`[TARGET EVENT PENDING] ${parsed.method} targetId=${targetId?.substring(0,8) || 'none'} (cached, no discoverer)`);
818
- }
800
+ console.log(`[TARGET EVENT DROPPED] ${parsed.method} targetId=${targetId?.substring(0,8) || 'none'} (no owner, dropped for isolation)`);
819
801
  }
820
802
  } else {
821
803
  console.log(`[TARGET EVENT DROPPED] ${parsed.method} targetId=${targetId?.substring(0,8) || 'none'} (no owner, dropped for isolation)`);
@@ -948,15 +930,33 @@ function handlePluginConnection(ws, clientInfo, request) {
948
930
  invalidateTargetsCache(ws);
949
931
  }
950
932
 
951
- const originalId = mapping.originalId;
952
- parsed.id = originalId;
953
- if (mapping.sessionId && !parsed.sessionId) {
954
- parsed.sessionId = mapping.sessionId;
933
+ if (mapping.isAutoDefaultPage) {
934
+ console.log(`[AUTO DEFAULT PAGE] createTarget response received for client=${mapping.clientId}, targetId=${parsed.result?.targetId?.substring(0,8) || 'none'} — skipping response send to client`);
935
+
936
+ if (mapping.pendingSetAutoAttach) {
937
+ const pending = mapping.pendingSetAutoAttach;
938
+ const pendingParsed = pending.parsed;
939
+ const pendingClientId = pending.clientId;
940
+
941
+ console.log(`[AUTO DEFAULT PAGE] Now forwarding pending setAutoAttach for client=${pendingClientId}`);
942
+
943
+ if (ws.readyState === WebSocket.OPEN) {
944
+ const forwardMsg = { ...pendingParsed, __clientId: pendingClientId };
945
+ ws.send(JSON.stringify(forwardMsg));
946
+ console.log(`[SEND TO PLUGIN] Forwarding setAutoAttach for client=${pendingClientId}`);
947
+ }
948
+ }
949
+ } else {
950
+ const originalId = mapping.originalId;
951
+ parsed.id = originalId;
952
+ if (mapping.sessionId && !parsed.sessionId) {
953
+ parsed.sessionId = mapping.sessionId;
954
+ }
955
+ const responseStr = JSON.stringify(parsed);
956
+ console.log(`[SEND TO CLIENT] ${responseStr.substring(0, 300)}`);
957
+ clientWs.send(responseStr);
958
+ console.log(`[ROUTE] Response global=${globalId} -> original=${originalId} -> client=${mapping.clientId} sessionId=${parsed.sessionId?.substring(0,8) || 'none'}`);
955
959
  }
956
- const responseStr = JSON.stringify(parsed);
957
- console.log(`[SEND TO CLIENT] ${responseStr.substring(0, 300)}`);
958
- clientWs.send(responseStr);
959
- console.log(`[ROUTE] Response global=${globalId} -> original=${originalId} -> client=${mapping.clientId} sessionId=${parsed.sessionId?.substring(0,8) || 'none'}`);
960
960
  }
961
961
  globalRequestIdMap.delete(globalId);
962
962
  } else {
@@ -1052,6 +1052,52 @@ function handlePluginConnection(ws, clientInfo, request) {
1052
1052
  }));
1053
1053
  }
1054
1054
 
1055
+ function autoCreateDefaultPageAndForward(clientWs, setAutoAttachParsed, originalData, clientId, originalRequestId) {
1056
+ const pluginWs = clientWs.pairedPlugin;
1057
+ if (!pluginWs || pluginWs.readyState !== WebSocket.OPEN) {
1058
+ forwardToPlugin(clientWs, originalData, clientId);
1059
+ return;
1060
+ }
1061
+
1062
+ globalRequestIdCounter++;
1063
+ const createGlobalId = globalRequestIdCounter;
1064
+
1065
+ globalRequestIdMap.set(createGlobalId, {
1066
+ clientId: clientId,
1067
+ originalId: -1,
1068
+ sessionId: null,
1069
+ method: 'Target.createTarget',
1070
+ isCreateTarget: true,
1071
+ isAutoDefaultPage: true,
1072
+ pendingSetAutoAttach: {
1073
+ parsed: setAutoAttachParsed,
1074
+ data: originalData,
1075
+ clientId: clientId,
1076
+ originalRequestId: originalRequestId
1077
+ }
1078
+ });
1079
+
1080
+ const request = {
1081
+ id: createGlobalId,
1082
+ method: 'Target.createTarget',
1083
+ params: { url: 'about:blank' },
1084
+ __clientId: clientId
1085
+ };
1086
+
1087
+ console.log(`[AUTO DEFAULT PAGE] Sending Target.createTarget for client=${clientId} globalId=${createGlobalId}, will forward setAutoAttach after`);
1088
+ pluginWs.send(JSON.stringify(request));
1089
+ }
1090
+
1091
+ function forwardToPlugin(clientWs, data, clientId) {
1092
+ const pluginWs = clientWs.pairedPlugin;
1093
+ if (pluginWs && pluginWs.readyState === WebSocket.OPEN) {
1094
+ console.log(`[SEND TO PLUGIN] method=Target.setAutoAttach clientId=${clientId}`);
1095
+ pluginWs.send(data);
1096
+ } else {
1097
+ broadcastToPlugins(data, clientWs);
1098
+ }
1099
+ }
1100
+
1055
1101
  /**
1056
1102
  * 处理 CDP 客户端连接 (Playwright/Puppeteer)
1057
1103
  */
@@ -1254,6 +1300,12 @@ function handleClientConnection(ws, clientInfo, customClientId = null, targetPlu
1254
1300
  }
1255
1301
  }
1256
1302
 
1303
+ if (parsed && parsed.method === 'Target.setAutoAttach' && parsed.params?.autoAttach && !ws._autoDefaultPageSent) {
1304
+ ws._autoDefaultPageSent = true;
1305
+ autoCreateDefaultPageAndForward(ws, parsed, modifiedData, id, originalId);
1306
+ return;
1307
+ }
1308
+
1257
1309
  if (parsed && parsed.method === 'Browser.close') {
1258
1310
  if (shouldLog('info')) {
1259
1311
  console.log(`\n[BROWSER CLOSE] Client ${id} requested Browser.close, forwarding to plugin`);