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
# dom-serviceworkerregistration-getnotifications

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
getNotifications

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.