ServiceWorkerGlobalScope: notificationclose イベント

notificationclose イベントは、 ServiceWorkerRegistration.showNotification() によって生成された表示中の通知をユーザーが閉じたときに発生します。

メインスレッドや、サービスワーカー以外のワーカーが Notification() コンストラクターを使用して生成した通知では、Notification オブジェクト自身が close イベントを受け取ります。

メモ: ServiceWorkerGlobalScope 内で Notification() コンストラクターを使用して通知を生成しようとすると、エラーが発行されます。

このイベントはキャンセル不可で、バブリングしません。

構文

このイベント名を addEventListener() 等のメソッドで使用するか、イベントハンドラープロパティを設定するかしてください。

js
addEventListener("notificationclose", (event) => {});

onnotificationclose = (event) => {};

イベント型

イベントプロパティ

親である Event からプロパティを継承しています

NotificationEvent.notification 読取専用

クリックされイベントが発行された通知を表す Notification オブジェクトを返します。

NotificationEvent.action 読取専用

ユーザーがクリックした通知ボタンの文字列 ID を返します。この値は、ユーザーがアクションボタン以外のどこかで通知をクリックした場合、またはその通知にボタンがなかった場合、空文字列を返します。

js
// サービスワーカーの内部で
self.onnotificationclose = (event) => {
  console.log("On notification close: ", event.notification.tag);
};

仕様書

Specification
Notifications API Standard
# dom-serviceworkerglobalscope-onnotificationclose

ブラウザーの互換性

BCD tables only load in the browser