Re: [whatwg/dom] Prohibit ServiceWorker event handler update after the initialization. (PR #1161)

Past discussion is here https://github.com/whatwg/dom/issues/371#issuecomment-378220178

If the developer adds a service worker global event for "install", "activate", "fetch", "push" after the initial execution of the service worker, they're going to get behavior they don't expect. Worse, it might work as they expect in testing, but sometimes go wrong for real users.

The goal here is to avoid this case. Right now we show a console warning, which is ok, but could it be worth tightening the rules here so issues are found in development?

## Option 1: Throw

I'd forgotten that we'd discussed that previously. We could limit the throwing to a [subset of event types](https://w3c.github.io/ServiceWorker/#service-worker-events), but it seems that folks we still be against that.

## Option 2: Ignore

Instead of throwing, the call could be ignored. This would cause it to fail in dev, and (hopefully) cause the developer to see the console warning, and amend their code. Again, this could be limited to particular event types.

In both cases, the behaviour should be applied to both event listeners and event handlers.

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

Message ID: <whatwg/dom/pull/1161/c1471845751@github.com>

Received on Thursday, 16 March 2023 12:14:52 UTC