SUSE Conversations


Setting and locking Firefox preferences in SLED



By: mikewillis

January 16, 2014 12:40 pm

Reads:684

Comments:0

Rating:0

Setting and locking preferences in Firefox is something that Mozilla provides documentation for but unfortunately the methods described don’t work for Firefox as it is packaged by SUSE for SLED. Here’s my guide to how I handle the setting of default preferences and the locking of Firefox preferences in SLED.

This guide assumes 64bit SLED and Firefox ESR 24. If you’re using 32bit SLED, change references to /usr/lib64/firefox/ to /usr/lib/firefox/. Some, all, or none of what follows may be invalid for future versions of Firefox. Things can and do change. That said, I’ve been doing this with every version of Firefox shipped in SLED since Firefox 3 and required required changes during that time have been minimal.

At some points in this guide reference is made to creating a clean Firefox profile. You can do this in various ways, but one way is

$ mkdir /tmp/fftmpprofile && firefox -new-instance -profile /tmp/fftmpprofile

That creates a Firefox that is stored in /tmp/fftmpprofile and also launches an instance of Firefox, separate to any instances of Firefox you already have running, which uses that profile.

If you just want to give people a set of defaults when their profiles are created then essentially you create a clean Firefox profile, set things up as you want them and then copy the relevant files from that profile in to /usr/lib64/firefox/browser/defaults/profile/

Most settings are stored in the prefs.js file so after configuring things as desired, you can take a copy of that from your temporary Firefox profile and put that in /usr/lib64/firefox/browser/defaults/profile. You must however check the file for any preferences that contain paths specific to the temporary profile and remove them.

If you want to give your users a set of default bookmarks, create a clean Firefox profile and set up the bookmarks as desired. Quit Firefox and take a copy of the places.sqlite file that’s in the temporary Firefox profile you created. Put that file in /usr/lib64/firefox/browser/defaults/profile/ and remove the bookmarks.html file that’s in there that’s provided by the MozillaFirefox-branding-SLED package. Note places.sqlite also contains the history of visited sites, not just bookmarks. If you’re using a clean Firefox profile to set up the bookmarks that doesn’t matter since you’re only going to be visiting places that end up in the bookmarks anyway. If you don’t want to ensure new profiles only get bookmarks and nothing else you can export the bookmarks to a HTML file and then replace the bookmarks.html file provide by the MozillaFirefox-branding-SLED package with it. To export bookmarks go to the Bookmarks menu, select Show All Bookmarks and in the window that opens, go to the the Import/Backup menu and select ‘Export bookmarks to HTML…’

Whilst adding desired configuration to the default Firefox profile is useful, it doesn’t let you a default preference for existing Firefox profiles. Consider a scenario where a new version of Firefox brings with a feature which is problematic or just undesirable in the context of your environment. Perhaps you want to ensure that it’s disabled by default but allow people to enable if they really want it, or you want to prevent people enabling it.

