NotificationEvent: NotificationEvent() constructor
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2023.
Note: This feature is only available in Service Workers.
The NotificationEvent() constructor creates a new NotificationEvent object.
Syntax
js
new NotificationEvent(type, options)
Parameters
type-
A string with the name of the event. It is case-sensitive and browsers set it to
notificationclickornotificationclose. options-
An object that, in addition of the properties defined in
ExtendableEvent(), can have the following properties:notification-
A
Notificationobject to be used as the notification the event is dispatched on. actionOptional-
An action associated with the notification. It defaults to
"".
Return value
A new NotificationEvent() object.
Examples
js
const n = new Notification("Hello");
const myNotificationEvent = new NotificationEvent(type, { notification: n });
Specifications
| Specification |
|---|
| Notifications API> # dom-notificationevent-notificationevent> |
Browser compatibility
Loading…