ServiceWorkerGlobalScope: notificationclose event
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Want more browser support for this feature? Tell us why.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Note: This feature is only available in Service Workers.
The notificationclose event of the ServiceWorkerGlobalScope interface 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.
This event is not cancelable and does not bubble.
Syntax
Use the event name in addEventListener():
addEventListener("notificationclose", (event) => { })
Alternatively, assign to the event handler property of the interface:
onnotificationclose = (event) => { }
Event type
A NotificationEvent. Inherits from ExtendableEvent and Event.
Example
// Inside a service worker.
self.onnotificationclose = (event) => {
console.log("On notification close: ", event.notification.tag);
};
Specifications
| Specification |
|---|
| Notifications API> # dom-serviceworkerglobalscope-onnotificationclose> |