Default Preferences

Introduction

A key part of any extension is the default settings that come with it. Mozilla provides a simple way of shipping default settings by allowing default preferences.

Remember that preferences are held in two separate trees. One with user supplied prefs, another with default prefs. User supplied prefs are set using the GUI and also by modifying a profile's prefs.js file (which uses the user_pref() function). Default preferences are set similarly but inside an extension and use the pref() function.

Setting default preferences

While most of an extension's directories can be named arbitrarily and mapped using a chrome manifest, default preferences must be in very particular spot:

| Extension Root
+--|content
+--|skin
+--|defaults
+--|preferences

To add preferences simply drop a .js file into that directory and Mozilla will read it and set the appropriate preferences.

The actual file, despite having .js extension, is not a JavaScript file. You may not set variables inside of it, nor may do any kind of program flow control (ifs, loops etc.) nor even calculated values (i.e. 3600 * 24 * 5). Doing so will cause Mozilla to stop processing your preferences file without any notification, warning, error, or exception. Think of it more as an .ini file. Comments are perfectly acceptable.

Document Tags and Contributors

Learn the best of web development

Get the latest and greatest from MDN delivered straight to your inbox.

E-mail

I'm okay with Mozilla handling my info as explained in this Privacy Policy.

Thanks! Please check your inbox to confirm your subscription.

If you haven’t previously confirmed a subscription to a Mozilla-related newsletter you may have to do so. Please check your inbox or your spam filter for an email from us.

Why does MDN look different?

MDN is changing to focus just on documenting web technologies. All the same great content is still here; we’re just changing some visual elements and navigation, to help you more quickly find the web technology docs you’re looking for.

But don’t worry, MDN and Mozilla are still together! In fact, we're updating MDN’s look to reflect Mozilla's new logo and colors.