title: pushManager notifications "getSubscription" null
body: <p>Attempting to get user subscribed - subscriptions works and the endpoint is added to my database via the Ajax call, but getSubscription seems to always return null and so my "notification instructions" div always shows because isSubscribed is always null.   Any ideas what I'm missing here..?</p>
  
  <pre><code> /*
      *
      *  Push Notifications codelab
      *  Copyright 2015 Google Inc. All rights reserved.
      *
      *  Licensed under the Apache License, Version 2.0 (the "License");
      *  you may not use this file except in compliance with the License.
      *  You may obtain a copy of the License at
      *
      *      https://www.apache.org/licenses/LICENSE-2.0
      *
      *  Unless required by applicable law or agreed to in writing, software
      *  distributed under the License is distributed on an "AS IS" BASIS,
      *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      *  See the License for the specific language governing permissions and
      *  limitations under the License
      *
      */
  
      /* eslint-env browser, es6 */
  
      'use strict';
  
      const applicationServerPublicKey = 'BOoidRv0BZvEcAnbRT3TaRzQxzHVRVtNijn85VB7U01XdDNbsstyUU1Usmv7NXINkdqhwCcCLx0zPOpLfy1oepI';
  
      //const pushButton = document.querySelector('.js-push-btn');
  
  
      $(document).ready(function() {
      var isSubscribed=false;
      var swRegistration = null;
      $('div[id="notifyinstructions"]').on('click',function(e){
      console.log("notifyinstructions clicked");
      $('div[id="notifyinstructions"]').css('display','none');
      });
      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;
          initializeUI();
        })
        .catch(function(error) {
          console.error('Service Worker Error', error);
        });
      } else {
        console.warn('Push messaging is not supported');
        //pushButton.textContent = 'Push Not Supported';
      }
  
      function urlB64ToUint8Array(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 &lt; rawData.length; ++i) {
          outputArray[i] = rawData.charCodeAt(i);
        }
        return outputArray;
      }
  
      function updateBtn() {
       if (Notification.permission === 'denied') {
          console.log('Push Messaging Blocked button.');
         // pushButton.disabled = true;
          updateSubscriptionOnServer(null);
          return;
        }
        if (isSubscribed) {
          console.log('Disable Push Messaging button');
        } else {
          console.log('Enable Push Messaging button');
        }
  
        //pushButton.disabled = false;
      }
      function initializeUI() {
          //pushButton.disabled = true;
  
        // Set the initial subscription value
  
        swRegistration.pushManager.getSubscription()
        .then(function(subscription) {
          isSubscribed = !(subscription === null);
  
          updateSubscriptionOnServer(subscription);
        }).catch(function(err) {
          console.log('getSubscription error: ', err);
         // updateBtn();
        });;
         if (isSubscribed) {
            // TODO: Unsubscribe user
          console.log("already subscribed");
          } else {
          showNotificationInstructions();
          subscribeUser();
          }
      }
      function subscribeUser() {
  
        const applicationServerKey = urlB64ToUint8Array(applicationServerPublicKey);
        swRegistration.pushManager.subscribe({
          userVisibleOnly: true,
          applicationServerKey: applicationServerKey
        })
        .then(function(subscription) {
          console.log('User is subscribed.');
          isSubscribed = true;
          updateSubscriptionOnServer(subscription);
         // updateBtn();
        })
        .catch(function(err) {
          console.log('Failed to subscribe the user: ', err);
         // updateBtn();
        });
      }
      function updateSubscriptionOnServer(subscription) {
        // TODO: Send subscription to application server
  
        const subscriptionJson = document.querySelector('.js-subscription-json');
        const subscriptionDetails =
          document.querySelector('.js-subscription-details');
  
        if (subscription) {
          subscriptionJson.textContent = JSON.stringify(subscription);
          doSubscriptionAjax(subscriptionJson.textContent);
          //subscriptionDetails.classList.remove('is-invisible');
        } else {
          //subscriptionDetails.classList.add('is-invisible');
        }
      }
      function doSubscriptionAjax(subscriptionText){
          $.ajax({
                 url   : 'push?act=upm',
                 type  : 'post',
                 data  : subscriptionText, // data to be submitted
                 dataType: 'json',
                 success: function(response){
                      if(response.status=="ADD_PUSH_MEMBER_OK"){
              console.log("added / updated push subscription data to database");
                      }
              else if(response.status.startsWith("ADD_PUSH_MEMBER_FAIL_")){
              console.log("there was an error adding the push data\n\n"+response.status + "\n" +response.mysql_error +"\n"+response.keystr);
              }
                 }
          });
      return;
      }
      function showNotificationInstructions(){
      $('div[id="notifyinstructions"]').show();
      return;
      }
      });
  </code></pre>
  
  <p>I can send messages to this endpoint using the testing tool at <a href="https://web-push-codelab.glitch.me/" rel="nofollow noreferrer">https://web-push-codelab.glitch.me/</a></p>