149

I have noticed that certain websites (e.g. Stack Exchange sites, Dell, etc.) are automatically added to my list of search engines in Google Chrome.

They even add a keyboard shortcut to their entry. Here are some examples:

  • Dell: Keyboard -> Dell.com
  • Stack Exchange Web masters: Keyboard -> webmasters.stackexchange.com
  • Reuters: Keyboard -> reuters.com

Q1: Is this the default behavior in Chrome? (to let websites add themselves to the list of search engines?)

Q2: Is it possible to disable this behavior in Chrome?

Note: I'm running the latest version of Chrome: 11.0.696.57 on Windows 7 64, and I only have one extension installed: Google URL shortener.

14 Answers14

69

This was making me absolutely insane, so I found a hackish, but effective solution to the issue.

Chrome stores it's search engines in a simple sqlite3 database. I found that you can create a trigger when chrome goes to add the search engine that causes the database insert statement to be ignored.
Note that the search engines are still kept in memory, so they will still show up in the list until the browser is restarted. However you wont have to clear them out all the time, and so if you want to add your own search engines, you won't have to worry about accidentally deleting them (yes, manually adding search engines will still work).

First you must locate the Web data file.

  • Mac OS X: ~/Library/Application Support/Google/Chrome/Default/Web Data

  • XP: C:\Documents and Settings\<username>\Local Settings\Application Data\Google\Chrome\User Data\Default\Web Data

  • Vista/7: C:\Users\<username>\AppData\Local\Google\Chrome\User Data\Default\Web Data

  • Linux: ~/.config/google-chrome/Default/Web Data or ~/.config/chromium/Default/Web Data

Then open it with an sqlite3 editor.

Chrome must be shut down at this point.

The official sqlite web site has a download page with a pre-compiled command line utility for the various operating systems. Though any editor capable of working with sqlite3 databases will work.

For the command line utility, use a command such as the following (don't forget to escape or quote the space in the file name):

sqlite3 /path/to/Web\ Data

Add the trigger.

CREATE TRIGGER no_auto_keywords BEFORE INSERT ON keywords WHEN (NEW.originating_url IS NOT NULL AND NEW.originating_url != '') BEGIN SELECT RAISE(IGNORE); END;

You're done. Close the editor and start chrome back up.


The way it works is that when chrome goes to add auto-add a search engine to the keywords table, chrome sets the originating_url field to the web site it came from. The trigger basically looks for any inserts with a non-empty originating_url field, and issues a RAISE(IGNORE) which causes the statement to be silently skipped.
Manually added search engines don't have an originating_url, and so the trigger allows them to be added.

phemmer
  • 2,475
49

Thanks to @10basetom's code and inspired by @shthed, I've released the Don't add custom search engines Chrome extension which does just that.

You'll find the source code here.

Let me know what you think!

39

There are two ways to do this:

  1. Add this userscript to Tamper Monkey:

    var elOpenSearch = document.querySelector('[type="application/opensearchdescription+xml"]');
    if (elOpenSearch) elOpenSearch.remove();
    
  2. If you're not a regular Tamper Monkey user and don't feel like wasting 15-20 MB of RAM just to load the Tamper Monkey extension for this purpose, then you can roll your own super lightweight extension that won't consume any memory. Instructions are provided below.

How to create your own extension to remove the OpenSearch <link> tag and prevent Chrome from auto-adding search engines:

  1. Create a folder where you will be putting the extension files.

  2. Inside this folder, create two text files named manifest.json and content.js containing the code provided below.

    manifest.json

    {
      "manifest_version": 2,
      "name": "Disable OpenSearch",
      "version": "1.0.0",
      "description": "Remove the OpenSearch <link> tag to prevent Google Chrome from auto-adding custom search engines.",
      "content_scripts": [
        {
          "matches": ["<all_urls>"],
          "js": ["content.js"]
        }
      ],
      "permissions": [
        "http://*/*",
        "https://*/*"
      ]
    }
    

    content.js

    var elOpenSearch = document.querySelector('[type="application/opensearchdescription+xml"]');
    if (elOpenSearch) elOpenSearch.remove();
    
  3. In Chrome, go to chrome://extensions/ (enter this into the URL bar).

  4. Enable Developer Mode.

  5. Click on 'Load unpacked extension', select the folder you created in step 1, and click 'OK'.

Congratulations! Now Google Chrome should be a little less annoying to use :-).

