MDN wants to learn about developers like you: https://qsurvey.mozilla.com/s3/d6d7ff2e2f9c

Add-ons

content/mod

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.

Experimental

Provides functions to modify a page content.

Globals

Constructors

Functions

attachTo(modification, window)

Function applies given modification to a given window.

For example, the following code applies a style to a content window, adding a border to all divs in page:

var attachTo = require("sdk/content/mod").attachTo;
var Style = require("sdk/stylesheet/style").Style;

var style = Style({
  source: "div { border: 4px solid gray }"
});

// assuming window points to the content page we want to modify
attachTo(style, window);
Parameters

modification : object
The modification we want to apply to the target.

window : nsIDOMWindow
The window to be modified.

detachFrom(modification, window)

Function removes attached modification from a given window. If window is not specified, modification is removed from all the windows it's being attached to.

For example, the following code applies and removes a style to a content window, adding a border to all divs in page:

var { attachTo, detachFrom } = require("sdk/content/mod");
var Style = require("sdk/stylesheet/style").Style;

var style = Style({
  source: "div { border: 4px solid gray }"
});

// assuming window points to the content page we want to modify
attachTo(style, window);
// ...
detachFrom(style, window);
Parameters

modification : object
The modification we want to remove from the target

window : nsIDOMWindow
The window to be modified. If window is not provided modification is removed from all targets it's being attached to.

getTargetWindow(target)

Function takes target, value representing content (page) and returns nsIDOMWindow for that content. If target does not represents valid content null is returned. For example target can be a content window itself in which case it's will be returned back.

Parameters

target : object
The object for which we want to obtain the window represented or contained. If a nsIDOMWindow is given, it works as an identify function, returns target itself.

Returns

nsIDOMWindow|null : The window represented or contained by the target, if any. Returns null otherwise.

attach(modification, target)

Function applies given modification to a given target representing a content to be modified.

Parameters

modification : object
The modification we want to apply to the target

target : object
Target is a value that representing content to be modified. It is valid only when getTargetWindow(target) returns nsIDOMWindow of content it represents.

detach(modification, target)

Function removes attached modification. If target is specified modification is removed from that target only, otherwise modification is removed from all the targets it's being attached to.

Parameters

modification : object
The modification we want to remove from the target

target : object
Target is a value that representing content to be modified. It is valid only when getTargetWindow(target) returns nsIDOMWindow of content it represents. If target is not provided modification is removed from all targets it's being attached to.

Document Tags and Contributors

 Contributors to this page: wbamberg
 Last updated by: wbamberg,