What I Learned While Developing a Firefox Extension (Add-on)

Sun, May 17, 2009

Tech Tips

I recently developed my first Firefox extension: Social Network User Mapper. Here is a brain dump / postmortem of what I learned.

1) All Add-ons are Open Source.
At least the javascript and xul part are. This is extremely helpful when you are starting out. Find an extension that works the way you want yours to and find out how it works. You should adhere to the author’s license, however most are liberally licensed and free to reuse.

2) You Can Make Ajax Calls without a Proxy
There are a variety of ways to do this. The following is the easiest way I found to do it in my case. I utilized a third party script. In three lines I was able to make a call to a REST xml web service (including a call back function). It returns a JSON object of the returned XML. If you need more features, you could try mootools.

3) XUL has a Reference and Tutorial Online
Some more examples would be good but it is complete. Here is the reference and tutorial.

4) Some Hello World Examples are Available
It is good to start out with a hello world example if you are new to extension development (but have development experience). I liked this one. Getting through this sample will give you good overview and test how motivated you are to make you own extension. Here is a newer but less complete one and an older one.

5) Debugging Extensions
First I would follow the steps in the article to set up your development environment. I used a combination of the Error Console that comes with Firefox and the Venkman debugger. There is also the Firebug debugger that is actually better (imho) but I stuck with later combination and it worked fine. Some additional tips: You can add the “debugger;” anywhere in your code to launch the debugger then start adding breakpoints. Before doing this, make sure you un-check the “Exclude Browser Files” in the Debug menu so you can debug your extensions.

6) Extensions That Help You Create Extensions
I only tried Extension Developer and it was all I needed. The Extension Builder that is included is easy to use and packages your files into an xpi, which is good when you are getting your extension ready to deploy.

7) Logging Messages to the Console
It helped to be able to log informational messages to to the console when making web service calls. I also read that there is a better Console. I didn’t have a chance to try it.

8) Extreme XUL Programming
This isn’t extension but a XUL front end to the amazon web service. Check out his newer version too.

9) Extension Developer Books
I didn’t find much that was recent so I stuck with online info.

10) Running Extension Code on Page Load
You can run some of your extension code on every page that loads including new tabs and such. My extension needed to do a quick parse of the url once a new page was viewed. You could try the window onfocus event as I saw another extension doing but I didn’t have much luck.

11) Packaging Your Extension and Enabling Auto Update Checking
If you made it this far, unfortunately it is not over. I had more issues then I care too admit but eventually got the process down. It might of been easier if I created an account on the official firefox addons site and deployed my applications from there but I didn’t. I wanted to host from my site using a non https link because I thought it would be easier. The documentation is out there but its hard to tell what’s relevant to the latest versions of Firefox (I was on Firefox 3). Not only did I have to sign my install.rdf and update.rdf but also include a sha1 key for the xpi file (for every new version). I gathered info from a culmination of these links and tools:
Extension Packaging
Extension Versioning. I had issues with starting my version with a 0.
Signing an Extension or this link. This removes the message the the “author is unknown”. I didn’t bother with my extension.
Securing your install.rdf and update.rdf

Well it definitely was a learning experience, hope this helps. I already have ideas for my next extension.

Bookmark and Share

Comments are closed.