Limitation: This solution is not 100% reliable. If you go to a URL that contains a search parameter (e.g., https://cdnjs.com/#q=fastclick), then in rare cases a custom search engine will still be added. I suspect this is because Chrome can parse the OpenSearch <link> tag before the userscript or extension has a chance to remove it from the DOM.

thdoan
  • 787
28
  1. Yes, this is by design.
  2. No, there's no way to disable this.
11

Edit: this no longer works in Chrome version 84 and upwards

To quickly remove large numbers of search engines, browse to chrome://settings/searchEngines, hit Ctrl-Shift-J (Opt-Cmd-J on OSX) to enter the Javascript console, and paste this:

settings
    .SearchEnginesBrowserProxyImpl
    .prototype
    .getSearchEnginesList()
    .then(function (val) {
        val.others.sort(function (a, b) { return b.modelIndex - a.modelIndex; });
        val.others.forEach(function (engine) {
            settings
                .SearchEnginesBrowserProxyImpl
                .prototype
                .removeSearchEngine(engine.modelIndex);
        });
    });

You may need to paste and run this a few times to clear everything.

alcohol
  • 219
11

Here a somewhat hacky workaround which works just fine for me. Just rename the search alias to something cryptic like "§$%!/()&/". While the search engine is still there you won't see it again, ever. Pretty annoying if you can't google for "jenkins" because chrome forces you to search in jenkins.

atamanroman
  • 280
  • 3
  • 8
8

If I'm understanding what you're describing correctly, then this isn't the websites doing anything at all. Rather, Chrome itself identifies search boxes on websites and then itself adds those to its list of search options in the omnibar.

A1: Yes, this is default behavior, but it's not the websites adding themselves, it's Chrome adding the websites.

A2: I do not believe you can disable this behavior, however you can remove search engines by going to the tool menu -> Options -> Manage Search Engines; they will appear under "Other Search Engines". You may be able to specify that one should not be re-added when you remove it, I'm not sure -- I happen to like this feature, so I'm not going to try removing them.

Kromey
  • 5,335
8

Try using this simple userscript:

// ==UserScript==
// @name       Block Opensearch XML specs
// @namespace  *
// @version    0.3
// @description  Block opensearch xml links
// @match      *
// @copyright  2012+, Christian Huang
// ==/UserScript==

var i;
var val;
var len;
var opensearches;

opensearches = document.getElementsByTagName('link');
len = opensearches.length;
for (i = 0; i < len;i++) {
    val = opensearches[i].type;
    if ( val == "application/opensearchdescription+xml") {
        opensearches[i].parentNode.removeChild(opensearches[i]);
    }
}
nc4pk
  • 9,257
  • 14
  • 61
  • 71
ythuang
  • 89
  • 1
  • 1
7

One workaround I've found for this is to acquire the habit of starting all my searches with a space. If you type ・Splunk median (where represents the space character), Chrome will perform a Google search on Splunk median.

Tog
  • 5,065
6

<-- Background -->

I have an alternate, less-intrusive idea for you here (at least if you're running an ad blocker, as so many of us are for our own sanity/safety). I like using existing extensions/scripts as much as possible to avoid the bloat of a whole extension for just one feature (worst-case scenario) so this solution works under this principle.

Adblock, and its variants/successors (uBlock is my weapon of choice), have the ability to block web page elements, including <link> elements, which is used for autodiscovery of OpenSearch Descriptions (OSDs), the XML files that contain the information which permits auto-adding search engines and causes us these headaches. I say "permits" because it's hardly mandatory, as, so far as my research has shown, Firefox simply reads this information and makes it available for easy addition under the Search Engines dropdown box, rather than quietly auto-adding it like Chrome does.

The use of the feature is described in the Opensearch specifications in multiple places:

http://www.opensearch.org/Specifications/OpenSearch/1.1#Autodiscovery_in_RSS.2FAtom (ignore the specific subtltle of this section for our purposes as it's just an example of it in use)


<-- The Solution -->

As it states that OpenSearch Descriptions (OSDs) have a unique type, we can filter them out with the following AdblockPlus/uBlock rule:

##link[type="application/opensearchdescription+xml"]

I've tested this and the rule shows the correct match on my test sites (filehippo.com etc) and the search engines are no longer auto-adding, so I believe this is a full solution.


A quick note on the history I've found behind this: Chromium's engineers have labeled this "WontFix" several times over the years (a power-user disable option/flag was requested multiple times) stating that this is considered a niche issue since the feature is "generally useful", their stance is that niche issues should be solved by extensions or 3rd-party scripts rather than by the devs adding countless flags and the like to cater to all whims, so basically what we're doing here is just in line with their preference and keeps it nice and manageable.

Best of luck! If anyone else tries this let us/me know how it works!

Rook
  • 472
4
  1. Go to chrome://settings/searchEngines
  2. Open the Developer Tools
  3. Run the following in the Javascript console tab
const otherEngines = document.querySelector("body > settings-ui")
                    .shadowRoot.querySelector("#main")
                    .shadowRoot.querySelector("settings-basic-page")
                    .shadowRoot.querySelector("#basicPage > settings-section.expanded > settings-search-page")
                    .shadowRoot.querySelector("#pages > settings-subpage > settings-search-engines-page")
                    .shadowRoot.querySelector("#otherEngines").shadowRoot

let n = otherEngines.querySelector('iron-list').childElementCount - 1;
let rmbtn = otherEngines.querySelector('#frb0')
                        .shadowRoot.querySelector('#delete')

const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));

