yyx990803 / register-service-worker

A script to simplify service worker registration with hooks for common events.
MIT License
638 stars 58 forks source link

Difficulty using the Push API #47

Open maarteNNNN opened 3 years ago

maarteNNNN commented 3 years ago

I'm having some trouble implementing Push notifications in a Quasar PWA. From what I've found on stackoverflow is that the notification needs to be executed immediately before any other code. Using the template given by the repos README.md is am running into the problem. However debugging the chrome dev tools the push notification comes in with the correct payload. But the notification shows: The site has been updated in the background without the provided notification settings I've given. It's pretty difficult to understand what's going wrong.

my ready function:

  async ready() {
    self.addEventListener('push', function (e) {
      e.waitUntil(
        self.registration.showNotification('Test notification', body: 'Testing the push notification' })
      )
    })
    console.log('App is being served from cache by a service worker.')
    const permission = await Notification.requestPermission()
    if (permission === 'granted') {
      console.log('Agora você receberá notificações importantes.')
    } else {
      console.log('Notificações negada.')
    }
  },
AdamGovier commented 6 months ago

Hi @maarteNNNN,

Did you ever find a solution for this?

Thanks, Adam