网页推送在本地的iframe上运行良好,但当我上传到云服务器时,它不能只在chrome或chrome浏览器中工作。
我已经开发了一个从Iframe提供服务的webpush微服务。这在本地运行得很好,但当我上传到云服务器时,它并不只在chrome或chrome浏览器中工作。你可以从https:alemran.me进行检查(点击机器人中的^图标)。
Web Worker:
self.addEventListener('push', function (event) {
if (!(self.Notification && self.Notification.permission === 'granted')) {
return;
}
const sendNotification = (title, body ) => {
return self.registration.showNotification(title,
body
);
};
if (event.data) {
const message = JSON.parse(event.data.text());
event.waitUntil(sendNotification(message.title,message.message));
}
});
There is no error show in console发布于 2019-06-06 14:55:24
您可以使用url打开一个新窗口,并获得用户....的权限。像这样:
let win = window.open("your url", "_blank");
let winInterval = window.setInterval(function() {
if (win.closed !== false) {
window.clearInterval(winInterval );
//check your api for user subscription status
}
}, 200);https://stackoverflow.com/questions/56373672
复制相似问题