-
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
Find a way for service workers to get their current state #1077
Comments
It is similar to my issue but I asked to use the same service worker as listener . I want notify my server when I can push a event and when a event can t be notified because no service worker is avaible to receive a notification |
|
F2F: |
|
it is past a lot of time ago when i wrote about this problem .... if i remember correctly in my case i was searching a listener inside the service for all the states of service worker. My idea it was a bit advanced , a bit more for actual html5 :). Service worker is designed with many problems :
|
If we stick this on I would also note we have another issue somewhere about referencing the current global as a Maybe something like
|
I totally agree that sticking this on the registration could get messy. |
Since this is a source of confusion, I would be extra explicit when naming this member. I like @wanderview solution but what about |
@delapuente you can have more than one SW instance running at a time, in this case we want the current context, not a currently running SW. @wanderview's suggestion makes more sense imo. |
Can you? I thought you could only have one executing service worker at a time. With executing I mean running JavaScript code. I thought you could have several service workers in different states at the same time (installing, activating, active...) but only one running at a time. I mean without real parallelism. If this is not the case, and since I continue thinking |
Alright, how about we just go with |
This is not accurate. You can have multiple service workers in different states and executing in separate threads simultaneously. Consider an installing worker handling its install event in parallel with the active worker handling fetch events from current page. |
Thank you for the clarification, @wanderview In that case, the spec says:
So, I'm happy with |
Note, if we do this we will need to also fix #1162. Currently a script cannot access its state at script evaluation time, but with the changes discussed here it might be possible. In that case we will need to expose the initial |
Good catch. I think we can set the initial value of the state attribute to "parsed". For the naming, I give my five cents to One more thing is what we'd expect postMessage() to self will do? Throwing an InvalidStateError? If the use case posed in the OP is about just exposing the state of itself, adding |
I see your reasoning here, but do you think it would be confusing if both of these were true:
One is the webidl interface and the other is an instance of that interface. Single character differences in global names seems a bit dangerous to me. |
I think we already have such a case in ServiceWorkerGlobalScope:
But I understand your point, and it would prevent devs from using |
Yea, we also already have |
@wanderview almost every single one which is exposed on global object: |
I'm less bothered about |
We might want to think about this in relation to #1036 – what would be the difference between a ServiceWorker, and a client representing a service worker? If this turn out to be the same thing (or are merged somehow), |
Or |
Previous discussion of exposing client IDs to the client #643 |
Spec change #1426 Tests web-platform-tests/wpt#17285 I went with |
@aliams @asutherland @youennf @cdumez I believe there was agreement for this feature at the F2F, but I'd like to be sure. TL;DR: New feature: In a service worker, So, if you wanted to know what state this service worker was in, you'd read Are you happy for me to land this change? |
@asutherland @youennf @cdumez nudge. Pretty sure we agreed on this at the f2f, but I don't want to land this without double checking. |
LGTM, thank you for doing this! |
Spec change: #1426 Chrome: https://bugs.chromium.org/p/chromium/issues/detail?id=977496 @youennf @cdumez Please let me know if you have any objections to this. |
LGTM too |
A service worker instance currently has no way to get it's current lifecycle state. There's a bit of a hack one can do where you keep track of the current event as a global variable but that's error prone and doesn't capture the waiting periods correctly.
Imo, the best way to solve this would be to just allow a service worker to get it's ServiceWorker object somehow. Maybe via
self.worker
orself.self
or something like that.The text was updated successfully, but these errors were encountered: