navigator.serviceWorker.register('/service-worker.js').then((reg) => {
})
Notification.requestPermission(function(result) {
console.log('User Choice', result);
if (result !== 'granted') {
console.log('No notification permission granted!');
} else {
navigator.serviceWorker.ready
.then(function(swreg) {
console.log("blaxblux");
swreg.showNotification('Successfully subscribed!', {body:'TEST'});
});
}
});
This is my code in main.js
It comes to console.log('blaxblux')
, but doesn't show the notification at all. Request permission works as browser shows a popup with allow button.
What things could be the issues?
(I am using latest version of chrome)
Settings > Sounds & Vibration > Do Not Disturb: if this setting is enabled, Push Notifications will not be received. Make sure this is disabled. Settings > General > Background App Refresh: this setting allows the app to run in the background and must be turned on.
Push notifications look like SMS text messages and mobile alerts, but they only reach users who have installed your app. All the mobile platforms – iOS, Android, Fire OS, Windows and BlackBerry – have their own services for supporting push.
This means the browser can have no windows open, and you'll still receive the push message in your service worker, because the browser in running in the background. The only time a push won't be received is when the browser is completely closed, i.e. not running at all (no marking).
I had a similar problem, but had notifications turned off on my Windows machine for Google Chrome. I went ahead and enabled notifications and they magically started working.
Settings -> System -> Notifications & Actions
Scroll down to the "Get Notifications from these Senders" section and verify "Google Chrome" (or your preferred browser) is set to "On"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With