I wrote this sometime before Ubiquity was first released but it’s probably still relevant, especially since the 1 billionth addon was downloaded recently, which is a great achievement given how hard it is to write an extension.
Creating a Firefox extension is a long and arduous process. Before your extension can even display an alert box, the amount of code you need to write and number of files/folders you need to create is remarkable:
- chrome.manifest
- install.rdf
- chrome/
- chrome/content/
- browser.xul
- browser.js
- (and finally, this single line of Javascript) alert(‘Hello world!’);
If starting up your development process was the only problem, it wouldn’t be a big deal. You could simply get an extension skeleton from somewhere. But there are other problems, too. You must restart your browser everytime you modify your code, however small that modification might be, just to say “Hi world” instead of “Hello world”. This is extremely frustrating when you write extensions. And when you want to share your extension, you need to change chrome.manifest and then, create a XPI. The user, after downloading and installing, needs to stop all the Youtube videos she has been watching and restart the browser just to get a quick preview of your extension.
The way it should be
A simpler way to extend Firefox must be possible. As Aza Raskin suggested a long time ago, imagine if displaying an “Hello world!” alert box was this simple:
function cmd_helloworld(){
alert(“Helloworld”);
}
Enter Ubiquity
That snippet of code can be run on Firefox using Ubiquity. Although Ubiquity is visibly a linguistic command-line for Firefox, it actually provides a perfect environment for extending Firefox. With Ubiquity, to start writing an extension, you just pull up the command editor and start writing a function like the one above. There’s no need to worry about manifests, RDF files and multiple folders. Of course, when you want to say Hello to Dick instead of to the World, you don’t have to restart. Just edit the function in the editor and you will instantly see the changes. And the command editor auto-saves! No clicking of save buttons.
Not commands but extensions
So, that script can be run as a Ubiquity command — which means you have to invoke Ubiquity, type in “helloworld” and then, it will display an alert box. But what makes Ubiquity commands behave like extensions is the fact that commands are not solely accessed by the Ubiquity popup UI. They are also exposed through the contextual menu. And many real extensions do nothing more than add a single item to the context menu. In fact, the Define extension that has been downloaded over 30000 times can be rewritten in just a few lines as a Ubiquity command and still be used in the same way – through the context menu.
Besides context menu addons, another class of extensions, those with no UI at all, can also be written on Ubiquity. Many useful extensions fall in this category including URL Fixer which has been downloaded over half a million times. Ubiquity provides support for these extensions, too. In order to run some code on page load, all you to do is prefix your function name with pageLoad_ or in the case of startup, prefix it with startup_ .
I rewrote the SearchKeys extension as a Ubiquity “command” (a misnomer as you would have realised by now). It was a wonderful experience, no initialization, no packaging trouble, no XPI bundle and best of all, no restarting during debugging. The code is just 200 lines and all of it is in a single file. This is truly the right way to create Firefox extensions.
Besides saving your time, extensions as Ubiquity commands also make it easier for the end-user who can “install” your extension and use it immediately without restarting the browser. You can even write extensions that use XUL (accessed through statusbar icons, toolbars, sidebars, etc.) like Leslie Orchard has done.
The future
Making extension development easier has always been one of the main focuses. Ubiquity might be a good way to get started and experiment, and then, move to writing standard Firefox extensions. I also hope extension development itself can become more humane.
Eventually, Ubiquity will allow all Ubiquity commands to be converted to extensions. So, this easy way of extending the browser may actually help you write a proper extension.


5 Comments
December 10, 2008 at 3:14 am
This seems to be reinventing the three-cornered wheel since the userChrome.js extension (and some additional modules such as userChrome.xul) does pretty much the same and did it long before you did.
Phil
December 10, 2008 at 4:39 am
That description of what you need to create an extension is very misleading and an unfair comparison though. You can create ‘the alert extension’ for your own personal use using only two of those (chrome.manifest and what you call browser.xul).
I’m quite sure that creating a Ubiquity extension and sharing it with others, while giving users information about it and ensuring that security is dealt with is much more complicated that writing a line of script.
December 10, 2008 at 12:03 pm
Restarting after changing something is only necessary for changes in XPCOM components. When things are set up correctly, it’s enough to open a new window for anything else:
https://developer.mozilla.org/En/Setting_up_extension_development_environment
The standard files for an extension (install.rdf, overlays and all) can be created through the Extension Wizard if you don’t want to copy them together:
http://ted.mielczarek.org/code/mozilla/extensionwiz/
December 11, 2008 at 1:51 pm
[...] most folks don’t yet know about Ubiquity is that it can be used for a lot more than just writing user-initiated commands. For example, any [...]
December 11, 2008 at 3:29 pm
[...] is the original post: Simply extending the bbrowser/b « chimney Rating 3.00 out of 5 [...]