0

Based on this answer How do I uninstall a Service Worker? Removing service worker can be done with the bellow code:

navigator.serviceWorker.getRegistrations().then(function(registrations) {
 for(let registration of registrations) {
  registration.unregister()
} })

When I add it. ESLint has the following error:

error iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations no-restricted-syntax

Any idea how to rewrite this code to make ESLint not complain?

idm
  • 189
  • 1
  • 11

2 Answers2

1

Modify the code like this, and use Object.entries/Object.keys/Object.values depending on use-case with forEach:

navigator.serviceWorker.getRegistrations().then(function(registrations) {
 Object.entries(registrations).forEach(registration =>{
  registration.unregister()
}) })
sidverma
  • 1,159
  • 12
  • 24
0

From the GitHub Issue for the error you mentioned.

You could use any of the array iterators mentioned in the link.

registrations.forEach(function (registration) {
  registration.unregister();
});
hendrixchord
  • 4,662
  • 4
  • 25
  • 39