while(n--) {
    rmbtn.click();
    await sleep(2000);
}

Adjust the sleep duration between clicks as you see fit.

Mahmoud
  • 221
1

Based on the javascript provided by others, I have created my own hackish script to remove all custom search engines in the list except any that you have nicknamed with the text "(KEEP)".

var engineList=document.querySelector("body > settings-ui").shadowRoot.querySelector("#main").shadowRoot.querySelector("settings-basic-page").shadowRoot.querySelector("#basicPage > settings-section.expanded > settings-search-page").shadowRoot.querySelector("#pages > settings-subpage > settings-search-engines-page").shadowRoot.querySelector("#otherEngines")
function get_engines_list() {
    return engineList.shadowRoot.querySelector("#container").children[0].children;
}
function get_engine_count(){
    // "Templates" is first entry.
    return get_engines_list().length - 1;
}
var i;
for (i = 1; i <= get_engine_count(); i++) {
    var entry=get_engines_list()[i]
    var engineName = entry.shadowRoot.querySelector('.list-item').querySelector('#name-column').childNodes[1].innerText;
    if(!engineName.includes("(KEEP)")){
        entry.shadowRoot.querySelector("#delete").click();
    }
}
0

I can Confirm that Mahmoud K's answer from May 1, 2020 Works as of today's latest release (Version 89.0.4389.90 Windows 10 1909).

I had to run 4-5 times since it stalled out. s I had to search and find an answer how to handle the 1st stall. This post shows how to pause a script, and then stumbled about the answer of stopping. See this post's picture stackoverflow.com/a/51802310/14947713 In the current version of come there is small arrow on that pause button that shows a Start and Stop symbol. I also had to reload the Settings page twice as I was figuring out how to use the script

Sorry I was unable to comment, but I thought it best to let others know who were search as it was difficult hunting to find this answer among the many prior SU.com questions

Be fore-warned, it seems I actually saw an increase in the Search Engines in the first couple of runs but think I saw removal activity, I am assuming it may have just been loading off-display entries, so just be patent and follow-through

Mahmoud K.'s Code here, but I changed to as low as 200ms on the final run and plan to go lower if need be in the future, as he notes :

const otherEngines = document.querySelector("body > settings-ui")
                    .shadowRoot.querySelector("#main")
                    .shadowRoot.querySelector("settings-basic-page")
                    .shadowRoot.querySelector("#basicPage > settings-section.expanded > settings-search-page")
                    .shadowRoot.querySelector("#pages > settings-subpage > settings-search-engines-page")
                    .shadowRoot.querySelector("#otherEngines").shadowRoot

let n = otherEngines.querySelector('iron-list').childElementCount - 1; let rmbtn = otherEngines.querySelector('#frb0') .shadowRoot.querySelector('#delete')

const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));

while(n--) { rmbtn.click(); await sleep(200); }

hsgg4
  • 39
0

I deleted all other search engines as follow.

  1. Go to the engine (link)
  2. Then hit ctrl + shift + j
  3. Then use paste the following code:
for (let i of document.querySelector("body > settings-ui")
     .shadowRoot.querySelector('#main')
     .shadowRoot.querySelector("settings-basic-page")
     .shadowRoot.querySelector("#basicPage > settings-section.expanded > settings-search-page")
     .shadowRoot.querySelector("#pages > settings-subpage > settings-search-engines-page")
     .shadowRoot.querySelector("#otherEngines")
     .shadowRoot.querySelectorAll(":scope settings-search-engine-entry"))
     {
         console.log(i);
         i.shadowRoot.querySelector("#delete").click();
     }
Anonymous
  • 275