Install the default search provider in Chrome using a script

I am trying to set various google chrome settings using a script (for both OS X and Windows). I can successfully set a number of settings and add bookmarks by editing the json settings and bookmark files in the Application Application folder. However, when I try to set a new default search provider, the browser automatically returns to Google search.

The default node search provider in the settings file is as follows:

"default_search_provider": { "enabled": true, "encodings": "UTF-8", "icon_url": "http://www.google.com/favicon.ico", "id": "2", "instant_url": "{google:baseURL}webhp?{google:RLZ}sourceid=chrome-instant&ie={inputEncoding}&ion=1{searchTerms}&nord=1", "keyword": "google.com", "name": "Google", "prepopulate_id": "1", "search_url": "{google:baseURL}search?{google:RLZ}{google:acceptedSuggestion}{google:originalQueryForSuggestion}sourceid=chrome&ie={inputEncoding}&q={searchTerms}", "suggest_url": "{google:baseSuggestURL}search?client=chrome&hl={language}&q={searchTerms}" } 

To add the desired search provider, I simply added it manually (via the wrench menu), looking at the effect of this action in the json file, and then wrote a script to simulate these changes. However, when I change it using a script, the default search provider is used for the first search, but then it is reset the next time chrome starts. What am I missing here?

+6
source share
3 answers

as already mentioned, you must edit the 'Web Data' file, which is the sqlite database.

To add a search engine, add an entry to the 'keywords' table.
To change the default search engine, edit the 'Default Search Provider ID value inside the 'meta' table.

+4
source

If you want to change the default search provider in Google Chrome, you need to modify the Web Data file, which is an SQLite file.

On my computer, where you can find the file, C:\Users\daniel\AppData\Local\Google\Chrome\User Data\Default (Windows7).

See file contents using SQLite Database Browser; You can find it here .

+2
source

The solution that works for Chromium and Chrome on Ubuntu can be found here:

https://github.com/andreashuber69/os-setup/blob/master/common/reset-browser-preferences

In addition to setting the default search provider, the associated script further customizes Chromium / Chrome to your liking. For Chrome, the part related to the question is as follows:

 # Modify the preferences relevant to the default search provider cat ~/.config/google-chrome/Default/Preferences | jq '.default_search_provider_data.template_url_data={ "keyword": "duckduckgo.com", "short_name": "DuckDuckGo", "suggestions_url": "https://duckduckgo.com/ac/?q={searchTerms}&type=list", "url": "https://duckduckgo.com/?q={searchTerms}&t=canonical" }' >adapted-preferences.json mv adapted-preferences.json ~/.config/google-chrome/Default/Preferences 

It simply adds a new entry to the list of search engines and sets it by default. If you want to select an existing one, everything will be a little more complicated (see the script for more details). This requires a jq package that is missing from Ubuntu.

Unlike other posts, it is no longer possible to set a default value in the meta table. This should be done through the settings file, as shown above.

0
source

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


All Articles