1
votes

From document.createEvent

The createEvent method is deprecated. Use event constructors instead.

In 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****

What am I missing?

1
Custom events from addon scope is tricky initially, there's this 4th argument on addEventListener. Check out this topic: How to listen to custom events on all windows, bubbling issue? - Noitidart
@Noitidart Correct, but that only applies when a privileged context (bootstrap.js, overlay script, etc.) wants to listen to events dispatched by an unprivileged website, so it doesn't really apply here. - nmaier
It might be a good idea to enclose startup/shutdown in try-catch blocks that Cu.reportError any exceptions. Makes it easier to figure out what code is broken. The regualar addons.xpi WARN message is not really helpful in that regard. - nmaier

1 Answers

1
votes

You're missing the CustomEvent constructor. The bootstrap.js code does not have one of those, only windows do.

The following should work:

let event = new (window.CustomEvent)('main-unload',
                                     {"detail":{"hazcheeseburger":true}});