How to make a custom search engine (URL parameter with %s) the default search engine?
Firefox used to allow a hack to add a custom search engine to the search engine list. This allowed users to make custom engines the DEFAULT search engine. (Engines can be added to Bookmarks but then they require a keyword to activate. Default engines do not require a keyword to activate).
The way to do it was: 1) place a folder called "searchplugins" with your custom .xml file describing your search engine (i.e.,, a URL with a %s added to it) inside your Home folder on a Linux OS.
2) open the Web Console
3) input: Services.search.addEngine("file:///home/user/searchplugins/custom-engine.xml", null, null, false);
4) now your custom search engine would appear in the search engine listing in Firefox and could be made default
On recent Firefoxes, this no longer works. When I inter the Sevices.search.addEngine part to the Web Console, I get this message: "ReferenceError: Services is not define"
I've been using Google Chrome because of stuff like this. Firefox just doesn't allow me to do what I want to do. But I appreciate Mozilla ideals and am trying to give Firefox another chance. But it is contingent on being able to make my custom search engine the default search engine.
Is there a fix for this error I'm encountering in the Web Console?
Wybrane rozwiązanie
Here is an updated set of instructions that may be slightly easier:
(1) Enable the Browser Console command line if you haven't done this previously
See: https://developer.mozilla.org/docs/Tools/Browser_Console#Browser_Console_command_line
For quick reference, that's:
- In a new tab, type or paste about:config in the address bar and press Enter/Return. Click the button accepting the risk.
- In the search box above the list, type or paste chrome and pause while the list is filtered
- Double-click the devtools.chrome.enabled preference to switch the value from false to true
(2) Drag and drop your .xml OpenSearch plugin file into a Firefox tab
We're going to use the shortcut of grabbing the path of the active tab in the active window, so it doesn't matter where on disk the .xml file is, as long as Firefox has permission to read that location.
(3) Select and copy the following line of script:
Services.search.addEngine(gBrowser.currentURI.spec, null, null, false);
You may wonder, what does this do, exactly? Good question, because it can be dangerous to run scripts from strangers in the Browser Console.
Documentation on addEngine(): https://developer.mozilla.org/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIBrowserSearchService#addEngine()
Parameter 1: URL of file to add -- will be grabbed from active tab Parameter 2: dataType of file (not really needed, so set to null) Parameter 3: URL for icon (not needed, so set to null) Parameter 4: ask user to confirm? (doesn't work, so set to false)
(4) Open the Browser Console
With the file:///.../mysearchengine.xml tab active, press Ctrl+Shift+j to launch the Browser Console (on Mac, press Command+Shift+j instead).
(5) Paste the script on the Browser Console command line and press Enter to execute it
The Browser Console should show that a Promise object was created. You can close the console window now unless you have more to add.
Switch over to Firefox to confirm that the new search engine appeared, this should only take a moment. To make it the default, you can use the usual methods. See: Change your default search settings in Firefox.
Success?
Przeczytaj tę odpowiedź w całym kontekście 👍 2Wszystkie odpowiedzi (8)
grgwmsm said
2) open the Web Console
Commands that modify browser internals generally need to run in the Browser Console rather than the page-specific Web Console. More info:
https://developer.mozilla.org/docs/Tools/Browser_Console
Does the old method still work there?
Wybrane rozwiązanie
Here is an updated set of instructions that may be slightly easier:
(1) Enable the Browser Console command line if you haven't done this previously
See: https://developer.mozilla.org/docs/Tools/Browser_Console#Browser_Console_command_line
For quick reference, that's:
- In a new tab, type or paste about:config in the address bar and press Enter/Return. Click the button accepting the risk.
- In the search box above the list, type or paste chrome and pause while the list is filtered
- Double-click the devtools.chrome.enabled preference to switch the value from false to true
(2) Drag and drop your .xml OpenSearch plugin file into a Firefox tab
We're going to use the shortcut of grabbing the path of the active tab in the active window, so it doesn't matter where on disk the .xml file is, as long as Firefox has permission to read that location.
(3) Select and copy the following line of script:
Services.search.addEngine(gBrowser.currentURI.spec, null, null, false);
You may wonder, what does this do, exactly? Good question, because it can be dangerous to run scripts from strangers in the Browser Console.
Documentation on addEngine(): https://developer.mozilla.org/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIBrowserSearchService#addEngine()
Parameter 1: URL of file to add -- will be grabbed from active tab Parameter 2: dataType of file (not really needed, so set to null) Parameter 3: URL for icon (not needed, so set to null) Parameter 4: ask user to confirm? (doesn't work, so set to false)
(4) Open the Browser Console
With the file:///.../mysearchengine.xml tab active, press Ctrl+Shift+j to launch the Browser Console (on Mac, press Command+Shift+j instead).
(5) Paste the script on the Browser Console command line and press Enter to execute it
The Browser Console should show that a Promise object was created. You can close the console window now unless you have more to add.
Switch over to Firefox to confirm that the new search engine appeared, this should only take a moment. To make it the default, you can use the usual methods. See: Change your default search settings in Firefox.
Success?
By the way, in an OpenSearch .xml file, the best parameter to use is {searchTerms} rather than the %s you use in keyword bookmarks. So the template URL will look something like this:
https://www.somesite.tld/search?q={searchTerms}
See:
If the search engine is available via the Mycroft website then you might be able to add the search engine in an easier way.
jscher2000 said
Here is an updated set of instructions that may be slightly easier: (1) Enable the Browser Console command line if you haven't done this previously See: https://developer.mozilla.org/docs/Tools/Browser_Console#Browser_Console_command_line For quick reference, that's:
- In a new tab, type or paste about:config in the address bar and press Enter/Return. Click the button accepting the risk.
- In the search box above the list, type or paste chrome and pause while the list is filtered
(2) Drag and drop your .xml OpenSearch plugin file into a Firefox tab We're going to use the shortcut of grabbing the path of the active tab in the active window, so it doesn't matter where on disk the .xml file is, as long as Firefox has permission to read that location. (3) Select and copy the following line of script:
- Double-click the devtools.chrome.enabled preference to switch the value from false to true
Services.search.addEngine(gBrowser.currentURI.spec, null, null, false);
You may wonder, what does this do, exactly? Good question, because it can be dangerous to run scripts from strangers in the Browser Console. Documentation on addEngine(): https://developer.mozilla.org/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIBrowserSearchService#addEngine() Parameter 1: URL of file to add -- will be grabbed from active tab Parameter 2: dataType of file (not really needed, so set to null) Parameter 3: URL for icon (not needed, so set to null) Parameter 4: ask user to confirm? (doesn't work, so set to false) (4) Open the Browser Console With the file:///.../mysearchengine.xml tab active, press Ctrl+Shift+j to launch the Browser Console (on Mac, press Command+Shift+j instead). (5) Paste the script on the Browser Console command line and press Enter to execute it The Browser Console should show that a Promise object was created. You can close the console window now unless you have more to add. Switch over to Firefox to confirm that the new search engine appeared, this should only take a moment. To make it the default, you can use the usual methods. See: Change your default search settings in Firefox. Success?
This worked. Thanks!
grgwmsm said
This worked. Thanks!
Hello "grgwmsm",
Would you be so kind as to mark jscher2000's post as Chosen Solution ?
It's the "Solved the problem" button to the right of his post.
Thank you in advance !
jscher2000 Top 10 Contributor said
Here is an updated set of instructions that may be slightly easier: (1) Enable the Browser Console command line if you haven't done this previously See: https://developer.mozilla.org/docs/Tools/Browser_Console#Browser_Console_command_line For quick reference, that's:
- In a new tab, type or paste about:config in the address bar and press Enter/Return. Click the button accepting the risk.
- In the search box above the list, type or paste chrome and pause while the list is filtered
(2) Drag and drop your .xml OpenSearch plugin file into a Firefox tab We're going to use the shortcut of grabbing the path of the active tab in the active window, so it doesn't matter where on disk the .xml file is, as long as Firefox has permission to read that location. (3) Select and copy the following line of script:
- Double-click the devtools.chrome.enabled preference to switch the value from false to true
Services.search.addEngine(gBrowser.currentURI.spec, null, null, false);
You may wonder, what does this do, exactly? Good question, because it can be dangerous to run scripts from strangers in the Browser Console. Documentation on addEngine(): https://developer.mozilla.org/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIBrowserSearchService#addEngine() Parameter 1: URL of file to add -- will be grabbed from active tab Parameter 2: dataType of file (not really needed, so set to null) Parameter 3: URL for icon (not needed, so set to null) Parameter 4: ask user to confirm? (doesn't work, so set to false) (4) Open the Browser Console With the file:///.../mysearchengine.xml tab active, press Ctrl+Shift+j to launch the Browser Console (on Mac, press Command+Shift+j instead). (5) Paste the script on the Browser Console command line and press Enter to execute it The Browser Console should show that a Promise object was created. You can close the console window now unless you have more to add. Switch over to Firefox to confirm that the new search engine appeared, this should only take a moment. To make it the default, you can use the usual methods. See: Change your default search settings in Firefox. Success?
Succeeded! Thank you!
The idea use case seems to be having custom search engines built into the browser settings like in Chrome as outline in the post: Custom Search Engines in Google Chrome: Essential Tips and Tricks Custom Search Engines in Google Chrome: Essential Tips and Tricks.