Re: [whatwg/dom] Nerfing all events on all event targets in a serviceworker after initial script evaluation seems odd (#371)

There are two intents here:

* Avoid executing the service worker to fire an event that isn't being listened to
* Prevent the user from creating an event listener that's likely to be lost before it's called

Eg

```js
self.addEventListener('install', () => {
  self.addEventListener('activate', () => {
    console.log('hello');
  });
});
```

The above is dangerous, as the listener to "activate" will be lost if the service worker closes between dispatching "install" and "activate".

I agree that we shouldn't be doing this for all targets as @bzbarsky says. For instance we want devs to be able to create a worker during a fetch event, and this rule prevents that.

For `addEventListener` on `ServiceWorkerGlobalScope` I'm struggling to see why throwing isn't the correct thing to do. Sure, it prevents you from lazy-adding a custom listener for manually-dispatched custom events you *know* will run before service worker termination, but the answer there is just to add the listener in the initial execution right?

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/371#issuecomment-261251184

Received on Thursday, 17 November 2016 13:51:34 UTC