How do I configure Firefox through a script?

8

2

I'm looking to configure the following Firefox settings through a script (VBS or batch)

  • default home page
  • default search engine
  • disable auto update

Is this possible?

asp316

Posted 2012-01-17T05:26:56.120

Reputation: 299

Answers

9

You can do this by creating or manipulating Mozilla preferences files with your preferred scripting language.

For a list of preferences that can be set through these files, see the Mozilla Preferences and about:config documentation, although the ones that correspond to your list appear to be:-

  • browser.startup.homepage (default home page)
  • browser.search.defaultenginename (default search engine)
  • app.update.auto (enable/disable auto update)

However, depending on your environment, you might find it better to push settings through a custom add-on (see the XPI comments in the Brief Guide to Mozilla Preferences), or through GPO with FirefoxADM or similar.

Kanji

Posted 2012-01-17T05:26:56.120

Reputation: 273

Today, two years later, setting browser.search.defaultenginename does not have effect. An update on this answer would be nice. – Hermann – 2019-06-24T12:21:37.297

Will FirefoxADM allow you to select your default search engine? – asp316 – 2012-01-17T15:39:08.653

Click the link to find out! – surfasb – 2012-01-17T23:48:29.263

I haven't used FADM, but browsing the source, it doesn't appear so. However, you could probably modify it to do so, and contribute your changes back to the project. – Kanji – 2012-01-18T00:04:46.337

2

You can override private browser options in a file user.js in the user profiles folder. I use it often to override some options for example pipelining. Firefox needs to be restart after you have update the user.js. If the file user.js doesn't exist you must create one.

Gigamegs

Posted 2012-01-17T05:26:56.120

Reputation: 1 784

0

to literally copy/paste the part of the answer I was looking for (win env.)

'C:\Users\User\AppData\Roaming\Mozilla\Firefox\Profiles\#####.default\prefs.js'

add

user_pref("browser.startup.homepage", "http://www.URL");

my attempts to copy to remote machines with Get-Content/cat string.txt/"String" >> path, ended with garbage being inserted into the prefs.js file due to the escape characters in the string.

jogjib

Posted 2012-01-17T05:26:56.120

Reputation: 1

0

cd /D "%APPDATA%\Mozilla\Firefox\Profiles\*.default"

set ffile=%cd%

echo user_pref("browser.startup.homepage", "http://superuser.com");>>"%ffile%\prefs.js"
echo user_pref("browser.search.defaultenginename", "Google");>>"%ffile%\prefs.js"
echo user_pref("app.update.auto", false);>>"%ffile%\prefs.js"
set ffile=

cd %windir%

Hyodo

Posted 2012-01-17T05:26:56.120

Reputation: 1

1Welcome to Super User. Your answer will be better if you explain the code a little. I fixed its formatting for you (and I hope I didn't break the code). I have a doubt: I guess your code adds lines instead of overwriting already existing ones. Am I right? Even if it is only the last appearance of a specific option that counts (and therefore your changes are effective), the file will unnecessarily grow with every reconfiguration, gathering more and more instances of these options, unless Firefox itself overwrites the file in a saner way. Was your solution tested against this scenario? – Kamil Maciorowski – 2016-11-26T01:43:06.563

0

The thread is a litte old, but I want to share my solution anyways. Hope this helps someone. We had a similar problem and wanted to add the certificates from windows store into firefox. So I created a script to do so. Anyways, you can change it to your needs: Just add or remove the lines at :: create cfg_file_name.cfg[...] and insert what you need e.g. echo pref("browser.startup.homepage", "http://superuser.com"^); for start homepage and so on. Remember to set the ^ before the last ), otherwise it will not work!

Since version 49 you can do it like that:

@echo off
setlocal enabledelayedexpansion
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: MAIN INFORMATION
:: Title: Change about:config entries in Mozilla Firefox
:: Author: I-GaLaXy-I
:: Version: 1.1
:: Last Modified: 10.01.2018
:: Last Modified by: I-GaLaXy-I
::------------------------------------------------------------------------------
:: This script will add two files, which will change about:config parameters of
:: Mozilla Firefox. You can change the name of these two files and remove or add
:: parameters according to your needs. Renaming the files could be essential, if
:: a user creates own files and you don't want to overwrite them.
:: 
:: If the two files already exist and the script is run, the complete content
:: of both files will be overwritten!
::
:: Note: You may have to run it with administrative privileges!
::
:: More information: https://developer.mozilla.org/en-US/Firefox/Enterprise_deployment
:: http://kb.mozillazine.org/Locking_preferences
::------------------------------------------------------------------------------
:: Subtitle: Import CAs from Windows certificate store
:: More information: https://serverfault.com/questions/722563/how-to-make-firefox-trust-system-ca-certificates
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: Set the name of the .cfg file
set cfg_file_name=add_win_certstore_cas

:: Set the name of the .js file
set js_file_name=add_win_certstore_cas

:: Registry keys to check for the installation path of Mozilla Firefox
set regkey1="HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\Windows\CurrentVersion\App Paths\firefox.exe" /v "Path"
set regkey2="HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\FIREFOX.EXE\shell\open\command" /ve

:: Get installation path of Mozilla Firefox (if not found exit script):
reg query %regkey1%
if %errorlevel%==0 (
    :: First key found, getting path
    for /f "tokens=2* delims=    " %%a in ('reg query %regkey1%') do set path_firefox=%%b
) else (
    :: If first key not found, try another one:
    reg query %regkey2%
    if !errorlevel!==0 (
        for /f "tokens=2* delims=    " %%a in ('reg query %regkey2%') do set path_firefox=%%b
        set path_firefox=!path_firefox:\firefox.exe=!
        for /f "useback tokens=*" %%a in ('!path_firefox!') do set path_firefox=%%~a
) else (
    :: No key found, exit script
    exit
))

:: Create cfg_file_name.cfg if it doesn't exist and input the following lines.
:: Caution! If cfg_file_name.cfg already exists, all lines will be overwritten!
:: Add more lines as needed with the following syntax: 
::echo pref("<name_of_config_entry>", <value>^);
(
    echo //Firefox Settings rolled out via KACE from Systec
    echo //Do not manually edit this file because it will be overwritten!
    echo //Import CAs that have been added to the Windows certificate store by an user or administrator.
    echo pref("security.enterprise_roots.enabled", true^);
) > "%path_firefox%\%cfg_file_name%.cfg"

:: Create js_file_name.js if it doesn't exist and input the following lines.
:: Caution! If js_file_name.js already exists, all lines will be overwritten!
(
    echo /* Firefox Settings rolled out via KACE from Systec
    echo Do not manually edit this file because it will be overwritten! */
    echo pref("general.config.obscure_value", 0^);
    echo pref("general.config.filename", "%cfg_file_name%.cfg"^);
) > "%path_firefox%\defaults\pref\%js_file_name%.js"

:: Files created, exit
exit

I-GaLaXy-I

Posted 2012-01-17T05:26:56.120

Reputation: 506