Log warning if running SW code outside of event handler
Reported by
a...@scirra.com,
Apr 6 2016
|
|||||||
Issue descriptionUserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2700.0 Safari/537.36 Steps to reproduce the problem: It appears Chrome allows code in a SW to execute outside of an event handler. AFAIK the spec disallows this, and Firefox appears to terminate any code outside a SW event handler. This creates a portability headache (see https://www.scirra.com/blog/ashley/27/service-workers-are-a-pain-in-the-ass) since something like a background update check will appear to work in Chrome but fail in Firefox, and may fail in future in Chrome if it is updated to work like Firefox. What is the expected behavior? If code is running outside of a SW event handler, Chrome should either: - terminate it, and log a message to the console that some code was terminated - leave it running, but log a message to the console that code is running outside of an event handler What went wrong? It silently allows non-portable behavior, which creates a nasty gotcha for SW code. Did this work before? N/A Chrome version: 51.0.2700.0 Channel: dev OS Version: 10.0 Flash Version: Shockwave Flash 21.0 r0
,
Apr 6 2016
Yes, exactly.
,
Apr 6 2016
,
Apr 7 2016
Perhaps a single warning if the SW runs code after an event is completed (so the SW is not guaranteed to be alive) would be useful. I'm a bit worried about log spam. "Guaranteed to be alive" is a bit fuzzy. Strictly speaking the spec allows the user agent to terminate the worker at any time (timeouts). Also, the spec allows running such code. Firefox also allows such code execution, in at least some cases. A quick test of setInterval() in onfetch shows the worker is running after it's guaranteed to stay alive. And indeed Firefox developers were supportive of allowing setTimeout() in service worker: https://github.com/slightlyoff/ServiceWorker/issues/838 Related: issue 455540
,
Apr 7 2016
How would you define this? There can be multiple functional events in flight being extended by promises. How can you know if any given chunk of async js code is part of one of those extended promises? Or are you saying just when there have been no extended promises at all? I guess that would work, but possibly miss some out-of-event code. Note, we basically implement the same grace timer approach that chrome does. So code can execute outside of the event.
,
Apr 7 2016
When using SW I found that Firefox was silently terminating some code because it wasn't in an extending promise. It was one of several gotchas that really confused the development process. I'm assuming Firefox is allowed to do that and not a bug, BTW. So I think there should just be a warning logged to the console if the SW is terminated - for any reason - while code is executing or there are promises in-flight. Maybe it could even cover termination while extended events are in-flight too, why not? Having code terminated mid-execution is surprising, and the developer should be informed so they're not left thinking "WTF", which I was thinking too many times while writing SW code.
,
Apr 7 2016
Logging when the service worker is timed out while running code is easier. We have an open bug for that here: https://bugzilla.mozilla.org/show_bug.cgi?id=1167553 Also note, at one point chrome forced service workers to stay alive while devtools was opened. I don't know if it still does that, but it might explain why you weren't seeing service workers killed outside of events there.
,
Apr 8 2016
> Also note, at one point chrome forced service workers to stay alive while devtools was opened. I don't know if it still does that, but it might explain why you weren't seeing service workers killed outside of events there. Yep, that's issue 455540 I linked to above. Maybe the best thing Chrome can do is: - Fix issue 455540 - Fix issue 457968 (but I don't know where we'd show error. when the SW is shutdown I believe the connection with DevTools is severed) +DevTools for advice.
,
Jun 24 2016
Assigning this one back to V8's Seth.
,
Sep 21 2017
,
Dec 13 2017
|
|||||||
►
Sign in to add a comment |
|||||||
Comment 1 by jaffathe...@gmail.com
, Apr 6 2016