diff --git a/files/en-us/web/api/notification/index.md b/files/en-us/web/api/notification/index.md index 90b08b484e1e310..394b4ef6d4dfd11 100644 --- a/files/en-us/web/api/notification/index.md +++ b/files/en-us/web/api/notification/index.md @@ -84,6 +84,8 @@ _Also inherits methods from its parent interface, {{domxref("EventTarget")}}_. ## Events +_Also inherits events from its parent interface, {{domxref("EventTarget")}}_. + - {{domxref("Notification.click_event", "click")}} - : Fires when the user clicks the notification. - {{domxref("Notification.close_event", "close")}} diff --git a/files/en-us/web/api/notification/notification/index.md b/files/en-us/web/api/notification/notification/index.md index 993808364711900..688c6ddf1573ff0 100644 --- a/files/en-us/web/api/notification/notification/index.md +++ b/files/en-us/web/api/notification/notification/index.md @@ -28,65 +28,80 @@ new Notification(title, options) - : An options object containing any custom settings that you want to apply to the notification. The possible options are: - - `dir` + - `dir` {{optional_inline}} - : The direction in which to display the notification. It defaults to `auto`, which just adopts the browser's language setting behavior, but you can override that behavior by setting values of `ltr` and `rtl` (although most browsers seem to ignore these settings.) - - `lang` + - `lang` {{optional_inline}} - : The notification's language, as specified using a string representing a language tag according to {{RFC(5646, "Tags for Identifying Languages (also known as BCP 47)")}}. - See the Sitepoint [ISO 2 letter language codes](https://www.sitepoint.com/iso-2-letter-language-codes/) page for a simple reference. - - `badge` + See the Sitepoint [ISO 2 letter language codes](https://www.sitepoint.com/iso-2-letter-language-codes/) page for a simple reference. The default is the empty string. + - `badge` {{optional_inline}} - : A string containing the URL of the image used to represent the notification when there isn't enough space to display the notification itself. - - `body` + - `body` {{optional_inline}} - : A string representing the body text of the notification, which is displayed below the title. - - `tag` + The default is the empty string. + - `tag` {{optional_inline}} - : A string representing an identifying tag for the notification. The default is the empty string. - - `icon` + - `icon` {{optional_inline}} - : A string containing the URL of an icon to be displayed in the notification. - - `image` + - `image` {{optional_inline}} - : a string containing the URL of an image to be displayed in the notification. - - `data` + - `data` {{optional_inline}} - : Arbitrary data that you want associated with the notification. This can be of any data type. - - `vibrate` + The default is `null`. + - `vibrate` {{optional_inline}} - : A [vibration pattern](/en-US/docs/Web/API/Vibration_API#vibration_patterns) for the device's vibration hardware to emit with the notification. If specified, `silent` must not be `true`. - - `renotify` + - `timestamp` {{optional_inline}} + - : A number representing the time at which a notification is created or applicable (past, present, or future). + - `renotify` {{optional_inline}} - : A boolean value specifying whether the user should be notified after a new notification replaces an old one. The default is `false`, which means they won't be notified. If `true`, then `tag` also must be set. - - `requireInteraction` + - `requireInteraction` {{optional_inline}} - : Indicates that a notification should remain active until the user clicks or dismisses it, rather than closing automatically. The default value is `false`. - - `actions` + - `actions` {{optional_inline}} - - : An array of actions to display in the notification. Each element in the array is an object with the following members: + - : An array of actions to display in the notification, for which the default is an empty array. Each element in the array can be an object with the following members: - - `action`: A string identifying a user action to be displayed on the notification. - - `title`: A string containing action text to be shown to the user. - - `icon`: A string containing the URL of an icon to display with the action. + - `action` + - : A string identifying a user action to be displayed on the notification. + - `title` + - : A string containing action text to be shown to the user. + - `icon` {{optional_inline}} + - : A string containing the URL of an icon to display with the action. Appropriate responses are built using `event.action` within the {{domxref("ServiceWorkerGlobalScope.notificationclick_event", "notificationclick")}} event. - - `silent` + - `silent` {{optional_inline}} - : A boolean value specifying whether the notification is silent (no sounds or vibrations issued), regardless of the device - settings. The default is `false`, which means it won't be silent. If `true`, then `vibrate` must not be present. + settings. The default is `null`. If `true`, then `vibrate` must not be present. + +### Return value + +An instance of the {{domxref("Notification")}} object. ### Exceptions - {{jsxref("TypeError")}} - - : Thrown if one of the following is true: - - `options.silent` is `true` and `options.vibrate` is specified. - - `options.renotify` is `true` but `options.tag` is empty. + - : Thrown if: + - The constructor is called within the {{domxref("ServiceWorkerGlobalScope")}}. + - The `actions` option is specified and is not empty. + - The `silent` option is `true` and the `vibrate` option is specified. + - The `renotify` option is `true` but the `tag` option is empty. +- `DataCloneError` {{domxref("DOMException")}} + - : Thrown if serializing the `data` option failed for some reason. ## Examples