ServiceWorkerRegistration: getNotifications() 方法
注意:此功能在 Web Workers 中可用。
getNotifications() 方法是 ServiceWorkerRegistration 介面的一部分,它返回當前源通過當前 Service Worker 註冊建立的通知列表,順序與建立時相同。不同的源可以擁有多個活躍但作用域不同的 Service Worker 註冊。由同一源上的一個 Service Worker 建立的通知,對該同一源上的其他活躍 Service Worker 將不可用。
語法
js
getNotifications()
getNotifications(options)
引數
options可選-
一個包含用於過濾返回通知的選項的物件。可用選項為:
tag可選-
一個表示通知標籤的字串。如果指定,則只返回具有此標籤的通知。
返回值
一個 Promise,它解析為一個 Notification 物件列表。
示例
js
navigator.serviceWorker.register("sw.js");
const options = { tag: "user_alerts" };
navigator.serviceWorker.ready.then((registration) => {
registration.getNotifications(options).then((notifications) => {
// do something with your notifications
});
});
規範
| 規範 |
|---|
| Notifications API # dom-serviceworkerregistration-getnotifications |
瀏覽器相容性
載入中…