This tutorial will take you through the steps required to build a very basic extension - one which adds a status bar panel to the Firefox browser containing the text "Hello, World!"
Note This tutorial is about building extensions for Firefox 1.5. Other tutorials exist for building extensions for earlier versions of Firefox.
Setting up the Development Environment
Extensions are packaged and distributed in ZIP files with the <tt>xpi</tt> (pronounced “zippy”) extension. The layout of content within the XPI file is like so:
extension.xpi: /chrome/chromeFiles/ /components/ /defaults/ /defaults/preferences/ chrome.manifest install.rdf
Because of this, it is easiest if we lay out our source files in a similar fashion, unless you want to write some sort of Makefile or shell script to package and zip all of your files. Even if you are prepared to do that, testing is much simpler if you lay out your files like this because of a feature of Firefox 1.5's Addon System.
So let's get started. Create a folder for your extension somewhere on your hard disk, e.g. <tt>c:\extensions\myExtension\</tt>. Inside this folder create another folder called <tt>chrome</tt>, inside the <tt>chrome</tt> folder create a folder called <tt>chromeFiles</tt> and inside the <tt>chromeFiles</tt> folder create a folder called <tt>content</tt>.
Inside the root of your extension folder, alongside the <tt>chrome</tt> folder create two new empty text files, one called <tt>chrome.manifest</tt> and the other called <tt>install.rdf</tt>.
Create the Install Manifest
Extending the Browser with XUL
To extend the browser, we modify parts of the browser UI by adding or modifying widgets. We add widgets by inserting new XUL DOM elements into the browser window, and modify them by using script and attaching event handlers.
The browser is implemented in a XUL file called <tt>browser.xul</tt>. In browser.xul we can find the status bar, which looks something like this:
<statusbar id="status-bar"> ... <statusbarpanel>s ... </statusbar>
<tt><statusbar id="status-bar"< is a "merge point" for a XUL Overlay. </tt>
XUL Overlays are a way of attaching other UI widgets to a XUL document at run time. A XUL Overlay is a .xul file that specifies XUL fragments to insert at specific merge points within a "master" document. These fragments can specify widgets to be insreted, removed, or modified.
<?xml version="1.0"> <overlay id="sample" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> <statusbar id="status-bar"> <statusbarpanel id="my-panel" label="Hello, World"/> </statusbar> </overlay>
Create a Chrome Manifest
For more information on Chrome Manifests and the properties they support, see the Chrome Manifest Reference.
More on XUL Overlays
Creating New User Interface Components
Understanding the Browser
Extension Versioning and Compatibility
Update and Compatibility
=== References ===