posted by Olier Raby on Mon 25th Jun 2007 23:48 UTC
"Firefox add-ons, 2/2"
Porting

After expanding Weekedit for a while in Firefox 1.5, I decided it was time to port it to Firefox 2.0. I had to first update the "install.rdf" file in order to tell Firefox 2.0 that my add-on worked with it. As I wrote before, playing with that file is never pleasing.

When Firefox 2.0 finally agreed to load the add-on, something failed when the add-on tried to access a global JavaScript object. After searching within forums, Mozillazine and elsewhere, I found an object close to what I was looking for. The search costed me two hours, and the correction took me another two hours: the new object is only valid in Firefox 2.0, I add to retain backward compatibility. This lead me to believe that many developers would not do the port, since it did not add anything to their add-on. I can understand that Firefox needed a code update, but not that it was so poorly documented. We, add-on developers, are amateurs churning out code as a hobby most of the time. In my opinion, an incomplete or outdated documentation is a serious barrier to deliver add-ons working accross a browser family.

In November 2006, two guys decided they needed my add-on for their Linux PC. In order to put pressure on me, they rated it 0 and 3/5. I became mad. I was doing my best to offer a free, documented, and bug-free add-on, and they were biting me. I decided to reply by writing a short message to my "fan base". And I requested the Mozilla repository to remove the 0 comment. Two months after that incident, even if such behavior was maddening me, I finally started the process of porting the add-on to Linux. Other users were much more respectful, they deserved it.

Since I could port the add-on to different Firefox flavors, I decided to port it to all OSes: Windows, Linux, MacOS, etc. It was working fine in Windows 2000 (W2K), and Windows XP. The port to Linux costed me two (three ?) afternoons. Not so bad considering what I had been through before. My most memorable bug was discovered by a user running an experimental Firefox version against Linux. Weekedit was failing when performing a function call. I was unable to reproduce it in W2K, but everytime in Linux. In a XUL file, a line had onload="Function". Because the parenthesis were missing (onload="Function();" is best), Linux Firefox choked. I still wonder why W2K Firefox never failed.

Naively, I thought if Weekedit worked against two OSes so different, it would work with any OS from now on. A reviewer from the Mozilla repository accepted that version, but wrote me that he could not modify any parameter when using MacOS. I was upset. I had built the add-on with flexibility in mind, and it was not behaving as expected. No MacOS computer around me, I finally settled to only support Windows and Linux.

If you read from time to time about Firefox popularity, you probably saw "Mozilla Firefox". This is a hint toward Firefox predecessor: Mozilla. While that browser gave lot of inputs to the Firefox developers, it is not officially supported anymore by the Mozilla Foundation. I tried to port Weekedit to its successor, SeaMonkey, but I gave up after one hour. I was not ready to go down that road again.

When the French Wikipedia contributors started to use Weekedit, they discovered a bug. When running Firefox 2.0, the accented characters were not properly rendered. In Firefox 1.5, my usual browser, they displayed as expected. I tried things for one year, then I figured out what was going on. The Gecko engine had changed, and the Unicode strings were rendered in a different way. To kill the bug, I needed to change code in .js and .xul files at the same time. In order to prevent disaster for Weekedit users, I created a new add-on offering the same services in Unicode: Wikudit. From a marketing point of view, that was bad, since I broke a product line, but I believe in responsible software practices. What upsets me the most in all this is that Mozilla Foundation still allows the use of plain characters, while the Firefox interface works with Unicode and it is simple to store and retrieve Unicode strings in the preferences (a persistent storage, like Windows Registry).

Today, Weekedit and Wikudit work with Firefox 1.5, Firefox 2.0, Bon Echo (aka Firefox 2.0 nightly build), and Firefox 3.0 (aka Gran Paradiso) against Windows and Linux, and their interface is in English or in French. These are my many-version, bilingual, and many OSes add-ons.

Miscellany

I use a very sophisticated technique to debug the JavaScript code : alert('...');. Coupled with Console2, something that I cannot live without anymore, I can get a good view of my add-on bowels. I could use Venkman, a JavaScript debugger, but it only works if the code is inserted within HTML files, not XUL files. My add-on needs to access the preferences for storing persistent data, but this is forbidden from a HTML file since it does not have enough execution privileges (this prevents malware installation). The same goes for .properties files. Thus, Venkman is not for me. I read on Firebug and tried Web Developer, these toolboxes offer something, but I still do not know how they can help. Sometimes, I browse the developer extensions and try things, but usually there is nothing remarkable.

I cannot copy the message of a Firefox popup. I find this quite annoying, especially when debugging. For instance, suppose I load a page and a JavaScript bug is lurking. Pop! a message tells me that a function-with-a-very-long-name failed. I wish I could copy its name, but since popups are modal (any further interaction with the browser is prevented until I click OK or Cancel), I cannot set them aside and copy their content by hand. Like any geek, I decided to provide a custom popup with message that any user can copy. It works decently, but it took me many headaches and many hours to build it. I hope something similar will be introduced in future Firefox versions.

