Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

service worker show notification not working

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)

like image 317
Nika Kurashvili Avatar asked Feb 21 '20 14:02

Nika Kurashvili


People also ask

Why are my push notifications not working?

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.

What is a mobile push notification?

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.

Do service workers work when browser is closed?

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).


Video Answer


1 Answers

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"

like image 63
birwin Avatar answered Sep 21 '22 18:09

birwin