cdp-tunnel 3.3.4 → 3.3.6

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.
@@ -107,23 +107,37 @@ var DebuggerManager = (function() {
107
107
  }
108
108
 
109
109
  function doAttach(tabId, state) {
110
- return chrome.debugger.attach({ tabId: tabId }, Config.DEBUGGER_VERSION)
111
- .then(function() {
112
- Logger.info('[Debugger] Attached to tab', tabId);
113
- if (state) {
114
- state.addAttachedTab(tabId);
115
- state.setCurrentTabId(tabId);
116
- state.persist(tabId, true);
117
- }
118
- return injectInternalUrlBlocker(tabId);
119
- })
120
- .then(function() {
121
- return true;
122
- })
123
- .catch(function(error) {
124
- Logger.error('[Debugger] Failed to attach to tab', tabId, ':', error.message);
125
- return false;
126
- });
110
+ var retryCount = 0;
111
+ var maxRetries = 3;
112
+
113
+ function attemptAttach() {
114
+ return chrome.debugger.attach({ tabId: tabId }, Config.DEBUGGER_VERSION)
115
+ .then(function() {
116
+ Logger.info('[Debugger] Attached to tab', tabId);
117
+ if (state) {
118
+ state.addAttachedTab(tabId);
119
+ state.setCurrentTabId(tabId);
120
+ state.persist(tabId, true);
121
+ }
122
+ return injectInternalUrlBlocker(tabId);
123
+ })
124
+ .then(function() {
125
+ return true;
126
+ })
127
+ .catch(function(error) {
128
+ retryCount++;
129
+ if (retryCount <= maxRetries) {
130
+ Logger.warn('[Debugger] Attach retry', retryCount, 'for tab', tabId, ':', error.message);
131
+ return new Promise(function(resolve) {
132
+ setTimeout(function() { resolve(attemptAttach()); }, 100 * retryCount);
133
+ });
134
+ }
135
+ Logger.error('[Debugger] Failed to attach to tab', tabId, 'after', maxRetries, 'retries:', error.message);
136
+ return false;
137
+ });
138
+ }
139
+
140
+ return attemptAttach();
127
141
  }
128
142
 
129
143
  function injectInternalUrlBlocker(tabId) {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "CDP Bridge",
4
- "version": "3.3.4",
4
+ "version": "3.3.6",
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.3.4",
3
+ "version": "3.3.6",
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",
@@ -191,6 +191,22 @@ class PortPoolManager {
191
191
  return;
192
192
  }
193
193
 
194
+ // SW 冷启动 warmup:第一个 client 连接时创建一个临时 tab 再关闭
195
+ // 确保 chrome.debugger API 完全初始化,避免第一批并发请求失败
196
+ if (!session.warmedUp) {
197
+ session.warmedUp = true;
198
+ const warmupId = `pool${session.portIndex}_internal_warmup`;
199
+ pluginWs.send(JSON.stringify({
200
+ id: warmupId,
201
+ method: 'Target.createTarget',
202
+ params: { url: 'about:blank' },
203
+ __portIndex: session.portIndex,
204
+ __clientId: `pool_${session.port}`
205
+ }));
206
+ // 响应回来后在 handlePluginMessage 里丢弃(_internal 前缀)
207
+ // tab 会在 Browser.close 或断开时清理
208
+ }
209
+
194
210
  // 通知扩展有 client 连接(带端口号作为分组标识)
195
211
  // clientId 固定为 pool_{port},让扩展为每个端口建一个独立分组
196
212
  const poolClientId = `pool_${session.port}`;