MDN will be in maintenance mode on Friday September 22nd, starting at 10 AM Pacific / 5 PM UTC, for about 1 hour.

Add-ons

show

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.

Starting from Firefox 53, no new legacy add-ons will be accepted on addons.mozilla.org (AMO) for desktop Firefox and Firefox for Android.

Starting from Firefox 57, only extensions developed using WebExtensions APIs will be supported on Desktop Firefox and Firefox for Android.

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 use WebExtensions APIs if they can. See the "Compatibility Milestones" document for more information.

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

The NativeWindow object is only available to privileged code running on Firefox for Android, and is intended for use by Firefox for Android add-ons.

NativeWindow.toast will be deprecated in Firefox 45.

New code should use Snackbars.jsm to display notifications. To maintain backward compatibility NativeWindow.toast will still work, by delegating calls to Snackbars.jsm.

Summary

NativeWindow.toast.show() displays a toast notification on Firefox for Android.

A toast notification is a message that appears on the screen for a set interval and then fades away. It does not accept user input.

Syntax

NativeWindow.toast.show(message, duration);

message
The message displayed by the toast.
duration

How long the toast should appear before fading away. This can take one of two values, short or long.

options
A set of options for the toast. See the "Supported options" section below

Supported options

button

Attribute Description
label The label for the button. This text won't be formatted like a link. Keep it a short single word to make it feel clickable.
icon An icon for the button. This can be a base64 encded url, a chrome/resource url, or a drawable url.
callback A callback that is called when you tap the icon. The function isn't passed any arguments.

Example

In the example below, an add-on adds a menu item that displays a toast:

function showToast(window) {
  window.NativeWindow.toast.show("Showing you a toast", "short", {
    button: {
      label: "Undo",
      icon: "drawable://alert_app",
      callback: function() {
        Services.prompts.alert("You clicked the button");
      }
    }
  });
}

function addMenuItem(window) {
  menuID = window.NativeWindow.menu.add("Show Toast", null, function() {
    showToast(window);   
  });
}

function removeMenuItem(window) {
  window.NativeWindow.menu.remove(menuID);
}

See Also

Document Tags and Contributors

 Contributors to this page: rebloor, andrewtruongmoz, wbamberg, dkocho4, leibovic, wesj, justinpotts
 Last updated by: rebloor,