How to determine the default Chrome search engine by default

I am developing a chrome extension and my requirement is to discover the default Chrome browser search engine.

I searched a lot on the net, but did not get any api to detect this.

I also searched the web to do this using Javascript / Jquery, but so far have failed.

Please suggest me a way so that I can discover the default search engine for Chrome browsers.

+6
source share
1 answer

The only way I can think of is to request the HTML5 front end .

Although this will not give you a search engine by default users, you can query the search engine URL and see if it uses the one you know the URL.

installed = window.external.IsSearchProviderInstalled(url) 

Returns a value based on a comparison of the URLs with the URLs of the result pages of the installed search engines.

0: None of the search engines installed matches the URL.

1: One or more search engines installed match the URL, but none of them are the default search engine.

2: The default search engine matches the URL.

But remember the following:

The URL is compared to the URLs of the search results pages of installed search engines using a prefix match. Only result pages in the same domain as the script that calls this method are checked.

This means that you can only check if the browser is on the site you are requesting.

So, if you go to https://www.google.com and run the following in the console:

 external.IsSearchProviderInstalled("https://www.google.com") 

2 will be returned, if you run the same in the console at a different URL than the one you are requesting, you will receive an error message.

+1
source

Source: https://habr.com/ru/post/979849/


All Articles