Setting the Default Search Provider on Chrome via a script

前端 未结 4 1143
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-09 06:39

I am attempting to set various Google Chrome preferences via a script (on both OS X and Windows). I can successfully set a number of preferences, and add bookmarks, by editi

相关标签:
4条回答
  • 2020-12-09 07:00

    A solution that is working for Chromium and Chrome on Ubuntu can be found here:

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

    Besides setting the default search provider, the linked script further customizes Chromium/Chrome to my liking. For Chrome, the part relevant to the question goes like this:

    # 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
    

    This simply adds a new entry to the list of search engines and sets it as default. If you want to select an existing one, things are little more complicated (see script for details). The above requires the package jq, which is not present out of the box on Ubuntu.

    Contrary to other posts, it seems no longer possible to set the default in the meta table. It must be done through the Preferences file as shown above.

    0 讨论(0)
  • 2020-12-09 07:04

    Despite everybody here suggesting to write to Chrome's Sqlite DB, the same can be achieved via JSON based config files (as noted above by https://stackoverflow.com/users/49572/andreas-huber).

    The relevant documentation can be found here:

    • https://www.chromium.org/administrators/policy-templates
    • https://www.chromium.org/administrators/linux-quick-start
    • https://www.chromium.org/administrators/policy-list-3#DefaultSearchProvider

    For Chrome on Linux putting something like this into /opt/chrome/etc/policies/recommended/duckduckgo.json shoud get you started:

    {
            "DefaultSearchProviderEnabled": true,
            "DefaultSearchProviderName": "DuckDuckGo",
            "DefaultSearchProviderSearchURL": "https://duckduckgo.com/?q={searchTerms}"
    }
    

    On Windows and OSX and with Chromium the places to set this are different, but are all documented under the above given URLs.

    0 讨论(0)
  • 2020-12-09 07:06

    as mentioned, you should edit the 'Web Data' file, which is an 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.

    0 讨论(0)
  • 2020-12-09 07:17

    If you want to change the default search provider in Google Chrome you have to modify 'Web Data' file wich is an SQLite file.

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

    See the content of file with SQLite Database Browser; you can find one here.

    0 讨论(0)
提交回复
热议问题