notifications

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,
Hide Sidebar