You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

31 lines
893 B

importScripts("./safari-notifications.js");
self.addEventListener("push", function (event) {
event.waitUntil((async () => {
try {
let payload;
if (event.data) {
payload = JSON.parse(event.data.text());
}
let value = await self.getNotificationCount();
const title = payload ? payload.title : "Custom Title";
const options = {
body: payload ? value : "SAMPLE",
icon: payload ? payload.icon : "icon.png",
badge: payload ? payload.badge : "badge.png",
};
await self.registration.showNotification(title, options);
} catch (error) {
console.error('Error in processing the push event:', error);
}
})());
});
self.addEventListener('message', event => {
if (event.data && event.data.type === 'SEND_LOCAL_DATA') {
self.secret = event.data.data;
console.log('Data stored in service worker:', self.secret);
}
});