What's the difference between components and chrome?

Mozilla has two ways in which a JavaScript-based extension can run.

Chrome: One of them, chrome, works very much like the way JavaScript programs run on an ordinary web page: you have a particular document, and the JavaScript sits behind it and provides the magic to make it work. The document could either be an HTML document, as on the web, or it could be written in Mozilla's own language, XUL, which defines the look of application windows and dialogues; they're loaded from your hard disk and not the web, and accessed by an address beginning chrome: rather than http:, such as


The big difference between chrome JavaScript and web JavaScript is that web JavaScript isn't allowed to read your hard disk, play with random network connections, and so on. After all, it could have been written by just anyone, so it's wise to treat it with some caution. Chrome JavaScript, on the other hand, is trusted and treated as part of your browser itself-- it's allowed to do pretty much anything Mozilla can do.

Chrome lives in the chrome/ directory of your Mozilla installation. Gnusto's chrome JavaScript is in chrome/gnusto/content/. This code is a duplicate of $/src/gnusto/content from CVS. At present, jury-rig does not update this for you-- it's just an identical copy, anyway. Use symlinks if you have them, or copy the whole directory into your Mozilla directory, or pester Marn to add the capability to jury-rig. It'll come soonish.

Components: On the other hand, under the bonnet, Mozilla uses a component system called XPCOM. (How does a component system work?) The components can be written in a bunch of different languages-- the main ones are written in C++, but you can also write them in Python or in JavaScript, which is where we come in. Components written in JavaScript work almost the same as those written in C++, but with the added advantage of portability without compilation.

We are gradually moving parts of Gnusto's code from pieces of chrome to independent component form, because components are simpler and cleaner. For example, there's no possibility that an identifier we use in one part of the program will clash with one from another part. (There are also a few things you just can't do in chrome.)

Components live in the components/ directory of your Mozilla installation. Gnusto's component JavaScript and XPIDL are in the subdirectories of $/src/xpcom in CVS; jury-rig should handle everything to do with compiling and copying these files between your Gnusto source directory and your Mozilla installation.

For more information on XPCOM, see:

The gnusto project can be contacted through the mailing list or the member list.
Copyright © 2000-2017. All rights reserved. Terms of Use & Privacy Policy.