We're looking for a person or people to help audit MDN to find places we could speed up. Is this you or someone you know? Check out the RFP: https://mzl.la/2IHcMiE

Extension FAQ

This is quick set of answers to the most common issues with extension development. They are currently written with mostly Firefox in mind, but most if not all should easily translate to SeaMonkey, Thunderbird or any of the other applications. For Thunderbird, you may also find the extension HowTo or FAQ pages helpful.

If you're looking for a place to get started, try our tutorial, Building an Extension or MozillaZine's Getting started tutorial. Use the Extension Wizard to generate a template to start with.

Be sure to set the development preferences.


You should set development preferences before attempting to debug your extension.

The Venkman JavaScript debugger may be useful in complex cases, remember to turn off the "Debug -> Exclude Browser Files" option when working on extension code.

How can I see errors in my code?

After you set the preference javascript.options.showInConsole to true, the errors will be reported to the Error Console. By logging all JavaScript errors into the console, it becomes much easier to track down the bugs in your code.

How can I display what my extension is doing?

You can use alert(), dump(), Components.utils.reportError(), or the console service to display variable data and debugging text. You can also try to use the Venkman JavaScript Debugger add-on.

Why doesn't my script run properly?

If your script doesn't function as expected, the first thing you should do is check the Error Console (see above).

One common mistake is trying to access the DOM of a window before it is fully loaded. This happens if you place the initialization code at the top level of your script (i.e. outside of any functions). The fix is to use a load event listener to delay your code until the window has finished loading:

function exampleBrowserStartup(event)
  // place your startup code here
window.addEventListener("load", exampleBrowserStartup, false);

If you see an error similar to "JavaScript error: chrome://myextension/content/overlay.js, line 47: missing ; before statement", you're likely using JavaScript 1.7 features or syntax when your extension is being run under an earlier version.  To force your code to be run under Javascript 1.7, you need to write:

<script type="application/x-javascript" src="overlay.js;version=1.7"/>

Accessing the document of a webpage doesn't work

To get the document of the current webpage from a browser.xul overlay, you should use content.document, instead of just document which is the document of the browser's window itself. See Working with windows in chrome code for details.

Also, by default XPCNativeWrapper prevents you from accessing script-defined objects in the web page and doing some other things.

I cannot initiate an XMLHttpRequest from my extension

If you try and get/send information with an extension through an XMLHttpRequest, odds are you will need to go cross domain. Normally this might be an issue, but as long as you execute the request from a chrome window, you will be inside the security scope, and it will be allowed.

You need to make sure that you are initializing the cross domain XMLHttpRequest from JavaScript code that is referencing a XUL window. If you try and execute the request in relation to the browser content document, as opposed to the "document" of the XUL window, you will receive a Permission Denied error.

I get an XML parsing error, but the file looks fine!

A common source of parsing errors (some <font color="red">red text</font> with a <font color="red">-------------^</font> underneath) is an & or a < character in your script or an attribute value, which has special meaning in XML. For example:

<button oncommand="window.open('http://example.com/q?param1=value&param2=val2')"/>


<script>function lesser(a,b) { return a < b ? a : b; }</script>

The problem can be solved in one of the following ways:

  1. Replace the character with its non XML conflicting representation (Ex: "&" -> "&amp;", "<" -> "&lt;")
  2. In case it's a text node, such as script, place CDATA tags around it:
       function lesser(a,b) {
         return a < b ? a : b;
  3. Put your script in a separate file and include it, e.g.:
    <script type="application/javascript" src="our.js"/>

Example code

The easiest way to find out what code you need to use in order to do something useful is to find an extension (or part of Mozilla itself) that does it and look at its code. (The XPI and JAR files use the ZIP format.)

There is also some documentation. See the list of extension-related articles on MDC, Code snippets, and Example code page on MozillaZine.

Where can I get more help?

Please see Extensions:Other Resources and Extensions:Community.

Before asking for help, be sure to set the debugging prefs and check the Error Console for related messages. Also, don't forget to do at least a simple web search before asking. And read this FAQ!

Document Tags and Contributors

 Last updated by: Jesse,