Skip to content

Feature request: Enhanced Control and Feedback for Service Worker Registration and Caching #57159

@khanurooj5299

Description

@khanurooj5299

Command

build

Description

Currently, the Angular service worker does not provide adequate control and feedback mechanisms during the registration and caching process. This can lead to issues where developers are unable to detect if the service worker registration has failed or if the caching process has been successfully completed.
Example, right now I am unable to detect if the service worker registration failed. After inspection I found out that the navigator.serviceworker.register code is present in main.js file generated after production build. The catch handler attached to the returned promise just consoles the error.
Also, there is no feedback about the caching of assets. The service worker is installed even if any asset could not be cached but some use cases might things to be handled a little differently.

Describe the solution you'd like

The ServiceWorker module could provide some observables which emit such errors and feedback for registration failure, successful caching etc.,
Also more control over caching should be present because for some applications which are fully offline might require that all assets be cached before the Service worker installation is deemed successful.

Describe alternatives you've considered

Tried using the observables provided by SwUpdate service but realized that they don't work for the initial registration.
Tried using navigator.serviceworker.ready promise but this promise never rejects and will wait indefinitely to resolve until some SW is registered.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: service-workerIssues related to the @angular/service-worker package

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions