soney soney - 1 year ago 142
Javascript Question

Chrome Debugging Protocol: HeapProfiler.getHeapSnapshot Ignores Callback

I'm working on a testing suite (implemented as a Chrome extension) that programmatically takes and analyzes heap snapshots with Chrome/Chromium's remote debugging protocol. Because

doesn't seem to be part of the public protocol, I'm using this page for reference.

Right now, I'm able to take a heap snapshot by calling
like in the snippet below. However, when I try calling
, my callback is completely ignored.

var debuggerId = {tabId:};
chrome.debugger.attach(debuggerId, "1.0", function() {
var listener = function(source, method, params) {
if(source.tabId === debuggerId.tabId) {
if(method === "HeapProfiler.addProfileHeader") {
var uid = params.header.uid;
chrome.debugger.sendCommand(debuggerId, "HeapProfiler.getHeapSnapshot", { uid: uid }, function() {
console.log("I never get called!");
chrome.debugger.sendCommand(debuggerId, "HeapProfiler.takeHeapSnapshot", { reportProgress: false }, function() {
if(chrome.runtime.lastError) { console.error(chrome.runtime.lastError); }

Answer Source

It is a bug in DevTools. I've filled an issue in chrome bug tracker.

Fortunately there is a workaround. You have to enable Debugger agent before getting the snapshot.

chrome.debugger.sendCommand(debuggeeId,"Debugger.enable", { }, function() { });

Three other commands were also affected by this bug.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download