Developing Fire Fox Extensions

This is mostly a link-dump of things that I have found; some are used regularly, some are kept for future evaluation. I need to clean this up, and explain more of what I do. OtherMichael September 17, 2009, at 09:58 AM

 

 

https://developer.mozilla.org/en/Extensions
Firefox addons developer guide
Getting started with extension development
Setting up extension development environment

 

https://developer.mozilla.org/en/Building_an_Extension
https://addons.mozilla.org/en-US/developers/tools/builder - this is new. hunh. looks like it has some “pre-built” features for preferences, toolbars, etc.

 

Firefox/Thunderbird Extension Wizard
How to fix broken Firefox extensions
Updating extensions for Firefox 3
Firefox 2.0 extension development... aaand, we’re at 3.0, now. How accurate is this, still? BUT it’s by LifeHacker’s Gina Trapani
Trapani’s extension posts
FF Extension Dev quick-start

 

Mozilla FF Add-ons Policy
getting addon reviewed
Mozilla addons blog
Install Manifests
Problematic Extensions and workarounds
Mozilla Extension Developer’s forum - search for a lot of answers!

 

a framework?
http://kb.mozillazine.org/Category:Example_code#XML_Technologies_in_Mozilla

 

Chat

http://irc.mozilla.org/ - list of chat channels
particularly:

#extdev
#js
#xul

 

 

Tutorials

video tutorial bootcamp
extension tutorial
http://www.leogas.net/lugext/index.html - 2007 (?) suite of pages from a UCLS Comp Sci doctoral candidate
another tutorial - from 2004, so ditto

 

https://developer.mozilla.org/En/Building_an_Extension
http://www.borngeek.com/firefox/toolbar-tutorial/ - for 1.5
http://www.leogas.net/lugext/index.html - for 1.5 again
http://www.gmacker.com/web/content/tutorial/firefox/firefoxtutorial.htm - for 1.5
http://www.businesslogs.com/technology/firefox_extension_tutorial.php - from 2005
http://lifehacker.com/software/programming/how-to-build-a-firefox-extension-264490.php

 

 

 

 

XPI - Cross Platform Install

The installer is an .xpi file -- just make a .zip and change the extension.
Wikipedia:XPInstall

 

 

Max version

http://www.mozilla.org/developer/ - should list the most recent version for download; s/b listed _somewhere_, though....
see also Extension Versioning, Update and Compatibility for info on updated the version numbers, but nothing concrete (that I could see)

 

Releases

 

 

hosting and updating

Stack Overflow: Packaging and self-hosting FF extensions
Stack Overflow: how does FF know when an extension update is available?
Stack Overflow: signing an XPI

 

 

signing:
http://stackoverflow.com/questions/129920/how-do-you-sign-your-firefox-extensions
http://www.mercille.org/snippets/xpiSigning.php
http://o-regan.org/2007/04/11/firefox-xpi-internal-structure/
http://o-regan.org/xpisigner-secure-your-firefox-extensions/download-xpisigner/

 

 

Testing

MozUnit is a test-driven development framework for the Mozilla platform.
UxU - UnitTest.XUL

http://eng.genius.com/blog/2009/07/14/automating-browser-testing-the-easy-way/

 

 

for study

Better GMail2 - compilation of multiple GM-scripts (for analysis)

 

 

 

First Run

Responsible first-run usage - don’t go crazy on modal dialogs, and put important into the first-run page.

 

Bugzilla: Add standardized support for first-run pages to install.rdf

 

mozdev: Running code on extensions first run, or update (was not loading the required code as of 2010-04-26)

 

Note that the page has some practices that are frowned upon in actual development because they will conflict in the global namespace with any other extension that uses that code verbatim

 

My own extended version of code on that page is below, with changes required to avoid conflicts:

 

