-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebworker
More file actions
41 lines (37 loc) · 1.27 KB
/
Copy pathwebworker
File metadata and controls
41 lines (37 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const version = '1.3';
async function onAttach(debuggeeId) {
/** Enable receiving 'Target.attachedToTarget' events */
await chrome.debugger.sendCommand(debuggeeId, 'Target.setAutoAttach', {
autoAttach: true,
waitForDebuggerOnStart: true,
flatten: true,
}); //
/** Enable Network events for the current tab */
chrome.debugger.sendCommand(debuggeeId, 'Network.enable');
}
function allEventHandler(debuggeeId, message, params) {
/** When workers are created, 'Target.attachedToTarget' events are fired */
if (message === 'Target.attachedToTarget') {
/** Attach debugger to workers */
chrome.debugger.attach(
{ targetId: params.targetInfo.targetId },
version,
() => {
/** Enable Network for workers to receive WebSocket events */
chrome.debugger.sendCommand(
{ targetId: params.targetInfo.targetId },
'Network.enable'
);
}
);
} else {
console.log(message, params);
}
}
chrome.debugger.onEvent.addListener(allEventHandler);
/** Click extension icon to attach debugger to the current tab */
chrome.action.onClicked.addListener(function (tab) {
const tabId = tab.id;
const debuggeeId = { tabId };
chrome.debugger.attach(debuggeeId, version, onAttach.bind(null, debuggeeId));
});