-
Notifications
You must be signed in to change notification settings - Fork 312
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
Registration API doesn't expose primitives #534
Comments
Agree
|
In section "8.1 Register" step 7.5 says "Return the result of running the Update algorithm...". This is done unconditionally, independent of if the scriptURL changed or not. As far as I can tell the Update algorithm will hit the network unless an update happened within the last 24h. A |
If the url hasn't changed, you hit 7.2.2.1.2 which returns. It probably should have an "abort these steps" afterwards.
Hmm yeah. Will think on this. |
Ah. I didn't realize the intent was to abort the steps. I don't think that's always the case when an algorithm returns a promise. Though what happens if we're in the process of installing a new worker, either due to a previous Seems like some tweaks are needed if the intent is that update should not be performed if the scriptURL is the same as last time |
Small thing, but we should somewhere agree on whether or not every time an algorithm says "return" it also needs to say "and stop running these steps". From a programming POV requiring the second sentence is silly, but maybe existing specs overrule such concerns. |
Yup, agreed. |
Since we don't know whether the new register request's scriptURL is byte-for-byte match to what has been installed, it just runs through to Update algorithm 4.3.10 where it downloads and checks it and resolve with the existing registration if the script has not been updated.
+1 to not explicitly specify "stop running these steps" for "return". For the majority of the cases "return" would mean stopping the steps from their. It seems it'd be better to articulate that in the opposite case. e.g., the snapshot version of the XHR's send() method stated explicitly, "Return the send() method call, but continue running the steps in this algorithm.", which is a rarer case. |
We added
|
As I was writing up the proposals in issue #445 I noticed some mainly unrelated oddities in the current registration API.
Right now there's a few operations that aren't exposed through the API. These operations are instead only available
serviceWorker.ready
property lets you do this, but only for the SW whose scope covers the current page. If you want to do it for any other SW you have to create an<iframe>
to a page within that scope and call serviceWorker.ready there.register()
, but that forces you to pass in the same registration parameters as when the registration was originally. It also creates a new "service worker registration", which I'm not sure if that has the side effect that it causesgetRegistration(s)
to return a differentServiceWorkerRegistration
instance (or doesgetRegistration(s)
always return new instances?)register()
does this, but it also forces an update check if the registration already exists.Per extensible web we should expose these lower level operations rather than just have them be part of larger APIs.
We could solve 1. by firing events on
navigator.serviceWorker
whenever registrations are added/removed/updated. Or we could add something likeregistrationReady(url)
which is likegetRegistration(url)
except rather than resolving with undefined if no registration is found, it waits to resolve until such a registration is created.Adding a
Promise<boolean> ServiceWorkerRegistration.update()
function would solve 2.I don't have a great solution for 3. One option would be to have
register()
not do an update check if a registration exists. That wayregister()
would provide this primitive. Alternatively we could add agetOrRegister()
function which is likeregister()
, except it doesn't do the update check.The text was updated successfully, but these errors were encountered: