-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
31 lines (26 loc) · 962 Bytes
/
background.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
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.debugger.attach({tabId:tab.id}, version,
onAttach.bind(null, tab.id));
});
var version = "1.0";
function onAttach(tabId) {
if (chrome.runtime.lastError) {
alert(chrome.runtime.lastError.message);
return;
}
chrome.debugger.onEvent.addListener(onEvent);
chrome.debugger.sendCommand({tabId:tabId}, 'HeapProfiler.takeHeapSnapshot', {reportProgress: false}, function() {
chrome.downloads.download({
url: window.URL.createObjectURL(new Blob([json], {type: 'application/json'})),
filename: new Date().toISOString().replace(/:/g,'.') + ".heapsnapshot"
});
chrome.debugger.detach({tabId:tabId});
});
var json = '';
function onEvent(debuggeeId, message, params) {
if (tabId == debuggeeId.tabId && message == 'HeapProfiler.addHeapSnapshotChunk' && typeof(params.chunk) !== 'undefined') {
debugger;
json += params.chunk;
}
}
}