George MacKerron: code blog

GIS, software development, and other snippets

Getting a Firefox extension’s directory from within the extension

without comments

When creating a Firefox extension recently, I was surprised how much pain is involved simply in finding out, from within an extension, where that extension’s files are installed.

You have to create a ‘component’, which entails a fair chunk of unintelligible boilerplate code (well, unintelligible unless you’re much better acquainted with Firefox’s innards than developing a basic extension generally requires you to be).

Plenty of places will tell you roughly how to do it. But, after some experimentation, let me show you exactly how.

  • Copy this JavaScript file into your extension’s /components directory (if that directory doesn’t exist yet, create it).
  • Use it from elsewhere in your extension like so:
own_path = Components.classes["@mackerron.com/get_ext_dir;1"]
  .createInstance().wrappedJSObject.get_ext_dir();

And that’s it. Let me know if it helps you out.

Written by George

May 7th, 2009 at 1:23 pm

Posted in JavaScript

Leave a Reply

Preview: