ServiceWorkerGlobalScope: notificationclose event
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.
Note: This feature is only available inService Workers.
Thenotificationclose event of theServiceWorkerGlobalScope interface fires when a user closes a displayed notification spawned byServiceWorkerRegistration.showNotification().
Notifications created on the main thread or in workers which aren't service workersusing theNotification() constructor willinstead receive aclose event on theNotification objectitself.
This event is not cancelable and does not bubble.
In this article
Syntax
Use the event name in methods likeaddEventListener(), or set an event handler property.
addEventListener("notificationclose", (event) => { })onnotificationclose = (event) => { }Event type
ANotificationEvent. Inherits fromExtendableEvent andEvent.
Event properties
Inherits properties from its ancestor,ExtendableEvent andEvent.
NotificationEvent.notificationRead onlyReturns a
Notificationobject representing the notification that was clicked to fire the event.NotificationEvent.actionRead onlyReturns 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 = (event) => { console.log("On notification close: ", event.notification.tag);};Specifications
| Specification |
|---|
| Notifications API> # dom-serviceworkerglobalscope-onnotificationclose> |