ServiceWorkerGlobalScope: notificationclose event

The notificationclose event fires when a user closes a displayed notification spawned by ServiceWorkerRegistration.showNotification().

Notifications created on the main thread or in workers which aren't service workers using the Notification() constructor will instead receive a close event on the Notification object itself.

Note: Trying to create a notification inside the ServiceWorkerGlobalScope using the Notification() constructor will throw an error.

This event is not cancelable and does not bubble.

Syntax

Use the event name in methods like addEventListener(), or set an event handler property.

addEventListener('notificationclose', event => { });

onnotificationclose = event => { };

Event type

An NotificationEvent. Inherits from Event.

Event ExtendableEvent NotificationEvent

Event properties

Inherits properties from its ancestor, Event.

NotificationEvent.notification Read only

Returns a Notification object representing the notification that was clicked to fire the event.

NotificationEvent.action Read only

Returns the string ID of the notification button the user clicked. This value returns an empty string if the user clicked the notification somewhere other than an action button, or the notification does not have a button.

Example

//Inside a service worker.
self.onnotificationclose = function(event) {
  console.log('On notification close: ', event.notification.tag);
};

Specifications

No specification found

No specification data found for api.ServiceWorkerGlobalScope.notificationclose_event.
Check for problems with this page or contribute a missing spec_url to mdn/browser-compat-data. Also make sure the specification is included in w3c/browser-specs.

Browser compatibility

No compatibility data found for api.ServiceWorkerGlobalScope.notificationclose_event.
Check for problems with this page or contribute missing data to mdn/browser-compat-data.