Many times, I wondered what methods (in object-oriented parlance, functions inside objects) a JavaScript object had. Firefox 1.5 and higher come with a DOM Inspector, but it does not work for dialogs outside the main interface (I found a way to partly circumvent that limitation - more on this below). I implemented a function to display the methods of any JavaScript object. I find this function invaluable.

While writing this article, I learned that I can directly open some XUL file, from the chrome directory, in a browser tab. For instance, typing chrome://wikudit/content/options.xul, in the address bar of my browser, opens up the Wikudit options dialog. I tested it with the DOM Inspector, and it gives me many valuable information and hints. I expect to test the Venkman soon and see what comes out. I still have many roads to explore.

An add-on without any icon is dull. This is the cost for living in the picture age. I decided to insert some plain pictures in mine. I started to explore a new field of knowledge: picture formats, image resizing, color depth, image cropping, noise filtering, etc. While many images were rendered correctly in a standalone viewer, the browser was not outputting the same images. After many hours on the subject, I am still wondering what is the way to create nice icons for Firefox. Please, if you have any good Web site to recommend, I will gladly browse it!

Many add-ons come with an About dialog. This is like a splash screen, but adapted to Firefox add-ons. Mine is available in English and in French, but Firefox cannot directly display the About dialog in French due to a bug. There is a workaround, but it only works if the add-on feeds plain text to Firefox. This thing makes me feel like coding in a tunnel. Just one more function, and I will be out.

For a while, I wanted to change on the fly Wikipedia Web pages: too much stuff. Leveraging Weekedit, I tried hard, but could not find a way to get what I wanted. Maybe I am still too dumb to understand that DOM stuff (in fact, I was searching for an undocumented Firefox event: pageshow, found in a buggy add-on). One day, I fell over a small add-on showing how this was possible with code retrieved from Greasemonkey. Now, I can change HTML and CSS properties of any loaded Wikipedia page. In fact, of any page within targeted Web domains (e.g., wiktionary.org). This is a tribute to the flexibility of Firefox and to the power of add-ons and.

Many add-ons explicitly display licenses: GPL (two varieties at least), LGPL (two varieties at least), MPL, Artistic license, Creative Commons License (six varieties), etc. Many developers do not care at all. Which license you choose for your add-on does not matter, but choose one. Or somebody else, in a remote country, will for you. Weekedit falls under three licenses at the same time: MPL 1.1/GPL 2.0/LGPL 2.1. Wikudit falls under GPLv3 or later. I believe that GPLv3 has more teeth than GPL 2.0, but I wish to respect Weekedit users: changing the license would be like pushing something down their throat.

Conclusion

In order to create an add-on for Firefox, you should be at least proficient in HTML and JavaScript. You will learn the other languages, CSS, XUL, DTD, and RDF, in due time. Expect to reverse-engineer many extensions. This is normal, since Firefox is a complex program, there are many Firefox flavors, and documentation is lacking, even if there are people trying to close the gap. Since April 2007, the book Programming Firefox is available. For me, it is two years too late. For you, it may be the right time.

Today, my extensions work fine. I am proud of what I achieved, but I believe there should be less obstacles in bringing up an add-on. Now, if you will excuse me, I must get back to Wikudit : I have tests to perform against FreeBSD and ZenWalk. See you on the road!

Resources

If you are still ready to jump in the add-ons pool, then read first Getting started with extension development. It is a good start, but be ready to roam the Web.

I use the following programs to develop my add-ons under Windows 2000.

  • UltraEdit (commercial, a nice professional text editor)
  • ASCII to UTF8 Converter (free, convert ASCII text to UTF-8 encoding)
  • FileZilla (free, FTP client to upload files to Web sites)
  • ExplorerXP (free, a tabbed file viewer - the more I use it, the more I like it)
  • IrfanView (free, a very nice image viewer)
  • XnView (free, another nice image viewer)
  • IcoFX (free, icon editor, it has quirks)

About the author:
Olier Raby was previously a natural food store director, an electrical engineer and a software developer. He is now a mathematics teacher interested in customizable educational software, like MediaWiki, the remarkable software behind Wikipedia. He lives in a middle-size city in Canada.


If you would like to see your thoughts or experiences with technology published, please consider writing an article for OSNews.
Table of contents
  1. "Firefox add-ons, 1/2"
  2. "Firefox add-ons, 2/2"
e p (0)    12 Comment(s)

Related Articles

posted by Alexandru Lazar on Mon 5th Jan 2009 19:13
posted by Kroc Camen on Sat 27th Dec 2008 20:52
posted by Thom Holwerda on Fri 26th Dec 2008 11:26, submitted by poundsmack