How to Add OpenSearch to your Website

Back in the days of Web 2.0, before Node.js, before Google Chrome, before Angular and Vue.js, the browser was slowly evolving, and every so often a truly useful feature would show up in the web ecosystem. This was the case of the OpenSearch specification, to allow browsers to search on any website.

Important: I’m not talking about the Elasticsearch fork, but rather, this specification, as explained on Wikipedia.

Sadly, the feature has been somewhat forgotten; thankfully, it is still currently supported by Chrome and Firefox. Let’s revive this feature, shall we?

Enabling

Here’s how to do it:

  1. Create a file named opensearchdescription.xml in the root of a website:
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
 <ShortName>[Name of the site]</ShortName>
 <Description>Search [Name of site]</Description>
 <Tags>[Name of site]</Tags>
 <Url type="text/html"
      template="https://www.example.com/search?q={searchTerms}"/>
</OpenSearchDescription>
  1. Add the autodiscovery link in the <head> of your HTML:
<link rel="search" href="[Absolute URL of the file you just created]"
      type="application/opensearchdescription+xml"
      title="[Site name]" />

Apparently, the href attribute should be an absolute URL, but at least in the case of Firefox it works with a relative URL "/opensearchdescription.xml", too.

You can see some working examples on this website and on De Programmatica Ipsum.

Chrome Quirks

Chrome (and browsers based thereof) are a bit picky regarding this specification, so please pay attention to the following guidelines:

Configuring

Once your website is deployed with your changes, force-refresh your browser and perform some minor operations.

Firefox & LibreWolf

Firefox will show additional search engines at the bottom of the URL location window when you start typing a URL, with a green “+” sign next to it.

Click on it, and then open the search preferences to assign an optional search prefix by double-clicking on the “Keyword” column.

Chrome & Chromium

Open the search preferences and you will see the newly detected search engine at the bottom of the page; click “Activate”, then (optionally) click the “pencil” button next to it to change the shortcut.

Searching

Hit CTRL+L to select the URL bar, type the chosen prefix, hit the space bar, and type your search term; your browser will redirect you to the search page of your website. Very handy!