1

来自document.createEvent

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":{"hazcheeseburger":true}});
window.dispatchEvent(event);
//Console error: 1404023846296  addons.xpi  WARN    Exception running bootstrap method shutdown on ***addon-id****

我错过了什么?

4

1 回答 1

1

您缺少CustomEvent构造函数。该bootstrap.js代码没有其中之一,只有 Windows 有。

以下应该有效:

let event = new (window.CustomEvent)('main-unload',
                                     {"detail":{"hazcheeseburger":true}});
于 2014-06-29T07:11:03.583 回答