cdp-tunnel 2.6.2 → 2.7.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.
@@ -27,12 +27,13 @@ importScripts('features/automation-badge.js');
27
27
  keepAliveInterval = setInterval(function() {
28
28
  var ws = State.getWs();
29
29
  if (ws && ws.readyState === WebSocket.OPEN) {
30
- Logger.info('[KeepAlive] Sending heartbeat');
31
30
  WebSocketManager.send({ type: 'keepalive', timestamp: Date.now() });
32
31
  }
33
32
  }, 20000);
34
-
35
- Logger.info('[KeepAlive] Started keepalive interval');
33
+
34
+ chrome.alarms.clear('sw-keepalive', function() {
35
+ chrome.alarms.create('sw-keepalive', { periodInMinutes: 0.4 });
36
+ });
36
37
  }
37
38
 
38
39
  function stopKeepAlive() {
@@ -362,5 +363,16 @@ importScripts('features/automation-badge.js');
362
363
  return true;
363
364
  });
364
365
 
366
+ chrome.alarms.onAlarm.addListener(function(alarm) {
367
+ if (alarm.name === 'sw-keepalive') {
368
+ var ws = State.getWs();
369
+ if (ws && ws.readyState === WebSocket.OPEN) {
370
+ WebSocketManager.send({ type: 'keepalive', timestamp: Date.now() });
371
+ } else {
372
+ WebSocketManager.connect();
373
+ }
374
+ }
375
+ });
376
+
365
377
  init();
366
378
  })();
@@ -37,6 +37,7 @@ var LocalHandler = (function() {
37
37
  if (params && params.discover) {
38
38
  return getTargetInfos().then(function(targets) {
39
39
  targets.forEach(function(targetInfo) {
40
+ State.addEmittedTarget(targetInfo.targetId);
40
41
  EventBuilder.send('Target.targetCreated', { targetInfo: targetInfo });
41
42
  });
42
43
  return {};
@@ -435,8 +435,6 @@ function checkTabVisibility(tabId) {
435
435
  var isPreExisting = !isCDPCreated;
436
436
 
437
437
  Logger.info('[CDP] Emitting target:', targetId, 'tabId:', tabId, 'preExisting:', isPreExisting);
438
-
439
- EventBuilder.send('Target.targetCreated', { targetInfo: targetInfo });
440
438
 
441
439
  var attachLogic = function(attached) {
442
440
  var sessionId = CDPUtils.generateSessionId();
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "CDP Bridge",
4
- "version": "2.6.2",
4
+ "version": "2.7.1",
5
5
  "description": "Chrome DevTools Protocol Bridge for Playwright/Puppeteer automation",
6
6
  "permissions": [
7
7
  "debugger",
@@ -10,7 +10,8 @@
10
10
  "scripting",
11
11
  "storage",
12
12
  "downloads",
13
- "tabGroups"
13
+ "tabGroups",
14
+ "alarms"
14
15
  ],
15
16
  "host_permissions": [
16
17
  "<all_urls>"
@@ -1,5 +1,5 @@
1
1
  var Config = {
2
- WS_URL: 'ws://localhost:9221/plugin',
2
+ WS_URL: 'ws://localhost:19236/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.6.2",
3
+ "version": "2.7.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",
@@ -9,7 +9,8 @@ const CONFIG = {
9
9
  CLIENT_IDLE_TIMEOUT: 300000,
10
10
  LOG_LEVEL: process.env.LOG_LEVEL || 'info',
11
11
  AUTO_RESTART: process.env.AUTO_RESTART === 'true',
12
- CHROME_RESTART_COOLDOWN: 30000
12
+ CHROME_RESTART_COOLDOWN: 30000,
13
+ PLUGIN_MAX_MISSED_PINGS: 3
13
14
  };
14
15
 
15
16
  const LOG_LEVELS = {
@@ -755,12 +755,10 @@ function handlePluginConnection(ws, clientInfo, request) {
755
755
  const ns = getNamespace(ws);
756
756
  const cdpMsg = {
757
757
  method: parsed.method,
758
- params: parsed.params,
759
- type: 'event'
758
+ params: parsed.params
760
759
  };
761
760
  if (parsed.sessionId) {
762
761
  cdpMsg.params.sessionId = parsed.sessionId;
763
- cdpMsg.sessionId = parsed.sessionId;
764
762
  }
765
763
 
766
764
  if (parsed.method === 'Target.targetCreated') {
@@ -797,7 +795,6 @@ function handlePluginConnection(ws, clientInfo, request) {
797
795
  const discWs = clientById.get(discClientId);
798
796
  if (discWs && discWs.readyState === WebSocket.OPEN) {
799
797
  discWs.send(cdpData);
800
- console.log(`[TARGET EVENT DISCOVERED] ${parsed.method} targetId=${targetId?.substring(0,8)} -> discovering client=${discClientId}`);
801
798
  routedToDiscoverer = true;
802
799
  }
803
800
  } else {
@@ -1241,7 +1238,7 @@ function handleClientConnection(ws, clientInfo, customClientId = null, targetPlu
1241
1238
  }
1242
1239
  }
1243
1240
 
1244
- if (parsed && (parsed.method === 'Target.setDiscoverTargets' || parsed.method === 'Target.setAutoAttach')) {
1241
+ if (parsed && (parsed.method === 'Target.setDiscoverTargets' || parsed.method === 'Target.setAutoAttach')) {
1245
1242
  const ns = ws.pairedPlugin ? getNamespace(ws.pairedPlugin) : null;
1246
1243
  if (ns) {
1247
1244
  ns.discoveringClientIds.set(id, Date.now());
@@ -1637,12 +1634,20 @@ const heartbeatInterval = setInterval(() => {
1637
1634
 
1638
1635
  pluginConnections.forEach((ws) => {
1639
1636
  if (!ws.isAlive) {
1640
- if (shouldLog('warn')) {
1641
- console.log(`[${now}] Plugin ${ws.id} not responding, terminating...`);
1637
+ ws.missedPings = (ws.missedPings || 0) + 1;
1638
+ if (ws.missedPings >= CONFIG.PLUGIN_MAX_MISSED_PINGS) {
1639
+ if (shouldLog('warn')) {
1640
+ console.log(`[${now}] Plugin ${ws.id} missed ${ws.missedPings} pings, terminating...`);
1641
+ }
1642
+ logConnectionEvent('HEARTBEAT_TIMEOUT', { type: 'plugin', id: ws.id, missedPings: ws.missedPings });
1643
+ cleanupPlugin(ws, ws.id, 'heartbeat_timeout');
1644
+ return ws.terminate();
1642
1645
  }
1643
- logConnectionEvent('HEARTBEAT_TIMEOUT', { type: 'plugin', id: ws.id });
1644
- cleanupPlugin(ws, ws.id, 'heartbeat_timeout');
1645
- return ws.terminate();
1646
+ if (shouldLog('info')) {
1647
+ console.log(`[${now}] Plugin ${ws.id} missed ping ${ws.missedPings}/${CONFIG.PLUGIN_MAX_MISSED_PINGS}`);
1648
+ }
1649
+ } else {
1650
+ ws.missedPings = 0;
1646
1651
  }
1647
1652
  ws.isAlive = false;
1648
1653
  ws.ping();