notifications

Add-ons using the techniques described in this document are considered a legacy technology in Firefox. Don't use these techniques to develop new add-ons. Use WebExtensions instead. If you maintain an add-on which uses the techniques described here, consider migrating it to use WebExtensions.

From Firefox 53 onwards, no new legacy add-ons will be accepted on addons.mozilla.org (AMO).

From Firefox 57 onwards, WebExtensions will be the only supported extension type, and Firefox will not load other types.

Even before Firefox 57, changes coming up in the Firefox platform will break many legacy extensions. These changes include multiprocess Firefox (e10s), sandboxing, and multiple content processes. Legacy extensions that are affected by these changes should migrate to WebExtensions if they can. See the "Compatibility Milestones" document for more.

A wiki page containing resources, migration paths, office hours, and more, is available to help developers transition to the new technologies.

Stable

Display transient, toaster-style desktop messages to the user.

Usage

This API supports desktop notifications on Windows, OS X using Growl (and Notification Center as of OS X 10.9 Mavericks), and Linux using libnotify.

Here's a typical example. When the message is clicked, a string is logged to the console.

var notifications = require("sdk/notifications");
notifications.notify({
  title: "Jabberwocky",
  text: "'Twas brillig, and the slithy toves",
  data: "did gyre and gimble in the wabe",
  onClick: function (data) {
    console.log(data);
    // console.log(this.data) would produce the same result.
  }
});

This one displays an icon that's stored in the add-on's data directory. See the self module documentation for more information.

var notifications = require("sdk/notifications");
var self = require("sdk/self");
var myIconURL = self.data.url("myIcon.png");
notifications.notify({
  text: "I have an icon!",
  iconURL: myIconURL
});

From Firefox 34, you can use "./myIcon.png" as an alias for self.data.url("myIcon.png"). So you can rewrite the above code like this:

var notifications = require("sdk/notifications");
var myIconURL = "./myIcon.png";
notifications.notify({
  text: "I have an icon!",
  iconURL: myIconURL
});

This module depends on the underlying system's notification service. If the user's system does not support desktop notifications or if its notifications service is not running:

  • if Firefox was started normally, notifications are logged to Firefox's error console
  • if the user launched Firefox from the command line, notifications are logged to the terminal.

Globals

Functions

notify(options)

Displays a transient notification to the user.

Parameters

options : object
Optional options:

Name Type  
title string

A string to display as the message's title.

text string

A string to display as the body of the message.

iconURL string

The URL of an icon to display inside the message. It may be a remote URL, a data URI, or a URL returned by the self module.

onClick function

A function to be called when the user clicks the message. It will be passed the value of data.

data string

A string that will be passed to onClick.

 

Document Tags and Contributors

 Contributors to this page: wbamberg, EvaCatHerder, nishanths, ChrisAntaki
 Last updated by: wbamberg,