Skip to content

Commit

Permalink
update parameters & return value & exceptions of Notification constru…
Browse files Browse the repository at this point in the history
…ctor (#31706)
  • Loading branch information
skyclouds2001 authored Jan 13, 2024
1 parent bcb7e55 commit 897b766
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 22 deletions.
2 changes: 2 additions & 0 deletions files/en-us/web/api/notification/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")}}
Expand Down
59 changes: 37 additions & 22 deletions files/en-us/web/api/notification/notification/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 897b766

Please sign in to comment.