Javascript Firefox引导加载项中的CustomEvent错误
从 createEvent方法已弃用。使用 相反 在Javascript Firefox引导加载项中的CustomEvent错误,javascript,firefox,firefox-addon,firefox-addon-restartless,Javascript,Firefox,Firefox Addon,Firefox Addon Restartless,从 createEvent方法已弃用。使用 相反 在bootstap.js中 // this works let event = window.document.createEvent('Event'); event.initEvent('main-unload',false,false); window.dispatchEvent(event); // this doesn't work let event = new CustomEvent('main-unload', {"detail"
bootstap.js中
// this works
let event = window.document.createEvent('Event');
event.initEvent('main-unload',false,false);
window.dispatchEvent(event);
// this doesn't work
let event = new CustomEvent('main-unload', {"detail":{"hazcheeseburger":true}});
window.dispatchEvent(event);
//Console error: 1404023846296 addons.xpi WARN Exception running bootstrap method shutdown on ***addon-id****
我缺少什么?您缺少了
CustomEvent
构造函数。bootstrap.js
代码没有其中一个,只有windows有
以下方面应起作用:
let event = new (window.CustomEvent)('main-unload',
{"detail":{"hazcheeseburger":true}});
来自加载项范围的自定义事件最初很棘手,在
addEventListener
上有第四个参数。查看此主题:@Noitidart正确,但这仅适用于特权上下文(bootstrap.js
、覆盖脚本等)想要侦听由非特权网站发送的事件时,因此它在这里并不适用。最好将启动
/关闭
包含在try-catch块中,该块包含Cu.reportError
任何异常。更容易找出哪些代码被破坏。regualaraddons.xpi WARN
消息在这方面没有真正的帮助。