Chrome中的Web推送通知 [英] Web push notifications in chrome

查看:364
本文介绍了Chrome中的Web推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了Web推送通知,并且它们可以在Firefox中正常运行(已注册服务工作者,已创建订阅,存储了订阅数据,使用订阅数据通知已成功发送).我曾在Chrome和Opera中尝试过相同的操作,但没有任何反应.我尝试调试,然后在发送推送通知后,浏览器收到了通知,执行了代码,但是没有任何反应.没有错误,代码一直运行到最后.服务人员代码如下:

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');
});

我在控制台中看到推送开始"和推送完成".服务器使用https.任何想法,有什么问题吗?

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

推荐答案

假设您有一个没有https的开发域. Google Chrome仅在使用配置的SSL运行时发送通知.

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

如何跳过:对于本地开发,您可以使用unsafely-treat-insecure-origin-as-secure选项启动Chrome.

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 \

这篇关于Chrome中的Web推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