我正在研究将通知推送到浏览器的代码。我显示通知的代码如下所示
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
属性,因此代码应堆叠多个通知。
但是,据我观察,多个通知不会叠加。替换了相同的通知(请参见下面的演示中的计数器值增加)。请看下面
可重现的代码库可在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)
有人可以帮助我了解如何获取多个堆叠的通知吗?
谢谢