To set defaults that will apply to both new Firefox profiles and ones that already exist, but that people can override if they want to, you need to create a file in /usr/lib64/firefox/browser/browser/defaults/preferences/. Files in that directory are read in reverse alphabetical order of their name so you’ll want to give the file a name which ensures it gets read after any other files which are already in there. E.g. aaa_initech.js. The file must start with a comment line (comment lines start //) and this is what is looks like with some example settings in:

// Initech default preferences
pref("print.postscript.paper_size","A4");
pref("spellchecker.dictionary", "en-GB");
// allow cut/copy/paste to work by default on Initech websites
pref("capability.policy.policynames", "allowclipboard");
pref("capability.policy.allowclipboard.sites", "http://www.initech.not https://www.initech.not https://cms.initech.not");
pref("capability.policy.allowclipboard.Clipboard.cutcopy", "allAccess");
pref("capability.policy.allowclipboard.Clipboard.paste", "allAccess");
// enable do not track
pref("privacy.donottrackheader.enabled", true);
// disable the sending of information to Mozilla
pref("toolkit.telemetry.prompted", 2);
pref("toolkit.telemetry.rejected", true);
pref("datareporting.healthreport.service.enabled", false);
pref("datareporting.healthreport.uploadEnabled", false);
// pref don't show the 'know your rights' dialogue
pref("browser.rights.3.shown", true);
// take homepage settings from initech.properties
pref("browser.startup.homepage","file:///path/to/initech.properties");
pref("browser.startup.homepage_reset","file:///path/to/initech.properties");
pref("startup.homepage_override_url","file:///path/to/initech.properties");

initech.properties can reside anywhere and looks like this:

browser.startup.homepage=http://www.initech.not
browser.startup.homepage_reset=http://www.initech.not
startup.homepage_override_url=http://www.initech.not

I can’t remember what led me to putting the homepage settings in a separate file. Whilst writing this I’ve tried setting them in the aaa_initech.js file instead of using initech.properties and it doesn’t work.

To figure out put in that file to achieve the desired behaviour, create a clean Firefox profile, copy the prefs.js file from it, make the change you want, quit Firefox and then diff the two prefs.js to see what got changed. E.g.

$ mkdir -p /tmp/fftmpprofile && firefox -new-instance -profile /tmp/fftmpprofile
$ cp /tmp/fftmpprofile/pref.js /tmp
[Set things and quit Firefox]
$ diff /tmp/fftmpprofile/pref.js /tmp/prefs.js

If you want to lock settings to that people cannot change them, those settings need to go in a different file. Add these lines to the aaa_initech.js file mentioned above

pref("general.config.obscure_value", 0);
pref("general.config.vendor", "initech");
pref("general.config.filename", "initech.cfg");

The initech.cfg file should be created in /usr/lib64/firefox. The format is the same as aaa_initech.js except instead of pref you use lockPref. E.g.:

// Initech locked preference
//
// do not display special page when browser has been updated.
// it is at best irrelevant and at worse unhelpful.
// at one point it advised people firefox was out of date and should be updated, even though the
// version of firefox was the latest one available in SLED.
lockPref("browser.startup.homepage_override.mstone", "ignore");
// lock the cache size to 50MB
lockPref("browser.cache.disk.smart_size.enabled", false);
lockPref("browser.cache.disk.smart_size.first_run", false);
lockPref("browser.cache.disk.smart_size_cached_value", 50000);

If your organisation’s website offers an OpenSearch Description File you can include that in Firefox by placing it in /usr/lib64/firefox/browser/searchplugins/ If you want the search engine to appear higher up in the list of available search engines than it would otherwise do, look in the file for the line that contains the ShortName, e.g.

$ grep ShortName /usr/lib64/firefox/browser/searchplugins/initech.xml
<os:ShortName>Initech</os:ShortName>

Then modify /usr/lib64/firefox/distribution/distribution.ini and add a section like this:

[LocalizablePreferences]
browser.search.order.1="Initech"
browser.search.order.2="Google"

That will make Initech the first search engine and Google the second one. distribution.ini belongs to the MozillaFirefox package so you will need to ensure any modifications are put back after an update to the MozillaFirefox package.

If you want to make your search engine the default put this in aaa_initech.js

pref("browser.search.defaultenginename","Initech");

If there are any search engines you really don’t want appearing in the list then unfortunately you have to remove them from multiple places as there’s a localised instances in the Firefox-translations packge. For example if you have particular dislike of the Bing search engine such that you wish to remove you can do:

$ find /usr/lib64/firefox/ -name bing.xml -exec rm {} \;

You’ll need to do that after every update to the MozillaFirefox-translations package.

You may find two of my previous articles useful when distributing Firefox customisations to multiple machines:

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)

Tags:
Categories: SUSE Linux Enterprise Desktop, Technical Solutions

Disclaimer: As with everything else at SUSE Conversations, this content is definitely not supported by SUSE (so don't even think of calling Support if you try something and it blows up).  It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test, test, test before you do anything drastic with it.

Comment

RSS