このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

ServiceWorkerRegistration.getNotifications()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2023年3月⁩.

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

ブラウザーの互換性