Notification Class

A notification shown to the user (https://notifications.spec.whatwg.org/#notification), by BrowsingContextOptions.ShowNotification once the notifications permission is granted. The host calls Notification.Click when the user activates the notification and Notification.Dismiss when the user closes it.

public sealed class Notification : EventTarget

Remarks

The error event is fired when the permission is not granted. A notification whose tag is not empty replaces the notification of the same origin with the same tag (its close event is fired). The persistent notifications of the service workers (showNotification()) and the actions are not supported.

See also

Inheritance
EventTarget Notification

Constructors

NameDescription
Notification(string, NotificationOptions?)Creates a notification and shows it (https://notifications.spec.whatwg.org/#dom-notification-notification): the show event is fired once it is shown, or the error event when the permission is not granted.

Notification(string, NotificationOptions?)

Notification.cs

Creates a notification and shows it (https://notifications.spec.whatwg.org/#dom-notification-notification): the show event is fired once it is shown, or the error event when the permission is not granted.

public Notification(string title, NotificationOptions? options = null)

Parameters

title string
The title of the notification.
options NotificationOptions?
The options of the notification.

Exceptions

TypeErrorException
The constructor is called in a service worker, the options have actions, or renotify is set without tag.

See also

Properties

NameDescription
ActionsGets the actions of the notification (https://notifications.spec.whatwg.org/#dom-notification-actions): always empty.
BadgeGets the absolute URL of the badge, or the empty string.
BodyGets the body of the notification.
DataGets a deserialization of the data of the notification (the same value each time).
DirGets the direction of the text.
IconGets the absolute URL of the icon, or the empty string.
ImageGets the absolute URL of the image, or the empty string.
IsShownGets whether the notification is shown: it is in the list of notifications of the browsing contexts.
LangGets the language of the text.
MaxActionsGets the maximum number of actions of a notification (https://notifications.spec.whatwg.org/#dom-notification-maxactions): 0, the actions are not supported.
NavigateGets the absolute URL to navigate to when the notification is activated, or the empty string.
OnClickGets or sets the event handler of the click event.
OnCloseGets or sets the event handler of the close event.
OnErrorGets or sets the event handler of the error event.
OnShowGets or sets the event handler of the show event.
PermissionGets whether the user allows the origin of the current global object to show notifications (https://notifications.spec.whatwg.org/#dom-notification-permission), read from the permission store (BrowsingContextOptions.Permissions).
RenotifyGets whether the user is alerted again when the notification replaces another one.
RequireInteractionGets whether the notification stays until the user activates or closes it.
SilentGets whether the notification is silent, or null for the default of the device.
TagGets the tag of the notification.
TimestampGets the time of the notification, in milliseconds since the Unix epoch.
TitleGets the title of the notification.

Gets the actions of the notification (https://notifications.spec.whatwg.org/#dom-notification-actions): always empty.

public IReadOnlyList<NotificationAction> Actions { get; }

Gets the absolute URL of the badge, or the empty string.

public string Badge { get; }

Gets the body of the notification.

public string Body { get; }

Gets a deserialization of the data of the notification (the same value each time).

public object? Data { get; }

Gets the direction of the text.

public NotificationDirection Dir { get; }

Gets the absolute URL of the icon, or the empty string.

public string Icon { get; }

Gets the absolute URL of the image, or the empty string.

public string Image { get; }

Gets whether the notification is shown: it is in the list of notifications of the browsing contexts.

public bool IsShown { get; }

Property value

bool

Gets the language of the text.

public string Lang { get; }

MaxActions

Notification.cs

Gets the maximum number of actions of a notification (https://notifications.spec.whatwg.org/#dom-notification-maxactions): 0, the actions are not supported.

public static uint MaxActions { get; }

Gets or sets the event handler of the click event.

public Action<Event>? OnClick { get; set; }

Gets or sets the event handler of the close event.

public Action<Event>? OnClose { get; set; }

Gets or sets the event handler of the error event.

public Action<Event>? OnError { get; set; }

Gets or sets the event handler of the show event.

public Action<Event>? OnShow { get; set; }

Permission

Notification.cs

Gets whether the user allows the origin of the current global object to show notifications (https://notifications.spec.whatwg.org/#dom-notification-permission), read from the permission store (BrowsingContextOptions.Permissions).

public static NotificationPermission Permission { get; }

Gets whether the user is alerted again when the notification replaces another one.

public bool Renotify { get; }

RequireInteraction

Notification.cs

Gets whether the notification stays until the user activates or closes it.

public bool RequireInteraction { get; }

Gets whether the notification is silent, or null for the default of the device.

public bool? Silent { get; }

Gets the tag of the notification.

public string Tag { get; }

Gets the time of the notification, in milliseconds since the Unix epoch.

public ulong Timestamp { get; }

Gets the title of the notification.

public string Title { get; }

Methods

NameDescription
Click()Activates the notification, as when the user clicks it (https://notifications.spec.whatwg.org/#activating-a-notification): fires its click event, and focuses its window unless the event is canceled. It must be called on the thread of the event loop of the browsing context.
Close()Closes the notification (https://notifications.spec.whatwg.org/#dom-notification-close), and fires its close event.
Dismiss()Closes the notification, as when the user dismisses it (https://notifications.spec.whatwg.org/#closing-a-notification): fires its close event. BrowsingContextOptions.CloseNotification is not called. It must be called on the thread of the event loop of the browsing context.
RequestPermission(NotificationPermissionCallback?)Asks the user to allow the origin to show notifications (https://notifications.spec.whatwg.org/#dom-notification-requestpermission), with BrowsingContextOptions.RequestPermission, unless the permission is already granted or denied.

Activates the notification, as when the user clicks it (https://notifications.spec.whatwg.org/#activating-a-notification): fires its click event, and focuses its window unless the event is canceled. It must be called on the thread of the event loop of the browsing context.

public void Click()

Closes the notification (https://notifications.spec.whatwg.org/#dom-notification-close), and fires its close event.

public void Close()

Closes the notification, as when the user dismisses it (https://notifications.spec.whatwg.org/#closing-a-notification): fires its close event. BrowsingContextOptions.CloseNotification is not called. It must be called on the thread of the event loop of the browsing context.

public void Dismiss()

RequestPermission(NotificationPermissionCallback?)

Notification.cs

Asks the user to allow the origin to show notifications (https://notifications.spec.whatwg.org/#dom-notification-requestpermission), with BrowsingContextOptions.RequestPermission, unless the permission is already granted or denied.

public static Task<NotificationPermission> RequestPermission(NotificationPermissionCallback? deprecatedCallback = null)

Parameters

deprecatedCallback NotificationPermissionCallback?
A callback invoked with the permission, before the task completes.

Returns

Task<NotificationPermission>

See also