Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mistakenly added service worker. Removed it but how to get it off existing computers?

When starting an Angular (6) project, i used a template that had a service worker. Several months later, i had a problem that the solution was to remove the service worker (via removing ServiceWorkerModule.register from my app.module imports). However, every computer that opened that app prior to that version still has the service worker installed and running (still causing the original issue). I know I can manually remove one on one computer via dev-tools, but how can I get a solution in code?

Some Things I've tried:

  • https://angular.io/guide/service-worker-devops#fail-safe This says you can remove your ngsw.json file and the service worker will "self destruct" but our running code's root folder doesn't have a ngsw.json, only a ngsw-config.json. Also says you can rename safety-worker.js to the name of your old service worker but my deployed code doesn't have safety-worker.js nor do i know the name of my service worker.
like image 317
Aaron Avatar asked Jan 18 '26 02:01

Aaron


1 Answers

You can 'unregister' the service worker using javascript. Here is an example:

if ('serviceWorker' in navigator) {
      navigator.serviceWorker.getRegistrations().then(function (registrations) {
        //returns installed service workers
        if (registrations.length) {
          for(let registration of registrations) {
            registration.unregister();
        }
     }
  });
}
like image 134
sibabrat swain Avatar answered Jan 20 '26 18:01

sibabrat swain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!