Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

Notifications

Notifications allow you to communicate information about your extension or its content using the underlying operating system's notification service.

Example notification on macOS, located below the system clock, with a bold title reading "Click notification" followed by regular text reading "You clicked https://developer.mozilla.org/en-US/docs/MDN". The notification has the Firefox Nightly logo on the left side, and a link icon on the right.

Notifications can include a call to action for the user, and your add-on can listen for the user clicking the notification or the notification closing.

Specifying notifications

You manage notifications programmatically, using thenotifications API. To use this API you must request thenotifications permission in your manifest.json:

json
"permissions": ["notifications"]

You then usenotifications.create to create your notifications, as in this example fromnotify-link-clicks-i18n:

js
const title = browser.i18n.getMessage("notificationTitle");const content = browser.i18n.getMessage("notificationContent", message.url);browser.notifications.create({  type: "basic",  iconUrl: browser.extension.getURL("icons/link-48.png"),  title,  message: content,});

This code creates a notification with an icon, title, and message.

If the notification includes a call to action, you can listen for the user clicking the notification to call the function to handle the action:

js
browser.notifications.onClicked.addListener(handleClick);

If you are issuing calls to action through notifications, you will also want to define the optional notificationid, so you can figure out which call to action the user has selected.

Icons

For details on how to create icons to use with your notification, seeIconography in theAcorn Design System documentation.

Examples

Thewebextensions-examples repository on GitHub includes thenotify-link-clicks-i18n example which implements notifications.

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp