title: Push notification "Error Registration failed - permission denied" before prompt is clicked?
body: <p>I'm trying to learn how to use <code>Push Notifications</code> but I am getting a </p>
  
  <pre><code>Registration failed - permission denied
  </code></pre>
  
  <p>Error even before I click allow or block the permission prompt.</p>
  
  <p>The line that produces this error in my service worker file is</p>
  
  <pre><code>const subscription = await self.registration.pushManager.subscribe(options)
  </code></pre>
  
  <p>The strange thing is if I click allow notifications after the error and refresh the page it all works fine. </p>
  
  <p>And when I check <code>window.Notification.requestPermission</code> it returns <code>granted</code></p>
  
  <p>Most of the code is from <a href="https://blog.atulr.com/web-notifications/" rel="nofollow noreferrer">https://blog.atulr.com/web-notifications/</a></p>
  
  <pre><code>const urlB64ToUint8Array = base64String =&gt; {
    const padding = '='.repeat((4 - (base64String.length % 4)) % 4)
    const base64 = (base64String + padding).replace(/\-/g, '+').replace(/_/g, '/')
    const rawData = atob(base64)
    const outputArray = new Uint8Array(rawData.length)
    for (let i = 0; i &lt; rawData.length; ++i) {
      outputArray[i] = rawData.charCodeAt(i)
    }
    return outputArray
  }
  
  const saveSubscription = async subscription =&gt; {
    const SERVER_URL = 'http://localhost:8081/save-subscription'
    const response = await fetch(SERVER_URL, {
      method: 'post',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(subscription),
    })
    return response.json()
  }
  
  self.addEventListener('activate', async () =&gt; {
    // This will be called only once when the service worker is installed for first time.
    try {
      const applicationServerKey = urlB64ToUint8Array(
        'BO29MqroVuQiUch951aG0kASkvQy9S4OLshzA3xc12Ar3oAT7UMxjlsq3OMlQXQaSsZILLy7nWuvmbZNZ1YOrXo'
      )
      const options = { applicationServerKey, userVisibleOnly: true }
      const subscription = await self.registration.pushManager.subscribe(options)
      const response = await saveSubscription(subscription)
      console.log(response)
    } catch (err) {
      console.log('Error', err.message)
    }
  })
  
  self.addEventListener('push', function(event) {
    if (event.data) {
      console.log('Push event!! ', event.data.text())
      showLocalNotification('Yolo', event.data.text(), self.registration)
    } else {
      console.log('Push event but no data')
    }
  })
  
  const showLocalNotification = (title, body, swRegistration) =&gt; {
    const options = {
      body,
      // here you can add more properties like icon, image, vibrate, etc.
    }
    swRegistration.showNotification(title, options)
  }
  </code></pre>