16

I have a local search engine backed by a elasticsearch and a thin nodejs API for search. I want to be able to search those documents from Google Chrome (builds available from Google, not Chromium) directly. In this use case, I will use chrome ONLY with this search engine, so I don't want to use OmniBox keyword search API. I want the same behavior as I get while choosing the default search engine in chrome. Which is

  1. Start typing in the OmniBox and it shows a list of suggestions.
  2. Hit enter and it takes to the search results page

I got the #2 working by adding a new search engine under settings and providing the search api's url. I can't get #1 working.

The two urls exposed by my server are:

  1. http://localhost:3000/complete?query=my (this returns a list of search suggestions which I want to show while typing in OmniBox).

  2. http://localhost:3000/results?query=my+sample+query (this returns the actual search results as a web page, this is working)

Things that I have tried:

  1. Added search engine using window.externals.AddSearchProvider with OpenSearchDescription.xml link. The XML has suggestions url as well.

  2. Tried writing a background extension with OmniBox but it does not allow me to search without using a keyword

I searched through Chromium and found this JSON file

https://code.google.com/p/chromium/codesearch#chromium/src/components/search_engines/prepopulated_engines.json&q=prepopulated&sq=package:chromium&l=1

But I don't know how can I use it (or if its even possible to do this in official builds of Chrome).

drcocoa
  • 1,155
  • 1
  • 14
  • 23

2 Answers2

17

I finally found the solution.

The opensearch.xml document reference can be used as a link in the head section of the HTML page. It contains two URL schemes, one for search results and other for suggestions.

The details can be found here: Opensearch Document Specs.

As soon as I updated my index.html and opened the page in Chrome, Chrome automatically added a new search engine. It didn't show that there is a suggestions URL under Settings > Manage search engines.

Next, I chose my engine as the default search engine by clicking on Make Default and done! Now I can see all the search suggestions in the omnibox without using a keyword.

Chris
  • 3,184
  • 4
  • 26
  • 24
drcocoa
  • 1,155
  • 1
  • 14
  • 23
  • 1
    That is a really useful find – Xan Feb 06 '16 at 16:49
  • 2
    I ran Charles Proxy and noticed that there is an API call everytime I type something, so there is a suggestions URL setting for every search engine somewhere. I found this particular solution accidentally when I was checking on how DuckDuckGo website does it when it says Click here to install DDG on chrome. They call window.external.AddSearchProvider("link to opensearch.xml for ddg). And done. I got that xml file as a reference, edited it with my server information and it worked. – drcocoa Feb 06 '16 at 16:55
1

There is a Setting Overrides mechanism for Chrome Extensions, which is not widely known, which can achieve what you want, but:

  • At least according to the docs, it only works on Windows and Mac.
  • You won't be able to publish the extension unless you can verify the site in Webmaster Tools. Otherwise, you are stuck with unpacked installs.
Xan
  • 74,770
  • 16
  • 179
  • 206
  • Thanks! I don't know why they can't have it on mac. – drcocoa Feb 06 '16 at 16:35
  • If you want pure speculation: it was written at the time when crackdown on Windows malware was happening (and Secure Preferences were introduced), so this was a workaround for legitimate use cases. – Xan Feb 06 '16 at 16:36
  • Ahaa! This does seem probable. See my answer for one solution. – drcocoa Feb 06 '16 at 16:48