A useful setup for developing firefox extensions

Finally, after much trial and error, I have something approaching a usable development environment for a firefox extension. It’s based around roachfiend’s helloworld tutorial.

  1. Set up a separate development profile in firefox that you can play around with. The article Setting up extension development environment is a good source for this. I also found this in my ~/.zshrc useful:
    alias firefoxdev="MOZ_NO_REMOTE=1 firefox -p dev -console"
  2. Download roachfiend’s helloworld extension. Extract it into a directory called helloworld.
  3. Inside the helloworld directory, remove the install.js file. It’s only used by older mozilla’s and we don’t care about it.
  4. Inside helloworld/chrome, create a new helloworld directory and extract the contents of helloworld.jar into it. Then remove helloworld.jar.
  5. Edit the install.rdf so that urn:mozilla:extension:file:helloworld no longer has a ”.jar” on the end.
  6. Now we’re ready to import this lot into subversion:
    % cd helloworld
    % svn import $SVNROOT/helloworld/trunk/src
  7. The extension needs to be built and imported into firefox once.
    % zip -9r ../helloworld.xpi *
  8. Start firefox (in your development profile), do File / Open / helloworld.xpi and install. Then quit firefox.
  9. Change into the development profile directory (I chose ~/work/mozdev to make it easy to find. Then replace the installed extension with the one checked out of subversion.
    % cd ~/work/mozdev
    % cd extensions
    % uuid="{9AA46F4F-4DC7-4c06-97AF-5035170633FE}"
    % mv $uuid $uuid.old
    % svn co $SVNROOT/helloworld/trunk/src $uuid
    % mv $uuid.old/uninstall $uuid

    Of course, this will differ if you have a different UUID (in which case don’t forget to update install.rdf!).

  10. You probably want to set a property to ignore that uninstall directory:
    % svn propset svn:ignore uninstall $uuid
    % svn commit -m 'Ignore uninstall.'
  11. Start firefox and check that the extension still works.
  12. You might want to create a symbolic link to get into the directory easily.
    % cd
    % ln -s ~/work/mozdev/extensions/$uuid helloworld

At this point, you have a version of firefox, with access to a full expanded extension, which you can start developing in. Also the extension is inside subversion, so you can keep track of things sensibly. You’ll note that I imported the extension into a directory called “src”—that’s so that I can put a build script and other stuff above it, in case I ever actually get as far as releasing something.

The steps for cvs instead of subversion should be pretty similiar.

Two very good sources of documentation are: mozillazine knowledgebase: Extension development and devmo: Extensions. It seems like they held all the pieces I needed to pull this together even though I wasn’t coherent enough to spot it.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s