Mozilla, Chrome and FUEL


I wrote an XSPF import handler for Songbird yesterday, before noticing that someone else had already mostly done it. Still, the code might be useful if you ever need to open an XML file and parse it using E4X within an XULRunner application.

The code probably works the same from within a Firefox extension as well, but there are still times where it takes trial and error to find out which commands work in which circumstances. The FUEL library is a good start at making things easier for Firefox extension and XULRunner developers, but doesn't cover enough yet.

For example, there's still a lot of confusion about how to call these:

  • The main browser window that includes the chrome (window)
  • The XUL document within that window (document)
  • The 'web browser' part of the window (gBrowser)
  • The current tab of the 'web browser' (gBrowser.mCurrentTab) - this is what's referred to in web page Javascript as 'window', I think.
  • The 'web page' part of that 'web browser' (gBrowser.contentDocument) - this is what's referred to in web page Javascript as 'document'
  • The 'web page' part of the 'web browser' relating to the current event (e.originalTarget.contentDocument)

There are also lots of helper functions that would be useful, such as
which could replace

It's that last kind of incantation that makes building Firefox extensions and XUL applications much harder than it needs to be.