Reddit Example


Support for extensions using XUL/XPCOM or the Add-on SDK was removed in Firefox 57, released November 2017. As there is no supported version of Firefox enabling these technologies, this page will be removed by December 2020.

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 (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.


This example uses the action button API, which is only available from Firefox 29 onwards.

This example add-on creates a panel containing the mobile version of Reddit. When the user clicks on the title of a story in the panel, the add-on opens the linked story in a new tab in the main browser window.

To accomplish this the add-on needs to run a content script in the context of the Reddit page which intercepts mouse clicks on each title link and fetches the link's target URL. The content script then needs to send the URL to the add-on script.

This is the complete add-on script:

var data = require("sdk/self").data;

var button = require("sdk/ui/button/action").ActionButton({
  id: "reddit-panel",
  label: "Reddit Panel",
  icon: "./icon-16.png",
  onClick: function() {;

var reddit_panel = require("sdk/panel").Panel({
  width: 240,
  height: 320,
  contentURL: "",
  contentScriptFile: [data.url("jquery-2.1.0.min.js"),

reddit_panel.port.on("click", function(url) {

This code supplies two content scripts to the panel's constructor in the contentScriptFile option: the jQuery library and the script that intercepts link clicks.

Finally, it registers a listener to the user-defined click event which in turn passes the URL into the open function of the tabs module.

This is the panel.js content script that intercepts link clicks:

$(window).click(function (event) {
  var t =;

  // Don't intercept the click if it isn't on a link.
  if (t.nodeName != "A")

  // Don't intercept the click if it was on one of the links in the header
  // or next/previous footer, since those links should load in the panel itself.
  if ($(t).parents('#header').length || $(t).parents('.nextprev').length)

  // Intercept the click, passing it to the addon, which will load it in a tab.
  self.port.emit('click', t.toString());

This script uses jQuery to interact with the DOM of the page and the self.port.emit function to pass URLs back to the add-on script.

To run this example you'll also have to have an icon file named "icon-16.png" saved in your add-on's "data" directory. You could download this icon: .