我正在开发一个测试套件(作为 Chrome 扩展实现),该套件使用 Chrome/Chromium 的远程调试协议以编程方式获取和分析堆快照。因为Profiler.*
似乎不是公共协议的一部分,我正在使用这一页 http://trac.webkit.org/browser/trunk/Source/WebCore/inspector/Inspector.json以供参考。
现在,我可以通过调用来拍摄堆快照HeapProfiler.takeHeapSnapshot
就像下面的代码片段一样。但是,当我尝试打电话时HeapProfiler.getHeapSnapshot
,我的回调被完全忽略。
var debuggerId = {tabId: sender.tab.id};
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.onEvent.removeListener(listener);
}
}
};
chrome.debugger.onEvent.addListener(listener);
chrome.debugger.sendCommand(debuggerId, "HeapProfiler.takeHeapSnapshot", { reportProgress: false }, function() {
if(chrome.runtime.lastError) { console.error(chrome.runtime.lastError); }
});
});
这是 DevTools 中的一个错误。我已填满an issue https://code.google.com/p/chromium/issues/detail?id=260749在 Chrome 错误跟踪器中。
幸运的是,有一个解决方法。
在获取快照之前,您必须启用调试器代理。
chrome.debugger.sendCommand(debuggeeId,"Debugger.enable", { }, function() { });
其他三个命令也受到此错误的影响。
Profiler.start
Profiler.stop
Profiler.getCPUProfile
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)