ServiceWorkerGlobalScope.onnotificationclose

The ServiceWorkerGlobalScope.onnotificationclose property is an event handler called whenever the notificationclose event is dispatched on the ServiceWorkerGlobalScope object, that is 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.

Syntax

ServiceWorkerGlobalScope.onnotificationclose = function(NotificationEvent) { ... };
ServiceWorkerGlobalScope.addEventListener('notificationclose', function(NotificationEvent) { ... });

Example

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

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
onnotificationclose
50
≤79
44
Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
No
34
11.1
50
50
44
34
11.3
5.0

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope/onnotificationclose