title: Failed to subscribe the user: DOMException: Subscription failed - no active Service Worker
body: <p>I am trying to learn from code lab google but I got an error while implementing it.</p>
  
  <p>here is my code.</p>
  
  <p>Registration of service worker</p>
  
  <pre><code> if ('serviceWorker' in navigator &amp;&amp; 'PushManager' in window) {
    console.log('Service Worker and Push is supported');
  
    navigator.serviceWorker.register('sw.js')
    .then(function(swReg) {
      console.log('Service Worker is registered', swReg);
  
      swRegistration = swReg;
    })
    .catch(function(error) {
      console.error('Service Worker Error', error);
    });
  } else {
    console.warn('Push messaging is not supported');
    pushButton.textContent = 'Push Not Supported';
  }
  </code></pre>
  
  <p>in this code snippet I got error</p>
  
  <pre><code>function subscribeUser() {
    const applicationServerKey = urlB64ToUint8Array(applicationServerPublicKey);
    swRegistration.pushManager.subscribe({
      userVisibleOnly: true,
      applicationServerKey: applicationServerKey
    })
    .then(function(subscription) {
      console.log('User is subscribed.');
  
      updateSubscriptionOnServer(subscription);
  
      isSubscribed = true;
  
      updateBtn();
    })
    .catch(function(err) {
      console.log('Failed to subscribe the user: ', err);
      updateBtn();
    });
  }
  </code></pre>
  
  <p>console.log('Failed to subscribe the user: ', err); 
  here I got error : Failed to subscribe the user:  DOMException: Subscription failed - no active Service Worker</p>