DEV Community

Discussion on: How to send push notifications with Firebase and React

Collapse
 
danielfogacaa profile image
danielfogacaa

I'm having trouble with background notifications, when I click on them nothing happens, would my App.js file be able to see when it was clicked?

Collapse
 
jeremytenjo profile image
Jeremy Tenjo

Hi @danielfoga

Use self.addEventListener('notificationclick', (event) => {} to listen to background notification clicks.

For example:

firebase-messaging-sw.js

...

self.addEventListener('notificationclick', (event) => {
  console.log({ notificationclick: event })
  if (event.action) {
    clients.openWindow(event.action)
  } else {
    // Open tv page
    clients.openWindow(origin + '/tv')
  }
  event.notification.close()
})

Enter fullscreen mode Exit fullscreen mode