title: How to unregister and remove old service worker?
body: <p>I have register a service woker using .register and can see in Application tab in dev tool. now my questionn is how to unregister this service worker.</p>
  
  <p>I have run this script </p>
  
  <pre><code>if ('serviceWorker' in navigator) {
          window.addEventListener('load', function() {
                  console.group('====SW registration=======');
                  navigator.serviceWorker.register('/sw.js', {scope: './'}).then(function(registration) {
                      console.log('SW registratered successfully');
                      console.log(registration);
                      registration.unregister().then(function(result) {
                          console.log('Unregistered done', result);
                      });
                  }).catch(function(error){
                      console.error('sw registration failed', error);
                  });
                  console.groupEnd();
          });
  }
  </code></pre>
  
  <p>But I see that by doing this, we are actually first registering the service worker and then unregister it. This seems not the correct way to me.</p>
  
  <p>Alternatively, I can click on <strong>unregister</strong> link near to the service worker from dev tools <em>Application > Service Workers</em> and also click on <em>Application >Clear Storage</em> and re-open the URL in the new tab.</p>
  
  <p>but when I check through <strong>chrome://serviceworker-internals/</strong></p>
  
  <p>it displays the list of old and unregistered service worker at bottom of list ( see image) </p>
  
  <p><a href="https://i.stack.imgur.com/REJmQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/REJmQ.png" alt="unregistered sw"></a></p>
  
  <p>So why I am seeing the redundant service worker list here? when will it update? does this is the default behaviour of chrome browser.</p>