-
Notifications
You must be signed in to change notification settings - Fork 313
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
Add registeringClientId to the ServiceWorker object #1379
Comments
Calls to The browser can technically update the service worker whenever it wants. It doesn't need to be linked to a client. Can you talk a bit more about why you want some tabs to react to the update, and others to not-react? |
Looking back on this issue several months later, I'm not sure Let me clarify the use case:
For apps the do a lot of SW to window post messaging, the scenario described above could result in a lot of errors for tab A, so tab A would likely want to show a notification to the user that they should reload, whereas tab B will likely work just fine. So, the use case is to enable a way for a developer receiving an
The problem, currently, is that when window code calls either I'm not tied to any particular solution to this problem, but if we could add a way for a page to reason about whether an Some possible solutions:
|
On the Workbox team, we're currently building a library that will run in the window context and aid in SW registration, updates, and lifecycle management (design doc).
One thing I discovered while working on an early prototype is there are use cases we want to support that are currently not possible (or they're super hacky) to achieve given the current spec.
Here's an example of two cases that are very difficult to reliably distinguish between (AFAIK):
updatefound
event.updatefound
event is triggered.The code running in tab A cannot easily tell that the updated SW wasn't triggerred by its call to
navigator.serviceWorker.register()
.This isn't necessarily a big problem if the SW code doesn't call
skipWaiting()
, or if it just displays a reload banner any time an update is found, but realistically there are cases where webapps want to be more aggressive about updates, or perform in-place updates, and in those cases it's really important to know whether the given update is the one your app was expecting or a future update your code isn't prepared to handle.I think a reasonable addition to the SW spec would be a property like
registeringClientId
, which would match the client of the window that executed thenavigator.serviceWorker.register()
code.Then, in an
updatefound
callback, a page could compare its clientId (my understanding is we want to expose the Clients API on the window at some point) to theregisteringClientId
property onevent.target.installing
and determine whether the update came from its version of the code.Another possible solution (arguably cleaner but probably also less doable), is a change to the way
register()
works. At the moment, there's no easy way to tell if aregister()
call didn't result in an update. If the result of callingregister()
(or some new method) came with any sort of signal for when an update was not found, then it would make the above issue a lot easier to solve, as you'd know you wouldn't need to add anyupdatefound
event listeners in that case.The text was updated successfully, but these errors were encountered: