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

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.

The NativeWindow object enables Firefox for Android add-ons to create user interface components.

NativeWindow is available as a property of the chrome window object. For example, if you use this template for initializing your extension, you can access it from the window argument passed into loadIntoWindow():

function loadIntoWindow(window) {
  window.NativeWindow.toast.show("I'm starting!", "short");
}

You can also access the chrome window using nsIWindowMediator:

let window = Services.wm.getMostRecentWindow("navigator:browser");
window.NativeWindow.toast.show("Here's another toast message!", "short");

Obtain NativeWindow object with add-on SDK:

// Obtain commonly used services : Services.jsm
// https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Services.jsm
const { Services } = require("resource://gre/modules/Services.jsm");

function getNativeWindow() {

	let window = Services.wm.getMostRecentWindow("navigator:browser");
	return window.NativeWindow;

}

The NativeWindow object enables developers of Firefox for Android add-ons to create UI components.

It supports the following components:

Add items to the main menu in Firefox for Android. See the menu API documentation.

/*
label: menu label
icon: file:// or data: URI for an icon
callback: JS function called when menu is tapped
returns a menu ID that can be used to remove the menu
*/
let id = NativeWindow.menu.add(label, icon, callback);
NativeWindow.menu.remove(id);

doorhanger

Show and hide doorhanger notifications. See the doorhanger API documentation.

/*
message: displayed text
value: string based tag
buttons: array of JS objects used to create buttons in the notification
tabId: tab associated with this notification
options: JS object that has 'persistence' and 'timeout' options
*/
NativeWindow.doorhanger.show(message, value, buttons, tabId, options);
NativeWindow.doorhanger.hide(value, tabId);

contextmenus

Add and remove context menu items. See the contextmenus API documentation.

/*
label: menu label
selector: JS object that has a 'matches(element)' function. Used to show the menu.
callback: JS function called when menu is tapped
returns a menu ID that can be used to remove the menu
*/
let id = NativeWindow.contextmenu.add(label, selector, callback);
NativeWindow.contextmenu.remove(id);

toast

Show Android toast notifications. See the toast API documentation.

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.

/*
message: displayed text
duration: "short" or "long"; Used for alert timeout
*/
NativeWindow.toast.show(message, duration);

 

pageactions

Add and remove pageactions, i.e. clickable indicators in the URL bar. See the pageactions API documentation.

NativeWindow.pageactions was deprecated in Firefox 34. Use the new PageActions.jsm instead.

/*
title: Pageaction title
icon: Icon image for the pageaction
clickCallback: Callback called when pageaction is clicked
longClickCallback: Callback called when pageaction is long pressed
*/
let options = {
  title: "title",
  icon: "chrome://myaddon/skin/image.png",
  clickCallback: function() { },
  longClickCallback: function() { } (optional)
};

//Adding pageaction
let id = NativeWindow.pageactions.add(options);

//Remove pageaction
NativeWindow.pageactions.remove(id);

Document Tags and Contributors

 Last updated by: rebloor,