Harshit Prasad bio photo

Harshit Prasad

Software Engineer - @blinkit, all about search systems - data and infrastructure stuff. Loves to talk about distributed systems and open source.

Email Twitter LinkedIn Github Stackoverflow

Explains how to set default search engine in a browser.

This blog was originally posted on FOSSASIA Blog.

Have you ever seen on the sites like Google and DuckDuckGo, when a user visits their website first time they provide an option to add their search engine as default search provider. Similarly, we raised up an issue regarding the implementation of this feature.

Currently, we have implemented this feature but facing some issues. Here is a screenshot:


Code for implementing this feature:

$(document).ready(function () {
  var isFirefox = typeof InstallTrigger !== "undefined";

  if (!isFirefox) {

  if (window.external && window.external.IsSearchProviderInstalled) {
    var isInstalled =

    if (!isInstalled) {

  $("#install-susper").on("click", function () {

  $("#cancel-installation").on("click", function () {

You can see, right side a box to add search provider as a default. But, this feature was not working for Chrome since it has some different approach to add search providers because of internal API method AddSearchProvider() and window.external.IsSearchProviderInstalled() works only with the newer version of Firefox and earlier they worked with Chrome as well, but now they don’t. So, to remove this feature from Chrome browser, we simply commented out the lines which are highlighted in the code as bold.

We are still having an issue like, if a user adds the search provider in Firefox by installing it and then he/she visits the site next time, that option still appears to be there. It should not appear again if Susper has been already added as default search provider. We’re working on it though via storing some metadata in local cache of the browser.

What else I did for other browsers compatibility?

I picked up the idea of adding an OpenSearch feature. It auto-discovers the search providers.

What I did simply:

  1. Created an XML file as and configure it like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
    <ShortName>[Name of your website]</ShortName>
    <Description>[Description of your website]</Description>
    <Url type="text/html" template="http://www.yourwebsite.com/search?q=site:[Site host] {searchTerms}"/>
  2. Add an auto-discovery link in your main index.html file:


We’re done! To see it in action, refresh the browser. The browser will auto-detect and tell you that a custom search engine was discovered and you can customise it according to your choice.

Check our susper.xml here: susper.xml