
function register() {
  navigator.serviceWorker.register("sw.js", {scope: '/'}).then(
    function(serviceWorkerRegistration) {
      serviceWorkerRegistration.pushManager.subscribe().then(
        function(pushSubscription) {
          console.log(pushSubscription.endpoint);

          var data = new FormData();
          data.append('endpoint', pushSubscription.endpoint);
          var xhr = new XMLHttpRequest();
          xhr.open("POST", "/register");
          xhr.onload = function () {
            console.log(this.responseText);
            window.location = "/manage"
          };
          xhr.send(data);

        }, function(error) {
          console.log(error);
        }
      );
    }
  );
}

addEventListener("load", register, false);

@@ -77,88 +77,79 @@
 /'%7D)
-.then(%0A    function(serviceWorkerRegistration
+;%0A%0A  navigator.serviceWorker.ready.then(%0A    function(swr
 ) %7B%0A
+%0A
       s
-erviceWorkerRegistration
+wr
 .pus
@@ -215,58 +215,8 @@
 n) %7B
-%0A          console.log(pushSubscription.endpoint);
 %0A%0A  
@@ -436,52 +436,8 @@
 ) %7B%0A
-            console.log(this.responseText);%0A
     
@@ -522,16 +522,25 @@
       %7D,
+%0A%0A       
  functio

Use serviceWorker.ready.then before calling subscribe