无法堆叠多个推送通知

时间:2020-04-10 01:01:03

标签: 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阅读文档之后,由于我没有在tag对象中使用options属性,因此代码应堆叠多个通知。

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

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)

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

谢谢

1 个答案:

答案 0 :(得分:1)

我还与Twitter上的@gauntface保持联系,在他的帮助下,我得以解决此问题。

Here is the Twitter thread

这是解决方案 Stack Push Notifications