--- title: Notifications API slug: Web/API/Notifications_API tags: - Landing - NeedsTranslation - Notifications - TopicStub - permission - system translation_of: Web/API/Notifications_API ---

{{DefaultAPISidebar("Web Notifications")}}

The Notifications API allows web pages to control the display of system notifications to the end user. These are outside the top-level browsing context viewport, so therefore can be displayed even when the user has switched tabs or moved to a different app. The API is designed to be compatible with existing notification systems, across different platforms.

Concepts and usage

On supported platforms, showing a system notification generally involves two things. First, the user needs to grant the current origin permission to display system notifications, which is generally done when the app or site initialises, using the {{domxref("Notification.requestPermission()")}} method. This will spawn a request dialog, along the following lines:

From here the user can choose to allow notifications from this origin, block notifications from this origin, or not choose at this point. Once a choice has been made, the setting will generally persist for the current session. 

Note: As of Firefox 44, the permissions for Notifications and Push have been merged. If permission is granted for notifications, push will also be enabled.

Next, a new notification is created using the {{domxref("Notification.Notification","Notification()")}} constructor. This must be passed a title argument, and can optionally be passed an options object to specify options, such as text direction, body text, icon to display, notification sound to play, and more.

{{AvailableInWorkers}}

In addition, the Notifications API spec specifies a number of additions to the ServiceWorker API, to allow service workers to fire notifications.

Note: To find out more about using notifications in your own app, read Using the Notifications API.

Notifications interfaces

{{domxref("Notification")}}
Defines a notification object.

Service worker additions

{{domxref("ServiceWorkerRegistration")}}
Includes the {{domxref("ServiceWorkerRegistration.showNotification()")}} and {{domxref("ServiceWorkerRegistration.getNotifications()")}} method, for controlling the display of notifications.
{{domxref("ServiceWorkerGlobalScope")}}
Includes the {{domxref("ServiceWorkerGlobalScope.onnotificationclick")}} handler, for firing custom functions when a notification is clicked.
{{domxref("NotificationEvent")}}
A specific type of event object, based on {{domxref("ExtendableEvent")}}, which represents a notification that has fired.

Specifications

Specification Status Comment
{{SpecName('Web Notifications')}} {{Spec2('Web Notifications')}} Living standard

Browser compatibility

{{Compat("api.Notification")}}

Firefox OS permissions

When using notifications in a Firefox OS app, be sure to add the desktop-notification permission in your manifest file. Notifications can be used at any permission level, hosted or above:

"permissions": {
  "desktop-notification": {}
}

See also