Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I read pushSubscription.endpoint inside service worker?

I'm using Google Chrome Service Worker to implement a push notification service for my web-users.

Given Chrome current security constraints is not possible to send a payload so I'm fetching the content from my webserver, however is quite complicated to identify at service side which end user is querying for the push payload

Is it possible to get information of the pushSubscription.endpoint or any form or unique identification about yhthat my service-worker is connected to?

like image 698
rat Avatar asked Oct 27 '25 10:10

rat


1 Answers

Inside the service worker you can use self.registration.pushManager.getSubscription().

self.registration.pushManager.getSubscription().then(function(subscription) {
    if (subscription) {
        // do something with subscription.endpoint
    }
});
like image 184
Steffen Avatar answered Oct 30 '25 14:10

Steffen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!