Path: blob/main/files/en-us/mozilla/add-ons/webextensions/api/notifications/create/index.md
6556 views
------{{AddonSidebar()}}
Creates and displays a notification.
Pass a {{WebExtAPIRef("notifications.NotificationOptions")}} to define the notification's content and behavior.
You can optionally provide an ID for the notification. If you omit the ID, an ID will be generated. You can use the ID to {{WebExtAPIRef("notifications.update()", "update")}} or {{WebExtAPIRef("notifications.clear()", "clear")}} the notification.
This is an asynchronous function that returns a Promise.
Warning: If you call
notifications.create()more than once in rapid succession, Firefox may end up not displaying any notification at all.
Syntax
Parameters
id{{optional_inline}}:
string. This is used to refer to this notification in {{WebExtAPIRef("notifications.update()")}}, {{WebExtAPIRef("notifications.clear()")}}, and event listeners. If you omit this argument or pass an empty string, then a new ID will be generated for this notification. If the ID you provide matches the ID of an existing notification from this extension, then the other notification will be cleared.
options: {{WebExtAPIRef('notifications.NotificationOptions')}}. Defines the notification's content and behavior.
Return value
A Promise that will be fulfilled when the notification is created and the display process has been started, which is before the notification is actually displayed to the user. It is fulfilled with a string representing the notification's ID.
Examples
This example displays a notification periodically, using {{WebExtAPIRef("alarms", "alarm")}}. Clicking the browser action dismisses the notification. You need the "alarms" permission to create alarms (as well as the "notifications" permission to create notifications).
{{WebExtExamples}}
Browser compatibility
{{Compat}}
Note: This API is based on Chromium's
chrome.notificationsAPI.