问题描述
我们的Chrome扩展从版本37.0.2062.103开始无法正常工作(它曾经在Chrome版本36.0.1985.143上正常工作)。
具体来说,调试器API在我们使用DOMDebugger时已停止工作。
查看附加代码:(background.js)
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo,tab){
if(changeInfo.status ==loading&& tab.active){
var debugId = {tabId:tabId};
chrome.debugger.attach (debugId,'1.0',function(){
chrome.debugger.sendCommand(debugId,'Debugger.enable',{},function(){
chrome.debugger.sendCommand(debugId,DOMDebugger .setEventListenerBreakpoint,{'eventName':'click'},
function(result){
console.log('registering click');
});
}) ;
});
}
});
chrome.debugger.onEvent.addListener(onEvent);
function onEvent(debuggeeId,method,params){
if(method ==Debugger.paused){
console.log('DONE!');
}
};
扩展程序成功启动调试器。我们得到黄色的调试器功能区。
我们也可以在控制台中看到'注册点击'消息。结果参数是一个空对象{}(第8行)。
然而,一旦点击一个具有点击事件监听器的按钮,就不会发生任何事情。
过去没有任何问题。
看起来像是用。需要调用DOM.enable才能使其工作。在Chrome方面,我们应该在setEventListenerBreakpoint的基础上隐式启用DOM域以实现向后兼容。不幸的是它已经被挤进了稳定的版本。
Our chrome extension does not work correctly anymore since version 37.0.2062.103 (It used to work correctly on chrome version 36.0.1985.143).
Specifically, the debugger API has stopped working for us when we use the DOMDebugger.See the attached code: (background.js)
chrome.tabs.onUpdated.addListener(function(tabId,changeInfo,tab){
if( changeInfo.status == "loading" && tab.active){
var debugId = {tabId:tabId};
chrome.debugger.attach(debugId, '1.0', function() {
chrome.debugger.sendCommand(debugId, 'Debugger.enable', {}, function() {
chrome.debugger.sendCommand(debugId, "DOMDebugger.setEventListenerBreakpoint", {'eventName':'click'},
function(result) {
console.log('registering click');
});
});
});
}
});
chrome.debugger.onEvent.addListener(onEvent);
function onEvent(debuggeeId, method,params) {
if(method=="Debugger.paused"){
console.log('DONE!');
}
};
The extension successfully starts the debugger. we get the yellow debugger ribbon.We also see the 'registering click' msg in the console. the result argument is an empty object {} (line 8).However upon clicking on a button that has a click event listener nothing happens.
It used to work without any issues.
It seems like it regressed with https://codereview.chromium.org/305753005. One needs to call "DOM.enable" for it to work now. On the Chrome side, we should implicitly enable DOM domain upon setEventListenerBreakpoint for backwards compatibility. Unfortunately it already squeezed into the stable release.
这篇关于Chrome扩展程序:(DOM)调试器API不再有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!