javascript - 无法堆叠多个推送通知

标签 javascript google-chrome firefox push-notification notifications

我正在编写代码以将通知推送到浏览器。我的显示通知的代码如下所示

const imageWithTextNotification = (reg) => {
            // more options at https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/showNotification#Syntax
            const options = {
                icon: "imgs/notification.png",

                // 07 - Notification with a body
                body: "Alert!! This is image notification",

                // 09 - Actions on notification click (see sw.js for log)
                actions: [
                    { action: "search", title: "Try Searching!" },
                    // 10 - More Actions
                    { action: "close", title: "Forget it!" },
                ],
                data: {
                    notificationTime: Date.now(),
                    githubUser: "hhimanshu"
                }
            }
            reg.showNotification("Counter=" + counter++, options)
        }

阅读 MDN 的文档后,代码应该堆叠多个通知,因为我没有在 options 对象中使用 tag 属性。

但是,根据我的观察,多个通知不会叠加。相同的通知被替换(请参阅下面演示中计数器值的增加)。请看下面

web push notification

可复制的代码库位于https://codesandbox.io/s/charming-hellman-8q4t3演示可在 https://8q4t3.sse.codesandbox.io/ 获取。

我已经测试过了

Google Chrome => Version 80.0.3987.163 (Official Build) (64-bit)
Firefox => 75.0 (64-bit)

有人可以帮助我了解如何获取多个堆叠通知吗?

谢谢

最佳答案

我还在 Twitter 上与 @gauntface 联系,在他的帮助下,我解决了这个问题。

Here is the Twitter thread

这是解决方案 Stack Push Notifications

关于javascript - 无法堆叠多个推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61132542/

相关文章:

javascript - underscore _.each 和 forEach 有什么区别?

html - 为什么我的 css 不影响我的 html 的字体颜色?

javascript - 获取使用gl.texImage2D绘制的纹理的 'red'像素值

javascript - jquery 将值放入输入框

javascript - 输入元素应该有自动完成属性

php - 从 TCPDF 在 Chrome 中下载 PDF

jquery - 如何在 WebKit 浏览器中使用 jQuery .focus()

javascript - 你如何通过 Firefox 扩展来操作选定的文本

firefox - Geb Firefox 驱动程序 : why my test runs twice?

javascript - 手动输入值时不考虑最大属性