Aaron
Aaron

Reputation: 1489

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:

Upvotes: 3

Views: 1524

Answers (1)

sibabrat swain
sibabrat swain

Reputation: 1368

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();
        }
     }
  });
}

Upvotes: 5

Related Questions