Repository navigation
Description
Which @angular/* package(s) are relevant/related to the feature request?
service-worker
Description
As you know debugging service worker in production can be a pain. Something that has made it easier for me is to display the hash version in the settings menu of my applications, it provides a way to view "version numbers" of deployed service workers and then I can prepare a safety-worker.js for the correct version.
So when I get a user who reports to me they are having issues, I ask them to go to settings and send me the version number there. Before I started using this method it was a pain to explain to users that they must clear cache or unregister.
Last I checked, the hash is only really emitted when update events are fired (and it is not type safe).
I would like an easier/official way of accessing the service workers hash/version to make it easier to debug and identify what version of deployed service worker is giving issues in deployed apps.
Proposed solution
A new method to get/expose the hash/version
e.g. this.swUpdate.getHash() or this.swUpdate.getCurrentVersion();
it would also be nice to perhaps have this.swUpdate.getPreviousHash();
Alternatives considered
Continue using a workaround for this value, perhaps add workaround to documentation.
Here is code I have written
availableUpdate$: Observable<void> = this.swUpdate.available.pipe(
map((event: UpdateAvailableEvent) => {
const updateInfo = {
current_version: event.current.hash,
update_version: event.available.hash,
};
// this.storage.set('pwaVersion', updateInfo.current_version).subscribe();
this.swUpdate.activateUpdate();
})
); activatedUpdate$: Observable<void> = this.swUpdate.activated.pipe(
map((event: UpdateActivatedEvent) => {
const previousUpdate =
event.previous?.hash !== undefined ? event.previous.hash : 'none';
const successfulUpdateInfo = {
previous_version: previousUpdate,
current_version: event.current.hash,
};
// this.storage.set('pwaVersion', successfulUpdateInfo.current_version).subscribe();
})
);
Activity
gkalpak commentedon Mar 23, 2022
Adding a method to get the current (and/or latest) version sounds reasonable to me.
BTW, a better work-around imo would be to fetch ngsw/state and parse it:
tayambamwanza commentedon Mar 23, 2022
@gkalpak thanks that would be much appreciated and thanks for the tip as well, I'll give it a shot.
peternixey commentedon Mar 23, 2022
This is so weird - I came to the issues page to ask literally exactly this question and it was the top one here. How bizarre 😂.
(I'd already previously asked this on StackOverflow too).
I did a little bit of research into how the
ngsw/statefile is generated and it appears that the version is taken from the Service Worker Debugger object:As far as I can tell though this object isn't exported generally into Angular. Perhaps if it were then we could access that directly rather than having to parse the page it produces?
angular-robot commentedon Mar 23, 2022
This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list.
You can find more details about the feature request process in our documentation.
gkalpak commentedon Mar 23, 2022
You are right that's it's the
DebugHandlerthat generates thengsw/state, but it retrieves the info we are talking about from the main SW class (Driver). So, it is not possible to expose the instance directly to the page.It is possible, though, to expose a way to retrieve this info from the SW (and hide it behind an
SwUpdatemethod for consuming from the app. (This is what we were discussing with @tayambamwanza above 😉)This is not something that is likely to be prioritized any time soon (if ever), but if anyone wants to work on a PR I would be happy to help/review.
[-]Fetch current service worker hash easily[/-][+]Fetch current service worker version/hash[/+]tayambamwanza commentedon Mar 24, 2022
@gkalpak I don't mind taking it on but maybe since @peternixey has been looking into this for a while maybe he's better equipped to take it on. @peternixey let me know if you want to take it on otherwise I will put something together.
peternixey commentedon Mar 24, 2022
@tayambamwanza I'd be delighted if you wanted to take it. I'm not yet familar with the comms structure of how the service worker communicates with the app so only on top of it to the extent of knowing what the problem is :)
BTW if you did get to tackle this it would be super to be able to surface the service woker AppData JSON to the app too. I'm writing that using the CI process but again there's no clear way to bubble it up into the app unless the version changes.
tayambamwanza commentedon Mar 25, 2022
@peternixey @gkalpak Ok I'll take on this as a side project, I've never done a pull request to Angular repo so forgive me if I don't get it right first time round.
13 remaining items
dylhunn commentedon Sep 29, 2022
If there are no unforeseen complications, we'd likely accept a PR for this.
artemv01 commentedon Oct 23, 2022
hi @gkalpak , do you think adding an additional url like 'ngsw/state/latest-hash' that acts just like 'ngsw/state' but only returns the hash is acceptable? Or we rather better off adding a new method to SwUpdate that utilizes CacheDatabase?
JeanMeche commentedon Mar 18, 2023
I've opened #49474, let me know what you think !
tayambamwanza commentedon Mar 20, 2023
@JeanMeche thank you, haven't had time to get around to this, is it in observable because you are waiting for the value to be retrieved or for some other reason? I thought the hash only changed whenever app is built so thought it would basically be instantly available.
JeanMeche commentedon Mar 20, 2023
The hash is generated by the service-worker (it's a sha1 of the manifest).
Since the value can be updated (when a new version is available), I made it an observable.
SkyZeroZx commentedon Aug 2, 2025
Is there any update on this? I saw the PR but it didn't get merged?
JeanMeche commentedon Aug 29, 2025
With #63364 we've announced that the service-worker package in now in maintenance mode and will not receive feature PRs and feature requests.
The message is also visible here: https://angular.dev/ecosystem/service-workers
angular-automatic-lock-bot commentedon Sep 29, 2025
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.