New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SharedServiceWorker needs an error event/interface #104
Comments
Feels like we need a namespace on navigator, would simplify the method/event names too. |
This came out of a discussion with @michael-nordman about error handling. I was also thinking navigator.serviceWorker.onerror would work. The only trick with that is it requires a serviceWorker to be present. I think that's ok though: the only error case that @michael-nordman and I could come up with right now was the case mentioned above (i.e. the case where the service worker has in fact been registered, but fails to start) in which case navigator.serviceWorker would exist. |
Feels weird having the events in different places, but… Is It's not always decided on page load, a page could have no serviceWorker, then one is registered, if it If this is a problem I'll draft up another api where |
As it stands today, navigator.serviceWorker looks sync, but under the covers, it doesn't need to be sync at all:
This means that the frontend only has to have a local object that is initialized at pageload time, that really only exists so as to be visible to the DOM. It doesn't need to reach into any storage or anything during access to the DOM object 'navigator.serviceWorker' The only time this will really be a problem is if we add synchronous attributes to this object, that can't be inferred during pageload time. I don't think we have any plans to do that. |
oh and since onerror is asynchronous (being an event) then it is ok too. The frontend implementation of navigator.serviceWorker.onerror = function(...) { ...} merely has to store a reference to that function in that frontend DOM object, it doesn't require being stored anywhere. |
The service worker can decide to take over during the lifetime of the document. Or did we kill that feature? |
@annevk As I understand it there has never been a way to take over in the middle of a document's existence - the document is either controlled from the start, or not at all. |
@alecf https://github.com/slightlyoff/ServiceWorker/blob/master/service_worker.ts#L98 (InstallEvent.prototype.replace) |
@annevk,the replace method can advance the version for already "controlled" document during the lifetime of a document. The navigator.serviceWorker is non null before and after that transition. |
Really? So what happens if you call replace() oninstall of the first worker, where there isn't another present? I thought it took over. |
Maybe we need to be clear that the 'onerror' is happening in the document. replace() is something that happens in the service worker. Looking at
if a page is not currently controlled, then replace() isn't affecting that window, right? But I think we're veering off the original topic here - this bug is about an error event in a document when the service worker fails to start. consider a service worker: if (Math.random() > .9) {
foo.bar = baz;
} 9 times out of 10 this will start fine, so it will probably install just fine. 1 time out of ten, this script will fail to run. Imagine it's successfully installed but fails to run 5 minutes later. the page needs to be able to capture that if it cares:
or possibly just |
There are some other events in the works too, surfacing this one as 'navigator.onserviceworkererror' looks most in keeping with the other event handlers i've seen mentioned in the .ts file. |
@michael-nordman agreed. I'll open another issue for the |
So with the new API this is the ServiceWorker object. It has onerror. Is that what we need? |
Dedicated workers currently throw errors like this:
We can do 1 easily, and should. However, this doesn't catch syntax errors. We can also do 2, but that won't catch syntax errors either. We could fire an error event at We could also bubble up to |
Thinking about the use-cases (following from #198)…
That leaves errors that happen before the SW instance is created. AppCache has an error event that covers network-related update failures, and also parse failures. However, once again we'd lose any errors that happened outside the life of a page. |
It may be important to tell a server that its new SW script has a parse error. Could we fire the |
…or However, update errors are part of the norm. If you're offline or in a captive portal, those are update failures. I guess parse errors could be treated differently. |
These feels like enhancements, let me know if something really ought to be offered as part of a v1/minimal viable product. |
Happy to treat as enhancements. We should probably have a call to sort this out. |
It has been pointed that we need a common understanding of how to use labels and milestones. I'll work on a draft to suggest how we should use the labels and milestones. Let me make some adjustments based on how I believe we should use these: enhancement: anything that was assessed as not having any impact on milestone 1 decisions and can therefore be safely discussed, rejected or prioritized later. milestone: to mark items we agreed to get done in principle by a given revision. I would argue that we should only focus on the current milestone and leave the rest without specific milestones. |
We need a way to communicate to pages that service workers may have failed to start on subsequent boot.
The text was updated successfully, but these errors were encountered: