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

Add-ons

View Source for XUL Applications

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.

Importing gViewSourceUtils

XUL applications wanting to show the source code for documents should import the viewSourceUtils.js script instead of attempting to open the viewSource.xul window themselves:

<script type="application/javascript" src="chrome://global/content/viewSourceUtils.js"/>

viewSourceUtils.js exposes a gViewSourceUtils global into the scope of the window that imports that script.

Method overview

gViewSourceUtils exposes several methods, but the only one you should be using directly is the viewSource method. The rest of those methods should be considered private, and might become inaccessible in the future.

void viewSource(aObject);

Methods

viewSource

Opens a viewer to the source code for some document or URI.

Parameters

The viewSource method takes an Object as its first and only parameter. The Object can include the following properties:

URL (required)
A string URL for the document to view the source of.
browser (optional)
The browser containing the document that we would like to view the source of. This is optional if outerWindowID is not passed.
outerWindowID (optional)
The outerWindowID of the content window containing the document that we want to view the source of. Pass this if you want to attempt to load the document source out of the network cache.
lineNumber (optional)
The line number to focus on once the source has loaded.

Deprecated API

This API is likely to go away in the future, and should no longer be used.

 The viewSource method will also accept the following arguments in place of the Object:

aURL
A string URL for the document to view the source of.
aPageDescriptor (optional)
A "descriptor" that allows the source to be retrieved from the network cache. This is usually gotten from the nsIWebPageDescriptor interface via currentDescriptor.
aDocument (optional)
The content document that we're attempting to load the source from.
aLineNumber (optional)
The line number to focus on once the source has loaded.

Document Tags and Contributors

 Contributors to this page: bunnybooboo, rolfedh, mconley
 Last updated by: bunnybooboo,