A brief introduction
This tutorial will attempt to explain in a simple manner how to create an OpenSearch plug-in for Firefox. These plug-ins appear in a drop-down menu in the Firefox Quick-Search bar (located right of the URL/Address bar) and help you perform quick searches across various search engines without having to visit the search page first. Pretty neat, eh?
These search plug-ins were in existence (for Firefox) for a long time. But only with the introduction of Firefox 2.0, the OpenSearch standards have been adopted.
OpenSearch is a collection of simple formats for the sharing of search results.
The OpenSearch description document format can be used to describe a search engine so that it can be used by search client applications.
The OpenSearch response elements can be used to extend existing syndication formats, such as RSS and Atom, with the extra metadata needed to return search results.
The example I’m going to demonstrate searches Invision Power Board (Bulletin Board System). You can make this plug-in perform searches on virtually any other Blogs / Bulletin Board / Content Management System / Search Engine with just some minor modifications in the way the search URL (along with keywords) is sent to the search engine. Here’s a screen-shot of two such plug-ins I’ve created for Astahost & Trap17 forums powered by IPB (Invision Power Board).

Advantages
There are quite a few advantages of shifting to the new OpenSearch format for these plug-ins, namely …
- OpenSearch plug-ins are universally supported across many browsers & search clients. Specially worth a mention here are Firefox and IE7 !!
- OpenSearch supports Autodiscovery of the plug-in, which means you don’t really have to instruct the user to click on a link on your site to install the plug-in. The search client can auto-discover the plug-in script based on a link provided between the HEAD tags of the page.If you wish to, the old-school click & install method can still be implemented.
- A lot of recent Blogs / CMS / BBS etc. softwares have started supporting the OpenSearch API, which provides a flexible common standard for XML based searches. A list of such software can be found here.
Without further ado, lets get down to business …
The actual plug-in
The OpenSearch plug-ins consist of a single XML file called the OpenSearch Description File. It follows a very simple syntax as shown below:
engineName engineDescription inputEncoding outputEncoding data:image/x-icon;base64, imageData searchFormURL
Most of the tags here need to be customised according to the Search Engine you’re going to use with the plug-in. Here’s what you need to modify here.
engineName
engineName enclosed within the ShortName tags specifies the name of the Search Engine as it’ll show up in the dropdown list. Replace this with the name of your Search Engine.
engineDescription
engineDescription enclosed within the Description tags shows up as a brief description of the Search Engine. Replace this with a suitable description.
inputEncoding
inputEncoding enclosed within the InputEncoding tags declares the encoding to use for search string / keywords you provide for a search. The search string is encoded in this format prior to sending to the Search Engine. Your best best is to use UTF-8 here to declare it as Unicoded text that’ll cover the whole Unicode Character Set.
outputEncoding
outputEncoding, enclosed within the OutputEncoding tags acts similar to InputEncoding and declares the character set to be used for producing the search results output. Even here the best used option is UTF-8.
Image
Enclosed within the Image tags, this specifies the image / icon to be used for the Search Engine. This icon turns up next to the search engine name in the dropdown list and also shows up to the left of the quick-search bar. The image is usually in a 16 x 16 pixels format.
The image data can be provided in two formats:
- As a direct URL link to the location of the image file (gif/jpg/png etc.)
- As base64 encoded data which can be embedded in the plug-in directly. This I believe, is a more elegant way of doing it. However, I couldn’t make it work properly for me. The image simply refused to turn up and hence I’d to resort to method 1.There’s a very good tool at URI Kitchen that encodes any uploaded image in base64 format. The encoded data can then be directly embedded in the plug-in.
Url
Enclosed within the Url tags, this provides the actual location of the Search Engine page. The method attribute defines whether to use GET or POST for fetching the data, while the template attribute points to the location of the search query page. NOTE, that IE7 doesn’t support the POST method and hence to make your plug-in compatible with both IE7 and Firefox, you should ideally use GET here.
Param
Further nested within the Url tags lie a series of Param tags which have two attributes - a name and a value. These act as parameters which are passed to the search engine while performing a query. This too, isn’t supported in IE7. However, you can use a dynamic variable called {searchTerms} to pass on keywords.
Say for instance, I’m searching Invision Power Board based forums. The standard search string in IP takes the format,
[html]http://www.domain.com/index.php?act=Search&CODE=show
&searchid=xxx&search_in=posts&result_type=topics&highlite=keywords
[/html]
If you study the URL carefully, you’ll notice that there are a couple of variables like act, CODE etc. which appear everytime along with same values. You can use Param tags to define key-value pairs for these variables, which will then be passed onto the Search Engine during a query.
The actual search keywords (as mentioned before) are available through a variable called {searchTerms}. IPB supports a variable called keywords in the search string and hence you can define a key-value pair like…
[xml]
[/xml]… to pass the keywords.Here’s a full working example of the plug-in I created for Astahost forums…[xml]xmlns:moz=”http://www.mozilla.org/2006/browser/search/”>
Here you’ll notice several other tags like Developer, Contact, SyndicationRight, AdultContent etc. which I haven’t discussed in this article. A detailed outline of all the OpenSearch tags can be found at: OpenSearch Description Elements.
Autodiscovery
If you recall I’d discussed a feature called Autodiscovery earlier on. This helps search clients automatically discover a plug-in embedded in your page. The process is quite simple. All you’ve to do is include a special LINK statement in the HEAD part of your page.
[html]
title=”xxx Search Plugin: By Author” href=”http://domain.com/plugin-file-name.xml”> [/html]You simply need to modify the title and the href link to the actual plug-in file.When you visit a site with the plug-ins set to be auto-discovered, here’s how the drop-down menu in the quick-search box will look like…

