files/en-us/web/api/notification/notification/index.md
{{APIRef("Web Notifications")}}{{securecontext_header}} {{AvailableInWorkers}}
The Notification() constructor creates a new {{domxref("Notification")}} object instance, which represents a user notification.
Trying to create a notification inside the {{domxref("ServiceWorkerGlobalScope")}} using the Notification() constructor will throw a TypeError.
Use {{domxref("ServiceWorkerRegistration.showNotification()")}} instead.
You must first get permission before being able to display notifications, using {{domxref("Notification.requestPermission_static", "Notification.requestPermission()")}}. The permission may not be grantable, for example if the page is in private browsing mode.
This constructor throws a {{jsxref("TypeError")}} when called in nearly all mobile browsers and this is unlikely to change, because web pages on mobile devices almost never "run in the background", which is the main use case for notifications. Instead, you need to register a service worker and use {{domxref("ServiceWorkerRegistration.showNotification()")}}. See Chrome issue for more information.
new Notification(title)
new Notification(title, options)
title
options {{optional_inline}}
actions {{optional_inline}}
actions is only supported for persistent notifications fired from a service worker using {{domxref("ServiceWorkerRegistration.showNotification()")}}.badge {{optional_inline}}
body {{optional_inline}}
data {{optional_inline}}
null.dir {{optional_inline}}
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.)icon {{optional_inline}}
image {{optional_inline}}
lang {{optional_inline}}
navigate {{optional_inline}} {{experimental_inline}}
renotify {{optional_inline}}
false, which means they won't be notified.
If true, then tag also must be set.requireInteraction {{optional_inline}}
false.silent {{optional_inline}}
true, the notification is silent; if set to null (the default value), the device's default settings are respected.tag {{optional_inline}}
timestamp {{optional_inline}}
vibrate {{optional_inline}}
silent must not be true.An instance of the {{domxref("Notification")}} object.
actions option is specified and is not empty.silent option is true and the vibrate option is specified.renotify option is true but the tag option is empty.DataCloneError {{domxref("DOMException")}}
data option failed for some reason.Here is a most basic example to only show a notification if permission is already granted. For more complete examples, see the {{domxref("Notification")}} page.
if (Notification.permission === "granted") {
const notification = new Notification("Hi there!");
}
{{Specifications}}
{{Compat}}