Your First Firefox Extension
 
SEARCH: webmonkey  the web

 
XML
-------------------------
Print
this article for free. 
-------------------------

Pages:
1  Your First Firefox Extension
2 Who's Got the Button?

Your First Firefox Extension
by Paul Adams 21 June 2006

Paul Adams [an error occurred while processing this directive]is Webmonkey's resident acronympho, covering the likes of PHP, DNS, and SOAP with startling aplomb.

Page 1

Firefox, the fun open-source browser that some ten percent of the web uses, has a secret.

No, not about:mozilla — that's old news. Firefox's secret is the same as Jessica Simpson's: its effortless, glamorous style is the result of — shhh — extensions!

Yes, when you use Firefox's coolest features, like All-In-One Sidebar or MeasureIt, you're actually looking at glossy, beautiful extensions. Firefox's extensions add specific functions, things the creators never intended, neatly integrated into the browser. The range of possibilities is boundless — making an extension is more or less like building a new application to do whatever you want, within the confines of Firefox (or Mozilla. In this article whenever I say "Firefox," you can echo "or Mozilla" to yourself in your head if you're a Mozilla fan.)

Today let's take a look at how one goes about creating these magical extensions. The active ingredient is XUL, a markup language (the eXtensible [or "XML-Based"] User-interface Language, to be precise) that describes things like toolbars, menus, keyboard shortcuts. It's what Firefox uses internally, in fact, to handle its own UI (what the developer types call "chrome"). XUL will provide the interface. JavaScript handles the functionality.

XUUUUL

If you've ever worked with XML, you're hired! I mean, sorry — if you've ever worked with XML, then XUL will look familiar. Every XUL script starts with a namespace declaration, and has its content inside tags like <tooltip> and <progressmeter>. Firefox's XUL parser sits right next to its parsers for things like HTML and JavaScript, and they work along similar lines. If you need to know about nuts and bolts, you can check out XULPlanet and its exhaustive minute-by-minute coverage. Mozilla.org has a lot of info too.

While you're doing that, the rest of us will plunge right in. An extension consists of a number of components, all keenly synchronized. Here's a summary of extension anatomy. If you unzip an XPI file, which is the format extensions come in, and which is really just a specialized ZIP archive, you'll see a few standard pieces. Some extensions are large and multifaceted, but they all contain a few key elements. Most crucially, there's a file called install.rdf and a directory called chrome, which contains a JAR file. There may also be optional directories of stuff like components, defaults, and plugins. As it happens, that JAR is also a ZIP file under another name (sorry if you know all this already), and when we peer inside it in turn, we find (possibly among other things) the XUL file that does all the work.

So, to make our extension, we need to create each one of those files. Before you groan, though, install this extension handily designed for the purpose. The extension requires Firefox or Mozilla to run — if you're trying to make a Firefox extension but all you have installed is IE, maybe you should just print out this article and go read it in the park.

next page»