Simon Westphahl

Simple Deployment of Firefox Settings

By Simon Westphahl on January 04, 2010

If you’ve ever deployed Firefox in a small or medium sized company, chances are you came to the point of manually applying the same settings over and over again.

Trial and error

There are serveral solutions for deploying firefox preferences, e.g. FirefoxADM, CCK Wizard + Firefox Release Packager (custom binaries) or FFDeploy (unmaintained). FirefoxADM mostly worked in the first place but always broke after some time.

Firefox preferences

Firefox saves user preferences to a file called prefs.js in a profile folder under %APPDATA%\Mozilla\Firefox\Profiles\. Each line beginning with user_pref specifies a setting that differs from the default preferences (see about:config if you use Firefox). On startup Firefox reads the preferences from this file. If you specify a setting twice, the last entry wins. On close all settings are written back to the prefs.js replacing all content and eliminating duplicate settings.

This behavior can be used to apply your custom preferences. We just wrote a script that appends some common settings (e.g. proxy settings, start page, etc.) to the users prefs.js file. To run this script whenever a user logs in, you just have to add it to a Group Policy.

How to detect changes

If you do not want to end up with an infinite growing preferences file, you have to check if Firefox has been started since the last login of the user.

Some options to do that:

  1. Create some kind of token file with a last-modified timestamp of the preferences file and compare it to the current timestamp of prefs.js.
  2. Use the archive bit on Windows to detect changes to the preferences file. (See the proof of concept below for reference)
  3. Set the hidden attribute of the preferences file and check in you script if it is still set.

The trick with attributes works because Firefox recreates the file every time it is closed. This includes resetting all attributes.

Proof of concept

I came up with a simple batch script. It uses the archive bit on Windows to check if the file was modified since the last login. This is only a proof of concept, but you can easily adapt it to your needs.

@echo off

FOR /F "tokens=*" %%R IN ('dir /B /AD "%APPDATA%\Mozilla\Firefox\Profiles\*.default"') DO CALL:write_settings %%R
GOTO:EOF

:write_settings
DIR "%APPDATA%\Mozilla\Firefox\Profiles\%1\prefs.js" /AA /B
if ERRORLEVEL 1 GOTO:EOF

echo user_pref("browser.download.useDownloadDir", false); >> "%APPDATA%\Mozilla\Firefox\Profiles\%1\prefs.js"
echo user_pref("browser.tabs.autoHide", false); >> "%APPDATA%\Mozilla\Firefox\Profiles\%1\prefs.js"
echo user_pref("browser.cache.disk.capacity", 3000); >> "%APPDATA%\Mozilla\Firefox\Profiles\%1\prefs.js"

ATTRIB -A "%APPDATA%\Mozilla\Firefox\Profiles\%1\prefs.js"
GOTO:EOF

Comments