I am trying to use Firebase messaging (web). Firebase by default searches for the file \"firebase-messaging-sw.js\" which holds the service worker.
The service work
By using useServiceWorker(registration) you can use notificationonclick event on Firebase push messaging via exiting service worker.
firebase.messaging().useServiceWorker(registration) is working and solved my problem, but keep in mind that I don't know if:
this is a secure way to get payload from the server.
this is the best way to handle push notifications.