title: Uncaught (in promise) DOMException: Subscription failed - no active Service Worker
body: <p>I'm trying to subscribe the user but this is the error I get the first time.
  The second time, it is working because the user is already active</p>
  
  <p>This is my code :</p>
  
  <pre><code> if ('serviceWorker' in navigator) {
     console.log('Service Worker is supported');
     navigator.serviceWorker.register('sw.js').then(function(reg) {
       console.log(':^)', reg);
       reg.pushManager.subscribe({
         userVisibleOnly: true
       }).then(function(sub) {
         console.log('endpoint:', sub.endpoint);
         var div = document.getElementById('id');
         div.innerHTML = div.innerHTML + sub.endpoint;
         // var b = document.getElementsByTagName('body')[0];
         //b.appendChild(div);
         //alert(sub.endpoint);
       });
     });
   }
  </code></pre>
  
  <p>I already tried the following, but the <code>ready.then()</code> method is not happening:</p>
  
  <pre><code> if ('serviceWorker' in navigator) {
     console.log('Service Worker is supported');
     navigator.serviceWorker.register('sw.js').then(function(sreg) {
       console.log(':^)', sreg);
       navigator.serviceWorker.ready.then(function(reg) {
         reg.pushManager.subscribe({
           userVisibleOnly: true
         }).then(function(sub) {
           console.log('endpoint:', sub.endpoint);
           var div = document.getElementById('id');
           div.innerHTML = div.innerHTML + sub.endpoint;
           // var b = document.getElementsByTagName('body')[0];
           //b.appendChild(div);
           //alert(sub.endpoint);
         });
       });
     });
   }
  </code></pre>
  
  <p>Any ideas ?</p>