eBlogzilla

Thursday, February 18, 2010

How to install search plugin together with your extension

A lot of modern sites has own search system. Such system usually performs search on a site and provide search result to a user in accordance with his request.

If you are working on some extension for such site, you can also create and install search plugin for the site.

There are two search plugin formats supported by Firefox:
MozSearch and OpenSearch. Hope that above links will help you to create necessary search plugin.

Then you need to distribute it with your extension. You should do two basic things:
1. Create searchplugins folder in the root of your extension.
2. Add your search plugin to this folder.

So, inside XPI your searchplugins folder will be located on the same level with chrome.manifest and install.rdf files.

There is also one small trick that can be used in your extension. You can select your installed search plugin as default search provider on the first run of your extension. To do that simply add two lines of code:
  var sb = document.getElementById("searchbar");
  sb.searchService.currentEngine = sb.searchService.getEngineByName("YourEngineName");

3 comments:

Nils Maier said...

Please refrain from changing the search provider by default.
This is considered a bad practice and is against addons.mozilla.org rules (NoSurprises policy).
Any AMO reviewer noticing such a thing will reject the nomination for this alone.

If you want to do it right, then please make it opt-in, asking the user if she wants to reset the search provider (ask only once) and assume "no" as the default answer.

devunion said...

I absolutely agree with you. The problem is that some customers need to have this option. And sometimes I was unable to explain them that it is not user-friendly behavior.

Leon Victor said...

We have great solution of this problem and that is “Google toolbar”. Google Toolbar Provides great user flexibility in Firefox for fast and accurate search result.