-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdevtools.js
38 lines (27 loc) · 1.02 KB
/
devtools.js
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
'use strict';
// Create a new panel
const scripts = new Map();
chrome.devtools.panels.create('SPAudit',
null,
'panel.html',
async function (panel) {
const cdt = new ChromeDebuggerDriver();
panel.onShown.addListener(async (panelWindow) => {
cdt.on('Debugger.scriptParsed', (item) => scripts.set(item.scriptId, item));
await cdt.start();
cdt.sendCommand('Debugger.enable', {});
panelWindow.document.addEventListener(InstructionEvent.TYPE, async (instruction) => {
const { data: { command, params } } = instruction;
if (command === 'SPAudit.getScripts') {
instruction.resolve(scripts);
}
cdt.sendCommand(command, params)
.then(instruction.resolve)
.catch(instruction.reject);
});
});
panel.onHidden.addListener(async () => {
await cdt.stop();
scripts.clear();
});
});