cdp-tunnel 3.2.5 → 3.2.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.
|
@@ -65,8 +65,30 @@ var SpecialHandler = (function() {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
var isAlreadyAttached = state.isTabAttached(tabId);
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
var isAttaching = state.attachingTabs && state.attachingTabs.has(tabId);
|
|
69
|
+
|
|
70
|
+
if (isAlreadyAttached || isAttaching) {
|
|
71
|
+
// 已 attach 或正在 attach——等待正在进行的 attach 完成后返回新 session
|
|
72
|
+
if (isAttaching && state.attachingTabs) {
|
|
73
|
+
// 等待 attach 完成
|
|
74
|
+
var waitAttach = function(cb, retries) {
|
|
75
|
+
if (state.isTabAttached(tabId)) {
|
|
76
|
+
var sid = CDPUtils.generateSessionId();
|
|
77
|
+
state.mapSession(sid, tabId, targetId);
|
|
78
|
+
muteTabIfNeeded(tabId);
|
|
79
|
+
cb({ sessionId: sid });
|
|
80
|
+
} else if (retries > 0) {
|
|
81
|
+
setTimeout(function() { waitAttach(cb, retries - 1); }, 100);
|
|
82
|
+
} else {
|
|
83
|
+
// 超时——直接生成 session(attach 可能成功了但标记慢了)
|
|
84
|
+
var sid2 = CDPUtils.generateSessionId();
|
|
85
|
+
state.mapSession(sid2, tabId, targetId);
|
|
86
|
+
muteTabIfNeeded(tabId);
|
|
87
|
+
cb({ sessionId: sid2 });
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
return new Promise(function(resolve) { waitAttach(resolve, 30); });
|
|
91
|
+
}
|
|
70
92
|
var newSessionId = CDPUtils.generateSessionId();
|
|
71
93
|
state.mapSession(newSessionId, tabId, targetId);
|
|
72
94
|
muteTabIfNeeded(tabId);
|
|
@@ -74,7 +96,14 @@ var SpecialHandler = (function() {
|
|
|
74
96
|
return { sessionId: newSessionId };
|
|
75
97
|
}
|
|
76
98
|
|
|
99
|
+
// 标记为正在 attach(防止并发 attach 同一个 tab)
|
|
100
|
+
if (!state.attachingTabs) state.attachingTabs = new Set();
|
|
101
|
+
state.attachingTabs.add(tabId);
|
|
102
|
+
|
|
77
103
|
return DebuggerManager.attach(tabId, state).then(function(attached) {
|
|
104
|
+
// 清除"正在 attach"标记
|
|
105
|
+
if (state.attachingTabs) state.attachingTabs.delete(tabId);
|
|
106
|
+
|
|
78
107
|
if (!attached) {
|
|
79
108
|
throw new Error('Failed to attach');
|
|
80
109
|
}
|
package/package.json
CHANGED