Force search engine in mozilla.cfg?
How can I lock the search to Google using mozilla.cfg on Firefox 44?
Based on searching, I've tried the following settings:
lockPref("browser.search.geoSpecificDefaults", false); lockPref("browser.search.defaultenginename", "Google"); lockPref("browser.search.selectedEngine", "Google"); lockPref("browser.search.order.1", "Google");
And both variations of:
lockPref("browser.search.defaultenginename.US","data:text/plain,browser.search.defaultenginename.US=Google");
lockPref("browser.search.order.US.1","data:text/plain,browser.search.order.US.1=Google");
lockPref("browser.search.defaultenginename.US", "Google"); lockPref("browser.search.order.US.1", "Google");
Nothing seems to work.
Soluzione scelta
See also Services.search:
- https://developer.mozilla.org/Mozilla/Tech/XPCOM/Reference/Interface/nsIBrowserSearchService
- https://developer.mozilla.org/Mozilla/JavaScript_code_modules/Services.jsm
- http://mxr.mozilla.org/mozilla-release/source/browser/components/search/content/search.xml
currentEngine = Services.search.currentEngine.name
Note that the mozilla.cfg file is run as a JavaScript file and can contain JavaScript that runs with full chrome privileges.
Leggere questa risposta nel contesto 👍 0Tutte le risposte (10)
The data:text/plain variant is only required to set the default value of a pref via defaultPref(); In all other cases you can use the plain value.
You can no longer set the default search engine via a pref similar to setting the new tab page (browser.newtab.url)
- bug 1029148 - store "current search engine" configuration outside of prefs
Please do not comment in bug reports
https://bugzilla.mozilla.org/page.cgi?id=etiquette.html
The setting of the current default search engine is stored in the search-metadata.json file in the Firefox profile folder in the [global] section.
[global]: current: ""; searchdefault: "Google";
Soluzione scelta
See also Services.search:
- https://developer.mozilla.org/Mozilla/Tech/XPCOM/Reference/Interface/nsIBrowserSearchService
- https://developer.mozilla.org/Mozilla/JavaScript_code_modules/Services.jsm
- http://mxr.mozilla.org/mozilla-release/source/browser/components/search/content/search.xml
currentEngine = Services.search.currentEngine.name
Note that the mozilla.cfg file is run as a JavaScript file and can contain JavaScript that runs with full chrome privileges.
Modificato da cor-el il
Thank you for your reply.
So best practice is to set the currentEngine property using javascript in the mozilla.cfg? (was unaware it was parsed in that fashion.)
Far less intuitive, but it will do.
For anyone else who has this issue:
In mozilla.cfg this following will set Google as the default. Users can still change it, but it will change back upon next start of Firefox.
Components.utils.import("resource://gre/modules/Services.jsm"); var searchService = Services.search; var engine = searchService.getEngineByName("Google"); searchService.currentEngine = engine;
Note that for the about:newtab page you need to use a similar way to do this.
Components.utils.import("resource:///modules/NewTabURL.jsm");
This seems to work consistently, at least on Firefox 45 ESR:
local-settings.js file:
// https://support.mozilla.org/en-US/questions/1065182#answer-740266 // http://mike.kaply.com/2012/03/16/customizing-firefox-autoconfig-files/
pref("general.config.obscure_value", 0); //do not obscure content with ROT-13 cipher pref("general.config.filename", "mozilla.cfg"); //use the mozilla config file for further preferences
Add to mozilla.cfg file
// Change default search engine to Google lockPref("browser.search.region", "US"); lockPref("browser.search.countryCode", "US"); lockPref("browser.search.defaultenginename", "Google"); lockPref("browser.search.defaultenginename.US", "Google");
That likely won't work anymore. Current releases store this data in search.json.mozlz4 and prefs are no longer being used.
Good to know, and I will have to research another method for the future when it no longer works for Firefox ESR.
Preferences definitely work on Firefox 45.1.0 ESR english release as per my prior post... I have not tested on the general release.
I am pushing it out to about 75 computers right now and I verified that the settings persisted on normal user logins as well as under an administrator login.
I obtained the preferences by comparing the default preferences under about:cofig with preferences after the user changes the default search engine under about:preferences#search
SigmaTech said
This seems to work consistently, at least on Firefox 45 ESR:
local-settings.js file:
// https://support.mozilla.org/en-US/questions/1065182#answer-740266
// http://mike.kaply.com/2012/03/16/customizing-firefox-autoconfig-files/
pref("general.config.obscure_value", 0); //do not obscure content with ROT-13 cipher
pref("general.config.filename", "mozilla.cfg"); //use the mozilla config file for further preferences
Add to mozilla.cfg file
// Change default search engine to Google
lockPref("browser.search.region", "US");
lockPref("browser.search.countryCode", "US");
lockPref("browser.search.defaultenginename", "Google");
lockPref("browser.search.defaultenginename.US", "Google");
This method seems to no longer work in Firefox 47.0.1. And it seems that the search settings are stored in a compressed file (search.json.mozl4z) that's uneditable? Come on, man! Why is it that this stuff is so hard to configure and control? Why are settings just randomly moved and changed every few versions and there is virtually NO documentation on how to manage these new or changed settings for enterprise customers who want some level of control over the browser...
My request is very simple, I just want the browser's default setting to be Google but Mozilla has decided, probably through some financial arrangement with Yahoo, that IT will be the default search engine... the settings above seem reasonable but do NOT WORK which means that there must be some new way of controlling them...
I already tried just copying the compressed file (search.json.*) to the program files folder (/browser/defaults/profile) but it doesn't work... what's interesting is that it DOES work if the profile already exists and I copy the file to the already existent profile folder...
I am really frustrated by this... anyone who has a method of doing this, can you please provide a working set of instructions or settings? We do not want to mandate Google as the search engine, just make it the default on first launch.
Thanks, jcl
Hello,
I spent about 5 hours trying to figure this out before I got to my solution, playing with all the variations of settings, even settings from the mozilla official page that describes every configuration value and what it does, etc.
I won't comment as to why they made it so hard for people to customize the firefox search engine for deployments now that Yahoo was the sponsor, it's just weird that all of a sudden after they sponsored them it was not as easy as setting a lockPref setting and done.. supposedly it was for security and vulnerability reasons that prevents search engine hijacking.. oh well.
Ok so here is the solution:
I read that search.xml is inside this folder somewhere called search plugins, but that folder is not present in the same location as before, it is now inside a file called omni.ja within the Resources/browser folder. This file cannot just be unzipped because you might run into errors, mozilla even recommends a certain unzip tool for it if you use Windows OS. I even tried Keka to unzip it and it wouldn't, don't know why a Mac built-in Linux version was able to unzip it and inflate the file if needed pretty easily.
Anyway, so what you do is take the omni.ja file, copy it to a new folder somewhere in your desktop, open up terminal and work from within that directory (cd /folder/etc..), then rename that file to omni.zip or add the .zip so that the system sees it as a zip file.
Then, at the terminal and within the directory of the omni.ja.zip or omni.zip file, type: unzip omni.zip
Then, find the folder: chrome/en-US/locale/browser/searchplugins/
In that folder you should see all the search engines listed:
chrome/en-US/locale/browser/searchplugins/amazondotcom.xml chrome/en-US/locale/browser/searchplugins/bing.xml chrome/en-US/locale/browser/searchplugins/ddg.xml chrome/en-US/locale/browser/searchplugins/eBay.xml chrome/en-US/locale/browser/searchplugins/google.xml chrome/en-US/locale/browser/searchplugins/list.txt chrome/en-US/locale/browser/searchplugins/twitter.xml chrome/en-US/locale/browser/searchplugins/wikipedia.xml chrome/en-US/locale/browser/searchplugins/yahoo-en-CA.xml chrome/en-US/locale/browser/searchplugins/yahoo.xml
You can obviously guess what comes next, delete ALL the files except list.txt and google.xml, and open list.txt and also remove all the references of search engines except the google one.
Done.
Now to zip the file again back to omni.ja the proper way.
Delete the omni.zip or omni.ja.zip file you copied because when you run the zipping command it will create the new file and you dont want to deal with dumb overwrite errors.
In the terminal type in: zip -qr9XD omni.ja *
This will create the file again with all folders and files in their proper way/order.
Now, with the new omni.ja file created, go into your Resources/browser folder and add the word .bak to your default/original omni.ja file that came with Firefox, so your original will be omni.ja.bak just in case anything went wrong and you have to do it again.
Now, copy that new omni.ja file to that directory and voila, Google is not only the default search engine, but there is no other engine to be changed to or able to select.
For reference, I used: https://developer.mozilla.org/en-US/docs/Mozilla/About_omni.ja_(formerly_omni.jar)
You're welcome.