我想要监听选项卡中发生的所有时间线事件, 我创建了一个扩展程序。
chrome.browserAction.onClicked.addListener(function(tab) {
var tabId = tab.id;
console.log("tabId = ", tabId);
if (running === false) {
checkAvailable();
chrome.debugger.attach({
tabId: tabId
}, protocolVersion, function() {
running = true;
if (chrome.runtime.lastError) {
console.log(chrome.runtime.lastError.message);
return;
}
chrome.debugger.sendCommand({
tabId: tabId
}, "Tracing.start", { "maxCallStackDepth" : 5 }, function(response) {
console.log(response);
// listening for responses from Timeline
chrome.debugger.onEvent.addListener(function(tabId, method, params) {
console.log("params = ", params);
});
});
chrome.debugger.onDetach.addListener(function (source, reason) {
running = false;
});
});
} else {
chrome.debugger.detach({
tabId: tabId
}, null);
running = false;
}
});
点击图标后,我可以看到页面顶部出现了黄色条形,并显示“扩展正在调试此页面”的消息。
然而,在按下F5后,我没有看到我的扩展监听时间轴事件。
看起来事件还没有被分配。
chrome.debugger.onEvent.addListener(function(tabId, method, params) {
console.log("params = ", params);
});
有什么想法吗?