The pushManager
property of the ServiceWorkerRegistration
interface returns a reference to the PushManager
interface for managing push subscriptions; this includes support for subscribing, getting an active subscription, and accessing push permission status.
this.onpush = (event) => {
console.log(event.data);
};
navigator.serviceWorker
.register("serviceworker.js")
.then((serviceWorkerRegistration) => {
serviceWorkerRegistration.pushManager.subscribe().then(
(pushSubscription) => {
console.log(pushSubscription.subscriptionId);
console.log(pushSubscription.endpoint);
},
(error) => {
console.error(error);
},
);
});