Reputation: 1
I'm trying to implement a service worker in JavaScript to display notifications to users, even when they've closed my website. However, my notifications aren't appearing when closed. Can you provide guidance on how to troubleshoot this issue?
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js',{ scope: "/" })
.then(function(registration) {
console.log('Service Worker registered with scope:', registration.scope);
}).catch(function(error) {
console.log('Service Worker registration failed:', error);
});
} else {
console.log('Service Worker or Background Sync is not supported in this browser.');
}
Upvotes: 0
Views: 87