function askPermission() {
  return new Promise(function(resolve, reject) {
    const permissionResult = Notification.requestPermission(function(result) {
      resolve(result);
    });

    if (permissionResult) {
      permissionResult.then(resolve, reject);
    }
  })
  .then(function(permissionResult) {
    if (permissionResult !== 'granted') {
      throw new Error('We weren\'t granted permission.');
    }
  });
}

function subscribeStore(storeId, userId) {
  askPermission()
  .then(function() {
    return navigator.serviceWorker.ready
  })
  .then(function(reg) {
    const subscribeOptions = {
      userVisibleOnly: true,
      applicationServerKey: urlBase64ToUint8Array('BAjY5Vq4p2wwLa-tdde3ip7uBxP02MN_4GTvQv4FDQTCs3b_tWl-eZoqtLhhtp_gPmvnk-CtS4zL4kRyeSb6f6I')
    }
    return reg.pushManager.subscribe(subscribeOptions)
  })
  .then(function() {
    console.log('sucess')
  })
}

function urlBase64ToUint8Array(base64String) {
  const padding = '='.repeat((4 - base64String.length % 4) % 4);
  const base64 = (base64String + padding)
    .replace(/\-/g, '+')
    .replace(/_/g, '/');

  const rawData = window.atob(base64);
  const outputArray = new Uint8Array(rawData.length);

  for (let i = 0; i < rawData.length; ++i) {
    outputArray[i] = rawData.charCodeAt(i);
  }
  return outputArray;
}


@@ -1,16 +1,123 @@
+var publicKey = 'BAjY5Vq4p2wwLa-tdde3ip7uBxP02MN_4GTvQv4FDQTCs3b_tWl-eZoqtLhhtp_gPmvnk-CtS4zL4kRyeSb6f6I'%0A%0A
 function askPerm
@@ -790,181 +790,867 @@
 ray(
-'BAjY5Vq4p2wwLa-tdde3ip7uBxP02MN_4GTvQv4FDQTCs3b_tWl-eZoqtLhhtp_gPmvnk-CtS4zL4kRyeSb6f6I
+publicKey)%0A    %7D%0A    return reg.pushManager.subscribe(subscribeOptions)%0A  %7D)%0A  .then(function(subscription) %7B%0A    var endpoint = subscription.endpoint;%0A    var key = subscription.getKey('p256dh
 ')
+;
 %0A    
-%7D%0A    return reg.pushManager.subscribe(subscribeOptions)%0A  %7D)%0A  .then(
+var auth = subscription.getKey('auth');%0A    sendSubscriptionToServer(endpoint, key, auth);%0A  %7D)%0A%7D%0A%0Afunction sendSubscriptionToServer(endpoint, key, auth) %7B%0A  var encodedKey = btoa(String.fromCharCode.apply(null, new Uint8Array(key)));%0A  var encodedAuth = btoa(String.fromCharCode.apply(null, new Uint8Array(auth)));%0A  $.ajax(%7B%0A      type: 'POST',%0A      url: 'http://localhost:8080/subscribe',%0A      data: %7B%0A        publicKey: encodedKey, %0A        auth: encodedAuth, %0A        endpoint: endpoint,        %0A      %7D,%0A      success: function (response) %7B%0A          console.log('Subscribed successfully! ' + JSON.stringify(response));%0A      %7D,%0A      error: 
 function
 () %7B
@@ -1645,25 +1645,29 @@
 function
-(
+ (err
 ) %7B%0A    
 console.
@@ -1654,24 +1654,28 @@
 (err) %7B%0A    
+ 
+   
 console.log(
@@ -1679,21 +1679,56 @@
 og('
-sucess')
+err', err)%0A      %7D,%0A      dataType: 'json'
 %0A  %7D)
+;
 %0A%7D%0A%0A

send subscribe to server