Web push notifications in chrome

拟墨画扇 提交于 2019-12-25 03:26:17

问题


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?


回答1:


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 \


来源:https://stackoverflow.com/questions/53134261/web-push-notifications-in-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!