从 Service Worker 发送通知
我有一个 PWA 应用程序,基本上是一个简单的形式。如果网络离线,则保存到本地存储(indexedDB)并在连接在线时发送。到目前为止,一切都很好,但我想向用户显示一条消息“表单已发送到服务器”,但我无法让它工作。我使用属性“SYNC”来执行此功能。在我的服务工作者中,与此功能相关的代码部分是:
self.addEventListener('sync', e => {
console.log('SW: Sync');
if ( e.tag === 'new-form' ) {
// send to DB when onLine
const resp = sendForm(); //up to here all is OK.
self.registration.showNotification(' Succesfully send to MongoDB');// this line is not working
e.waitUntil( resp);
}
});
可能出了什么问题?在javascript方面,已验证Notification.permission ===“已授予”。
I have a pwa app that basically is a simple form. If the network is offline, it is saved to local storage(indexedDB) and send afterwards when the connection is online. Up to here everything is ok, but I would like to show a message to the user 'the form was sent to the server' and I can't get it working. I use the property 'SYNC' for doing this feature. In my service worker the part of the code relative to this feature is:
self.addEventListener('sync', e => {
console.log('SW: Sync');
if ( e.tag === 'new-form' ) {
// send to DB when onLine
const resp = sendForm(); //up to here all is OK.
self.registration.showNotification(' Succesfully send to MongoDB');// this line is not working
e.waitUntil( resp);
}
});
What could be wrong?, in javascript side, It is verified that Notification.permission === 'granted'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论