Adding the plug-in Programmatically
You can also include the plug-in on your page in a click-and-install manner. The process has been simplified. All you need to do is provide a link to install the plug-in on your page and in the link, add the window.external.AddSearchProvider() JavaScript statement. Example is shown below.
[html]Link Text
[/html]
Clicking on this link will cause Firefox to pop-up a dialog box asking the visitor for a confirmation of plug-in installation. Example of the dialog box …

Working examples can be found at the Astahost Plug-ins Page.
Any questions / confusions ?? Feel free to leave a comment and I’ll make sure to get back to you.






On Creating an OpenSearch Plug-in for WordPress (for Firefox & IE7) | Chaos Laboratory said:
[...] In my earlier tutorial titled Creating OpenSearch Plugins for Firefox (adds to the QuickSearch bar) I taught you how to write a basic OpenSearch XML format plug-in that can be used with both Firefox 2.x and IE7. The demonstrated example consisted of creating a plug-in that searches through Invision Power Boards. [...]
RON said:
Hi
very intresting ive done all you ask but i still cant get it to run.This is the first one but am keen to get it of the ground.It take me to the site but the puzo.org name is missing and the search engine doesnt pull up any details can you help at all
thanks
RON said:
Ive just found out that mine is not appearing in the search bar ive macthed yours with mine AHH ill wait for your input thanks
miCRoSCoPiC^eaRthLinG said:
Hi Ron,
I just read about your problem. Can you perform a normal search through your IPB installation and paste me the code that comes up in your URL ??
Secondly can you mail me the plug-in you wrote to microscopic_DOT_earthling_AT_gmail_DOT_com. I’d be able to advise better if I took a look at it. The code that you pasted here got all messed up because of the way WordPress parses HTML.
Cheers,
m^e
miCRoSCoPiC^eaRthLinG said:
Hi there Ron,
I analysed your file and found several mistakes because of which you faced so much of difficulty in getting it to work. The basic structure was fine. Here’s a list of the errors - so that you can avoid them in future, in case you write the plugin for some other site.
Also the closing tag was declared simply as moz and not moz:SearchForm, making it an of invalid (mismatched tags) XML document.
I’ve fixed all the problems above and attached a working copy of the extension here. You can easily compare the two and figure out the mistakes yourself. I’ve tested it and it seems to work just fine.
Firefox OpenSearch Plug-in Samples for a wide variety of sites | Chaos Laboratory said:
[...] January 14, 2007 Following the tutorial(s) I posted on creating OpenSearch plug-ins for Firefox that can search Invision Power Board based forums & WordPress blogs, I received quite a few requests for help in creating such plug-ins for a wide variety of blogs/CMS/sites. [...]
Grace said:
Thanks for fixing my plugin. One strange thing: OpenSearch seems to demand an absolute URL, and won’t allow a local location (file://…) for the plugin.
miCRoSCoPiC^eaRthLinG said:
No problem at all, Grace
I hadn’t really tried it out using the file based approach. Will have to ascertain it, now that you’ve brought it to my notice.
Cheers,
m^e
OpenSearchFox: A Firefox extension to create OpenSearch Plug-ins in a single click at Chaos Laboratory said:
[...] Tutorial: Creating OpenSearch Plugins for Firefox (adds to the QuickSearch bar) [...]
Guy Rintoul said:
Hi there,
Great tutorial
Just one thing though… my plugin’s working no problems on Firefox but in IE it says “Internet Explorer could not install this search provider. There was a problem with this search provider’s information”. I notice you said a few times some parameters aren’t compatible with IE… can you see any problem in my XML below?
Regards,
Guy
http://www.guyrintoul.com
The Relentless Stream of Consciousness
http://www.guyrintoul.com/favicon.ico
contact@guyrintoul.com
Guy Rintoul’s weblog, The Relentless Stream of Consciousness, at http://www.guyrintoul.com
Guy Rintoul
open
false
UTF-8
UTF-8
miCRoSCoPiC^eaRthLinG said:
Ooops
Seems like the WordPress parsed all the XML tags in your comment and made them disappear leaving out just the content between the tags.
It’d be better if you can mail me your code at: sourjya AT chaos-laboratory DOT com
noob said:
it works in ie7 also
miCRoSCoPiC^eaRthLinG said:
Yep noob. It’s supposed to. Any OpenSearch plugin should work uniformly across IE7 and Firefox 1.5 .
Bubbila said:
Sweet tutorial, just what I have been looking for! Well Pleased…