cdp-tunnel 1.2.0 → 1.3.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.
- package/extension-new/background.js +12 -0
- package/extension-new/cdp/handler/local.js +35 -1
- package/extension-new/cdp/handler/special.js +15 -0
- package/extension-new/cdp/index.js +2 -0
- package/extension-new/config-page-preview.html +39 -0
- package/extension-new/config-page.js +8 -0
- package/extension-new/utils/config.js +9 -0
- package/package.json +1 -1
|
@@ -216,6 +216,18 @@ String.prototype.hashCode = function() {
|
|
|
216
216
|
var sessionId = CDPUtils.generateSessionId();
|
|
217
217
|
State.mapSession(sessionId, tabId, targetId);
|
|
218
218
|
|
|
219
|
+
Config.getAutoMute(function(enabled) {
|
|
220
|
+
if (enabled) {
|
|
221
|
+
chrome.tabs.update(tabId, { muted: true }, function() {
|
|
222
|
+
if (chrome.runtime.lastError) {
|
|
223
|
+
Logger.error('[TabMute] Failed to mute tab ' + tabId + ':', chrome.runtime.lastError.message);
|
|
224
|
+
} else {
|
|
225
|
+
Logger.info('[TabMute] Tab muted:', tabId);
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
|
|
219
231
|
// 将标签页添加到CDP组(添加延迟等待)
|
|
220
232
|
setTimeout(function() {
|
|
221
233
|
// 获取openerTabId对应的clientId
|
|
@@ -135,6 +135,39 @@ var LocalHandler = (function() {
|
|
|
135
135
|
return {};
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
+
function tabGetMuteStatus(params) {
|
|
139
|
+
var cdpOnly = params && params.cdpOnly;
|
|
140
|
+
var attachedTabIds = State.getAttachedTabIds();
|
|
141
|
+
|
|
142
|
+
return new Promise(function(resolve) {
|
|
143
|
+
chrome.tabs.query({}, function(tabs) {
|
|
144
|
+
if (chrome.runtime.lastError) {
|
|
145
|
+
resolve({ tabs: [] });
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
var result = tabs;
|
|
150
|
+
if (cdpOnly) {
|
|
151
|
+
result = tabs.filter(function(t) {
|
|
152
|
+
return attachedTabIds.indexOf(t.id) !== -1;
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
resolve({
|
|
157
|
+
tabs: result.map(function(tab) {
|
|
158
|
+
return {
|
|
159
|
+
id: tab.id,
|
|
160
|
+
url: tab.url || '',
|
|
161
|
+
title: tab.title || '',
|
|
162
|
+
muted: tab.mutedInfo ? tab.mutedInfo.muted : false,
|
|
163
|
+
mutedReason: tab.mutedInfo ? (tab.mutedInfo.reason || '') : ''
|
|
164
|
+
};
|
|
165
|
+
})
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
138
171
|
function getTargetInfos() {
|
|
139
172
|
return chrome.debugger.getTargets().then(function(targets) {
|
|
140
173
|
// 为每个有 tabId 的 target 查询 openerTabId
|
|
@@ -274,6 +307,7 @@ var LocalHandler = (function() {
|
|
|
274
307
|
emptyObject: emptyObject,
|
|
275
308
|
getTargetInfos: getTargetInfos,
|
|
276
309
|
getTargetInfoById: getTargetInfoById,
|
|
277
|
-
mapToTargetInfo: mapToTargetInfo
|
|
310
|
+
mapToTargetInfo: mapToTargetInfo,
|
|
311
|
+
tabGetMuteStatus: tabGetMuteStatus
|
|
278
312
|
};
|
|
279
313
|
})();
|
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
var SpecialHandler = (function() {
|
|
2
|
+
function muteTabIfNeeded(tabId) {
|
|
3
|
+
Config.getAutoMute(function(enabled) {
|
|
4
|
+
if (!enabled) return;
|
|
5
|
+
chrome.tabs.update(tabId, { muted: true }, function() {
|
|
6
|
+
if (chrome.runtime.lastError) {
|
|
7
|
+
Logger.error('[TabMute] Failed to mute tab ' + tabId + ':', chrome.runtime.lastError.message);
|
|
8
|
+
} else {
|
|
9
|
+
Logger.info('[TabMute] Tab muted:', tabId);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
2
15
|
function targetSetAutoAttach(context) {
|
|
3
16
|
var params = context.params;
|
|
4
17
|
State.setAutoAttachConfig({
|
|
@@ -116,6 +129,8 @@ var SpecialHandler = (function() {
|
|
|
116
129
|
function addTabToAutomationGroup(tabId, clientId) {
|
|
117
130
|
Logger.info('[TabGroup] Starting addTabToAutomationGroup for tabId:', tabId, 'clientId:', clientId);
|
|
118
131
|
|
|
132
|
+
muteTabIfNeeded(tabId);
|
|
133
|
+
|
|
119
134
|
var groupName;
|
|
120
135
|
var groupClientId = clientId;
|
|
121
136
|
|
|
@@ -22,6 +22,8 @@ var CDP_HANDLERS = {
|
|
|
22
22
|
'Target.getBrowserContexts': { type: 'LOCAL', handler: LocalHandler.targetGetBrowserContexts },
|
|
23
23
|
'Target.attachToBrowserTarget': { type: 'LOCAL', handler: LocalHandler.targetAttachToBrowserTarget },
|
|
24
24
|
|
|
25
|
+
'Tab.getMuteStatus': { type: 'LOCAL', handler: LocalHandler.tabGetMuteStatus },
|
|
26
|
+
|
|
25
27
|
'SystemInfo.getInfo': { type: 'LOCAL', handler: LocalHandler.systemInfoGetInfo },
|
|
26
28
|
'SystemInfo.getProcessInfo': { type: 'LOCAL', handler: LocalHandler.systemInfoGetProcessInfo },
|
|
27
29
|
|
|
@@ -458,6 +458,35 @@
|
|
|
458
458
|
font-size: 12px;
|
|
459
459
|
}
|
|
460
460
|
|
|
461
|
+
.toggle-switch {
|
|
462
|
+
position: relative;
|
|
463
|
+
display: inline-block;
|
|
464
|
+
width: 40px;
|
|
465
|
+
height: 22px;
|
|
466
|
+
}
|
|
467
|
+
.toggle-switch input { opacity: 0; width: 0; height: 0; }
|
|
468
|
+
.toggle-slider {
|
|
469
|
+
position: absolute;
|
|
470
|
+
cursor: pointer;
|
|
471
|
+
top: 0; left: 0; right: 0; bottom: 0;
|
|
472
|
+
background-color: #ccc;
|
|
473
|
+
transition: .3s;
|
|
474
|
+
border-radius: 22px;
|
|
475
|
+
}
|
|
476
|
+
.toggle-slider:before {
|
|
477
|
+
position: absolute;
|
|
478
|
+
content: "";
|
|
479
|
+
height: 16px;
|
|
480
|
+
width: 16px;
|
|
481
|
+
left: 3px;
|
|
482
|
+
bottom: 3px;
|
|
483
|
+
background-color: white;
|
|
484
|
+
transition: .3s;
|
|
485
|
+
border-radius: 50%;
|
|
486
|
+
}
|
|
487
|
+
input:checked + .toggle-slider { background-color: #4CAF50; }
|
|
488
|
+
input:checked + .toggle-slider:before { transform: translateX(18px); }
|
|
489
|
+
|
|
461
490
|
.divider {
|
|
462
491
|
height: 1px;
|
|
463
492
|
background: #e5e7eb;
|
|
@@ -721,6 +750,16 @@
|
|
|
721
750
|
</div>
|
|
722
751
|
<button class="btn btn-primary btn-block" id="connectBtn">🔗 保存并连接</button>
|
|
723
752
|
|
|
753
|
+
<div class="config-item" style="display: flex; justify-content: space-between; align-items: center; margin-top: 12px;">
|
|
754
|
+
<label style="font-size: 13px; color: #666;">
|
|
755
|
+
🔇 自动静音新标签页
|
|
756
|
+
</label>
|
|
757
|
+
<label class="toggle-switch">
|
|
758
|
+
<input type="checkbox" id="autoMuteToggle" checked>
|
|
759
|
+
<span class="toggle-slider"></span>
|
|
760
|
+
</label>
|
|
761
|
+
</div>
|
|
762
|
+
|
|
724
763
|
<div class="divider"></div>
|
|
725
764
|
|
|
726
765
|
<div class="usage-guide">
|
|
@@ -258,8 +258,16 @@
|
|
|
258
258
|
elements.serverAddress.value = result.wsAddress;
|
|
259
259
|
}
|
|
260
260
|
});
|
|
261
|
+
chrome.storage.local.get(['autoMute'], function(result) {
|
|
262
|
+
document.getElementById('autoMuteToggle').checked = result.autoMute !== false;
|
|
263
|
+
});
|
|
261
264
|
}
|
|
262
265
|
|
|
266
|
+
document.getElementById('autoMuteToggle').addEventListener('change', function(e) {
|
|
267
|
+
chrome.storage.local.set({ autoMute: e.target.checked });
|
|
268
|
+
addLog(e.target.checked ? '🔇 自动静音已开启' : '🔊 自动静音已关闭', 'action');
|
|
269
|
+
});
|
|
270
|
+
|
|
263
271
|
fetchState();
|
|
264
272
|
|
|
265
273
|
setInterval(fetchState, 5000);
|
|
@@ -16,5 +16,14 @@ var Config = {
|
|
|
16
16
|
chrome.storage.local.get(['wsAddress'], function(result) {
|
|
17
17
|
callback(result.wsAddress || Config.WS_URL);
|
|
18
18
|
});
|
|
19
|
+
},
|
|
20
|
+
AUTO_MUTE: true,
|
|
21
|
+
getAutoMute: function(callback) {
|
|
22
|
+
chrome.storage.local.get(['autoMute'], function(result) {
|
|
23
|
+
callback(result.autoMute !== false);
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
setAutoMute: function(enabled, callback) {
|
|
27
|
+
chrome.storage.local.set({ autoMute: enabled }, callback);
|
|
19
28
|
}
|
|
20
29
|
};
|