cdp-tunnel 1.4.0 → 1.5.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.
@@ -21,7 +21,7 @@ var SpecialHandler = (function() {
21
21
  });
22
22
 
23
23
  if (params && params.autoAttach) {
24
- return emitAutoAttachForExistingTargets().then(function() {
24
+ return emitAutoAttachForExistingTargets(context).then(function() {
25
25
  return {};
26
26
  });
27
27
  }
@@ -354,9 +354,11 @@ function checkTabVisibility(tabId) {
354
354
  });
355
355
  }
356
356
 
357
- function emitAutoAttachForExistingTargets() {
357
+ function emitAutoAttachForExistingTargets(context) {
358
+ var clientId = context ? context.clientId : null;
359
+ var config = State.getAutoAttachConfig();
360
+
358
361
  return chrome.debugger.getTargets().then(function(targets) {
359
- var config = State.getAutoAttachConfig();
360
362
  var promises = [];
361
363
 
362
364
  Logger.info('[CDP] emitAutoAttachForExistingTargets: checking', targets.length, 'targets');
@@ -389,13 +391,14 @@ function checkTabVisibility(tabId) {
389
391
  EventBuilder.send('Target.targetCreated', { targetInfo: targetInfo });
390
392
 
391
393
  if (target.attached && isAttachedByUs) {
392
- var promise = Promise.resolve();
393
-
394
- promises.push(promise.then(function() {
394
+ promises.push(Promise.resolve().then(function() {
395
395
  var sessionId = CDPUtils.generateSessionId();
396
396
  State.mapSession(sessionId, target.tabId, targetId);
397
397
 
398
- addTabToAutomationGroup(target.tabId);
398
+ if (clientId) {
399
+ State.setTabIdToClientId(target.tabId, clientId);
400
+ }
401
+ addTabToAutomationGroup(target.tabId, clientId);
399
402
 
400
403
  if (config.waitForDebuggerOnStart) {
401
404
  State.addPendingDebuggerTab(target.tabId);
@@ -404,9 +407,32 @@ function checkTabVisibility(tabId) {
404
407
  EventBuilder.send('Target.attachedToTarget', {
405
408
  sessionId: sessionId,
406
409
  targetInfo: Object.assign({}, targetInfo, { attached: true }),
407
- waitingForDebugger: config.waitForDebuggerOnStart
410
+ waitingForDebugger: config.waitForDebuggerOnStart || false
408
411
  });
409
412
  }));
413
+ } else if (!target.attached) {
414
+ promises.push(
415
+ DebuggerManager.attach(target.tabId).then(function(attached) {
416
+ if (!attached) return;
417
+ var sessionId = CDPUtils.generateSessionId();
418
+ State.mapSession(sessionId, target.tabId, targetId);
419
+
420
+ if (clientId) {
421
+ State.setTabIdToClientId(target.tabId, clientId);
422
+ }
423
+ addTabToAutomationGroup(target.tabId, clientId);
424
+
425
+ if (config.waitForDebuggerOnStart) {
426
+ State.addPendingDebuggerTab(target.tabId);
427
+ }
428
+
429
+ EventBuilder.send('Target.attachedToTarget', {
430
+ sessionId: sessionId,
431
+ targetInfo: Object.assign({}, targetInfo, { attached: true }),
432
+ waitingForDebugger: config.waitForDebuggerOnStart || false
433
+ });
434
+ })
435
+ );
410
436
  }
411
437
  });
412
438
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cdp-tunnel",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "Chrome Extension CDP Proxy - 通过 Chrome 扩展将 chrome.debugger API 暴露为 WebSocket 端点",
5
5
  "main": "server/proxy-server.js",
6
6
  "bin": "./cli/index.js",