How to add a new feed handler in Firefox 2.0

December 30th, 2008. This post was published long time ago on the Italian version of my blog then moved here after the English blog has been opened. Please note that the following post can contain outdated information and (probably) multiple typos.

Firefox 2.0 is out… uhm? what are you saying? what a great news?… oh yeah, but this isn't the main topic of this post.

As someone of you probably remember, on June I made a few tests with Firefox 2.0 Bon Echo 3 focused on how the new Firefox handles feeds. Firefox 2 gives you full control over Web feeds, showing you a preview and letting you choose how you want to subscribe.

At the end of the tests I wrote an article showing how is possible to add a new content handler, aka web aggregator, in Firefox 2.0… it was digged too! (Note. The article is no longer available). Since Firefox 2.0 was not yet released at the time the article was written, I didn't know that there was an easier way to add an content handler without tweaking by hand Firefox registry.

Using registerContentHandler() javascript function is possible to add with just one click a new feed handler… how? Let me show you.

Adding a new feed handler to Firefox 2.0 with registerContentHandler()

registerContentHandler() is a JavaScript function that allows you to register a new content handler in Firefox 2.0. It accepts 3 required params:

the content mime type. For a feed must be application/vnd.mozilla.maybe.feed.
the content handler URI. %s can be used as a placeholder for the resource URI.
the content handler Title

Once again, let's use Rmail as example. Rmail add-new-subscription URI is (always the same) while content handler title is Rmail. Thus, the final JavaScript should looks like the following.


You can put/call this JavaScript function where everywhere in a HTML page, for example as a link (as Netvibes did)…

Example 1.

Look & feel

Click here and add Rmail


<a href="javascript:window.navigator.registerContentHandler('application/vnd.mozilla.maybe.feed',
'','Rmail');">Click here</a>
and add Rmail

… you can put it into a form button…

Example 2.

Look & feel


<input type="button" name="add" value="Click here and add Rmail"
'','Rmail');" />

or include it into a JavaScript function and call it anywhere in the page.

Example 3.


<script type="text/javascript">
function subWith() {
navigator.registerContentHandler('application/vnd.mozilla.maybe.feed', '', 'Rmail');
<input type="button" name="add" value="Click here and add Rmail"
onclick="function subWith();" />

More power to registerContentHandler()

This tutorial might be closed here, but the real reason why I wrote this post is to show how is possible to add more power to registerContentHandler() with a few JavaScript lines.

The idea comes from this post where Randy shows a button to add Rmail as a new content handler. In a comment pat asks which is the best technique between Randy's magic button (see example 2 and example 3) and my tutorial (Note. The tutorial is no longer available).

This is Randy's answer.

Pat, Simone's technique is actually superior as it also includes the email address. I'm working on making that possible too! Randy

The only difference between my code and Randy's code is that I used the following Rmail subscription string (please note the mailto param)

instead of

Thus, what we should do is find a way to allow user to type its own email address and append it to the content handler URI.

My first idea was to create a new input text field. It's better than using other techniques such as JavaScript input boxes since the field can be easily filled with a server side programming language in a more complex site, can be validated and you can re-use in thousand ways. While I was writing the code, I decided to do a little more. Why not creating a script that allows developers to add custom arguments to a content handler URI instead of a single one? Rmail just needs a mailto param but other readers may need mail and user

This is what I wrote!

The following script allows you to register a new content handler in Firefox 2.0 just calling a simple function. In addition, you can create as many form field as you wish calling them name="args". For each field, the script will collect its value and if the field isn't empty, will appends the value to the content handler URI.

Let's see an example. Again, I will use Rmail and I will show you how it's easy to append your personal email to the URI.

Example 4.

<!-- include the script -->
<script type="text/javascript" src="firefox2-registerFeedHandler.js"></script>

<!-- add as many field as you wish.
Each field called 'args' will be appended to content handler URI.
The argument name will be its unique form Id, the value the field value.
<input type="text" name="args" id="email" value="" /><br />

<!-- call the function, use subWith(true) instead of subWith()
to collect form fields.
<input type="button" name="subWith" onclick="subWith(true);" value="Make Rmail your Firefox RSS handler" />

First you must include the script. Don't forget to customize chUri and chTitle variables, as written at the top of the javaScript file.

Then add an input text field for each argument you wish to append to the URI. You can also use hidden inputs to pass hidden values. Don't forget to call them args or the script will not work.

Now call the subWith() function. You can use a link, a button or a common JavaScript event.

Enjoy the confirmation dialog! :D

Add new handler confirmation dialog