ServiceWorkerRegistration.getNotifications()
getNotifications() は ServiceWorkerRegistration インターフェイスのメソッドで、現在のサービスワーカー登録を介して現在のオリジンから作成された順序で通知のリストを返します。オリジンには、アクティブではあるがスコープが異なるサービスワーカー登録が多数あります。 同じオリジンの 1 つのサービスワーカーによって作成された通知は、同じオリジンの他のアクティブなサービスワーカーでは利用できません。
構文
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) => {
// notifications で何かをします
});
});
仕様書
| Specification |
|---|
| Notifications API Standard # dom-serviceworkerregistration-getnotifications |
ブラウザーの互換性
BCD tables only load in the browser