0
votes

I have created web push notifications and they work in Firefox ok (service worker is registered, subscription created, subscription data stored, using subscription data notification is sent ok). I have tried the same in Chrome and Opera, but nothing happens. I tried to debug, and after I send push notification, browser receives it, executes code, but nothing happens. There are no errors, code runs till the end. Service worker code is the following:

'use strict';
self.addEventListener('push', function(event) {
  console.log('Push started');
  const promiseChain = self.registration.showNotification('Hello, World.');

  event.waitUntil(promiseChain);
  console.log('Push finished');
});

I see in console 'Push started' and 'Push finished'. Server uses https. Any ideas, what can be wrong?

2
I have no idea about how its work in Firefox, so I might sound stupid, but did you remember to ask the user for permission to send them notifications? developers.google.com/web/fundamentals/codelabs/… - Benjaco
Yes, I ask for permission to send notifications before subscribing. When I check permissions, it shows notifications are allowed. Possibly that's because I ask for permission in web-page, not in service worker. It happens like this: function askp() { return new Promise(function(resolve, reject) { const permissionResult = Notification.requestPermission(function(result) { resolve(result); }); if (permissionResult) { permissionResult.then(resolve, reject); } }) .then(function(permissionResult) { // get subscription }); } - Vasya

2 Answers

1
votes

A assume you have a development domain with no https. Google Chrome only sends notifications when running with configured SSL.

How to bypass: For local development you can launch Chrome with the unsafely-treat-insecure-origin-as-secure option.

open -a /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
     --args \
     --user-data-dir=$HOME \
     --unsafely-treat-insecure-origin-as-secure=http://your-insecure-domain.dev \
0
votes

I have configured SSL in my application and running it with https.Till i am not getting any notifications in chrome, but in firefox and edge its working.