Writing a Firefox add-on

I’ve created my first plugin for Firefox. It turned out to be easier than I thought. However, it was so easy beacause I didn’t have to interfere Forefox menu. If I hafd to, I would use XUL, which would be tough.

What I was supposed to do, was to add a link Post to notitio.us to articles on wiki that use MediaWiki engine. The link should be placed in the right menu in a box, where link Help is. I decided to use only JavaScript and test the code with GreaseMonkey plugin for Firefox. In short, GreaseMonkey allows to run a specified JavaScript on declared web pages.

So I ended up with the following JavaScript code:

// ==UserScript==
// @name            IKHarvesterWikiPlugin
// @namespace    http://notitio.us/IKHarvesterWikiPlugin
// @description    Adds to Wikipedia pages "Post to notitio.us" link
// @include         http://*wiki*/*
// @exclude        *url=*
// ==/UserScript==

(function () {
var IKHarvesterWikiPlugin = {

    addPostToNotiotiousLink: function() {
        var li = document.createElement("li");
        li.setAttribute("id", "notiotious");
        li.setAttribute("title","Added by IKHarvester plugin");
        li.innerHTML = ' \
            <a title="Post to notitio.us" \
            window.location.href+'\" \   
            style="color:red; font-weight:bold;">Post to notitio.us</a>'

I’ve tested with GreaseMonkey and it worked. So it could be used by anyone who used GreaseMonkey plugin. Then I stared to think how to create a real add-on to Firefox, an xpi file added to Firefox. I’ve found User Script Compiler, a service that compiles GreaseMonkey scripts to real add-ons. Compilation finished with success, and the plugin is available here

So, GreaseMonkey and User Script Compiler allow to create Firefox add-ons. The former can be used during development and testing stage, while the latter generates the final add-on. User Script Compiler creates JavaScript, xul, and other files that are required so that the plugin works. However, you can do it this way only if you don’t plan to add items to Firefox menu and taskbar. Actually, this way you can create only simple extensions. Anyway, sometime it’s just what you want icon smile Writing a Firefox add on

6 Responses to “Writing a Firefox add-on”

  • Hello!
    I think this try.

  • Hi Jarosław,
    Thanks to your post, I created an xpi for my greasemonkey script. But the problem now is, if I upload it to my site, clicking that doesn’t install to Firefox. For example on your page if I click the xpi link, why doesn’t firefox ask to install that as it does on its Add on site?


  • Piyush,

    That’s wierd because Firedix used to ask if you want to install the plugin and now really you can only save or open the xpi file. Anyway, let’s save it and then drag the xpi file and drop it onto Firefox. The plugin installation pop-up will appear and you will be able to install it.


  • Hello, I came across this blog post while searching for help with JavaScript. I have recently changed browsers from Safari to Microsoft IE 6. Just recently I seem to have a problem with loading JavaScript. Everytime I go on a website that requires Javascript, my computer does not load and I get a “runtime error javascript.JSException: Unknown name”. I cannot seem to find out how to fix it. Any help is very appreciated! Thanks

  • i like how you explained it, well written good job.

Leave a Reply