javascript - getSubscription upon activation of sw -
i'm not sure i'm making mistake.
i want register service worker , moment it's "activated" make xhr request server in order store subscription data.
self.addeventlistener('activate', function(event) { console.log('activated', event); event.waituntil( self.registration.pushmanager.getsubscription().then(function (subscription) { console.log(subscription);//this null }) ) })
so far wasn't able subscription inside sw, can other javascript on site. not udnerstanding?
edit:
this how register pushmanager
function reg(){ if ('serviceworker' in navigator) { navigator.serviceworker.register(sw).then(function(reg) { reg.pushmanager.subscribe({ uservisibleonly: true }).then(function(subscription) { send_subscription(subscription); }); }).catch(function(error) { console.log(':^(', error); }); } } function send_subscription(subscription){ [...] }
you attempting subscription pushmanager
:
the pushmanager.getsubscription() method of pushmanager interface retrieves existing push subscription.
if intended, first have subscribe pushmanager
using pushmanager.subscribe()
.
Comments
Post a Comment