Forum

 
menu_l Home Search Members Calendar Help Donatemenu_r Current time: 11-03-2024, 07:59 PM menu_l

Hello There, Guest!
(LoginRegister)

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Thread Contributor: RazorDOXHow to create Firefox extensions (Beginner's guide)

10-17-2010, 03:05 PM,
#1
How to create Firefox extensions (Beginner's guide)
[Image: xuleditor-header.png]

The meat of a Firefox extension is simply Javascript - the not-very-mysterious stuff of bookmarklets and regular old web pages - and a markup language called XUL (pronounced "zool.") To build your own, you'll need some Javascript know-how, comfort editing XML files, and a healthy curiosity about bending your favorite web browser to your will.

I started teaching myself how to build Firefox extensions using free tutorials on the web over two years ago. While whole books have been written about creating Firefox extensions, today I've got a quick start list of resources for the curious programmers out there who want to give it a try.

Warning and disclaimer: This post isn't our usual Lifehacker fare - it's a programming tutorial intended for actual hackers, not just lifehackers, who want to get their feet wet in Firefox development. We'll get back to how-to's applicable to regular humans right after this.
Set up your development environment

First things first: you're going to develop a Firefox extension? At some unfortunate moment, you're going to completely hose your Firefox profile. This isn't a possibility, it's a guarantee. So do yourself a favor, and create a fresh Firefox profile that you use exclusively for development. Here's how to create and manage multiple Firefox profiles. I enjoy having my default profile running for quick code reference lookups, and launching my "dev" profile simultaneously using the -no-remote switch detailed in that article.

Once you've loaded up your fresh, clean dev profile, you'll want to make a few about:config tweaks and install a couple of development extensions to make your life easier.
Hello, Firefox extension world!

Back in December of 2004, during some mindless web surfing, I stumbled upon Eric Hamiter's excellent How to create Firefox extensions tutorial and it was the single link that got me started down the road to extension development. The tutorial is a bit dated (especially since Firefox 2), but it's a nice complement to Mozilla Developer Center's official Building an Extension document.

Following the instructions - which involve a lot of placing specific XML and Javascript files in specific folders and zipping them up just the right way - you can build a simple extension that pops up a "Hello, world!" Javascript alert. Do it - every programmer starts a new language by saying hello to the world.

For extra Hello World help, see MozillaZine's Getting Started with Extension Development. A slew of other extension development tutorials are available here.
The Extension Wizard

Once you get into the extension development groove, you'll quickly tire of creating all those weirdly-named folders and files. That's where Ted Mielczarek's Extension wizard comes in handy. You give it your extension's information: ID, icon, license, author and other information and it'll generate an extension folder and file skeleton for you.
The Greasemonkey Compiler

Another wizardly extension-helper is the previously-posted Greasemonkey user script compiler. A Greasemonkey script is just Javascript; and this compiler turns that script into a full-fledged extension. (Note: The Better Gmail extension and all its younger siblings released here on Lifehacker started out using this compiler.)
WTF, XUL?

One of the steep learning curves of extension development is getting your head around XUL, and how it creates elements like menu items and dialog boxes in Firefox. Think of it this way: XUL creates Firefox interfaces like HTML creates web pages. (But being XML, XUL has a lot stricter rules about what tags are allowed.)

For example, a simple XUL-based window with radio buttons for apples, oranges and cherries looks like this in XUL:
Code:
<?xml version="1.0"?> <?xml-stylesheet href="chrome://global/skin/" type="text/css"?> <window id="yourwindow" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> <radiogroup> <radio label="apples" /> <radio label="oranges" /> <radio label="cherries" /> </radiogroup> </window>

To start experimenting with XUL, install the Extension Developer's extension in your development profile. From the Tools menu, Extension Developer submenu, choose "XUL editor" to start composing XUL documents that preview live as you type, as shown:

[Image: xuleditor.png]


Automate your extension builds


Once your extension is working and ready in your development Firefox profile, you want to zip it up and try it out in your "real" Firefox install. Doing this manually is an exhausting pain in the buttocks, so do yourself a favor and employ a batch script to reduce the process to a single command operation. I use a modified version of this Windows build script to package up my extensions.

Like all good things in life, Firefox extension development takes a serious investment, but the reward - making your web browser do exactly what you want it to - is huge.

You ready to give extension dev a try? Let us know how it goes in the comments.
Add Thank You Reply
10-19-2010, 03:42 PM,
#2
How to create Firefox extensions (Beginner's guide)
cool! I was looking for this.... do you also know how to make an extension for safari?
Add Thank You Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Developping a Firefox extension RazorDOX 0 2,185 10-17-2010, 03:16 PM
Last Post: RazorDOX

Forum Jump:


Users browsing this thread: 1 Guest(s)