// https://developer.mozilla.org/en/Code_snippets/On_page_load#Running_code_on_an_extension%27s_first_run_or_after_an_extension%27s_update
var myExtensionOverlay = {
    init: function(){

        var prev = -1, firstrun = true;
        var skipdate = ""; var dateNotSet = true;
        var showFirsts = true, debugVerbose = false;

        // no need for this var to be in the global name-space
        // NOR to share a potentiall common name. so, ssPrefs
        var svc = Components.classes["@mozilla.org/preferences-service;1"]
        .getService(Components.interfaces.nsIPrefService);
        var ssPrefs = svc.getBranch("extensions.myextension.");

        //gets the version number.
        var gExtensionManager = Components.classes["@mozilla.org/extensions/manager;1"]
        .getService(Components.interfaces.nsIExtensionManager);
        var current = gExtensionManager.getItemForID("myExtension@myExtension").version;

        try{

            prev = ssPrefs.getCharPref("version");
            firstrun = ssPrefs.getBoolPref("firstrun");
            dateNotSet = (skipdate == "");
            showFirsts = ssPrefs.getBoolPref("showfirstruns"); // allows start pages to be turned off for partners
            debugVerbose = ssPrefs.getBoolPref("debugVerbose");

        }catch(e){

            alert("myExtension error in auxilliary.js: " + e.message
                  + "\n\ncurrent: " + current
                  + "\nprev: " + prev
                  + "\nfirstrun: " + firstrun
                  + "\nshowFirstRuns: " + showFirsts
                  + "\ndebugVerbose: " + debugVerbose);

        }finally{

            // debugVerbose s/b set to false for AMO and self-builds
            // leave as manually set for beta-builds
            if (debugVerbose) {
                alert("current: " + current
                      + "\nprev: " + prev
                      + "\nfirstrun: " + firstrun
                      + "\nshowFirstRuns: " + showFirsts
                      + "\ndebugVerbose: " + debugVerbose);
            }

            if (dateNotSet) {
                ssPrefs.setCharPref("firstskipdate", Date());
            }

            // change this depending on the branch
            var newPage = "http://www.myextension.com/install/whatsnew_self.html?ver=" + current;

            // NOTE: showfirst-check is INSIDE both code-blocks, because prefs need to be set no matter what.
            if (firstrun){
                ssPrefs.setBoolPref("firstrun",false);
                ssPrefs.setCharPref("version",current);

                if (showFirsts) {
                    // Insert code for first run here
                    window.setTimeout(function(){
                        gBrowser.selectedTab = gBrowser.addTab("http://www.myextension.com/welcome.html");
                        gBrowser.selectedTab = gBrowser.addTab(newPage);
                    }, 1500); //Firefox 2 fix - or else tab will get closed (leave it in....)
                }

            }

            if (prev!=current && !firstrun){ // !firstrun ensures that this section does not get loaded if its a first run.
                ssPrefs.setCharPref("version",current);

                if (showFirsts) {
                    // version is different => upgrade (or conceivably downgrade)
                    window.setTimeout(function(){
                        gBrowser.selectedTab = gBrowser.addTab(newPage + '&prev=' + prev);
                    }, 1500); //Firefox 2 fix - or else tab will get closed
                }
            }
        } // end finally

        window.removeEventListener("load",function(){ myExtensionOverlay.init(); },true);
    },


};

// fires on browser launch, which includes open-link-in-new-window
window.addEventListener("load",function(){ myExtensionOverlay.init(); },true);
 

 

 

localization

http://blog.babelzilla.org/2009/01/14/externalized-251-localization-blues/

 

 

 

 

XUL - XML User-Interface Language

see also Wikipedia:XUL
Joy of XUL
XUL Tutorial
http://www.hevanet.com/acorbin/xul/top.xul
Getting started with XULRunner
SO:xul
XUL tools
XUL Explorer

 

 

http://www.cmiss.org/cmgui/zinc/ScrollingXulWindows

 

 

see also: XML

 

 

RDF

see also Wikipedia:Resource_Description_Framework
http://www.w3.org/RDF/

 

 

launch the “dev” profile

"%ProgramFiles%\Mozilla Firefox\firefox.exe" -no-remote -P dev

 

specifically, that launches the pre-existing profile named “dev” - if it doesn’t exist, you’ll get the profile selection pane.

 

generally, I create shortcut called ff-pm that launches the profile-manager to allow me to select what I want, now.

 

see also FireFox#profiles

 

 

live development

Registering your extension in the Extension Manager

 

With Firefox closed, create a “pointer” file with the same name as your extension’s Description:ID (as found in your install.rdf) in //path/to/profile folder/extensions/ and edit it so that it contains the path to your extension’s folder (the root containing containing install.rdf and chrome.manifest files).

 

E.g. helloworld’s ID is helloworld@mozilla.doslash.org and we would like to register it in X:\Dev\helloworld\ (i.e. there is X:\Dev\helloworld\install.rdf file etc.). Just put a single line into the file at this path: profile folder/extensions/helloworld@mozilla.doslash.org

 

X:\Dev\helloworld\ - note trailing slash and no CR - single line, remember?

 

(Re)Start Firefox, and check that your extension is installed.

 

 

run code at install/upgrade

Stack Overflow How to run code during the “firstrun” of a Xulrunner Application - answers and vague, but I tracked this down elsewhere. need to document it in here.... (it did take me a few weeks of on-off searching to find the right terms to find the right info)

 

 

Extensions I’ve written

Skip Screen - a Grease Monkey script that is slowly growing out of its short pants

 

 

See Also

Fire Fox
JavaScript
Grease Monkey
FireFox#dev - for my list of developer extensions
Extension Build

 

 

Category tags

Programming browser development web firefox