I get a lot of questions about debugging AutoConfig issues, so I thought I would document what I do to try to track them down.
If Firefox starts, go to about:config and search for general.config. Make sure there are values for general.config.filename and general.config.obscure_value. If they are not there, your defaults/prefs/autoconfig.js file is not being read. The most common reason this happens is permissions or you’ve placed it in the wrong directory.
If both the general.config values are present, the next step is to check if your cfg file is being read. I usually make a very simple cfg file:
[code type=”javascript”]
// First line is always a comment
lockPref("a.b.c.d", "e.f.g.h");
[/code]
Then I go to about:config and verify that the a.b.c.d preference is there (it will be at the top). If the preference is not there, then something must be very wrong. I check the browser console to see if there are any errors. If the preference is there, AutoConfig is working correctly. I then start adding it the parts of my AutoConfig file a piece at a time, leaving the setting of the a.b.c.d pref at the end of the file. Then I check about:config each time and see which line is breaking the AutoConfig file.
If the browser doesn’t start at all, the first thing I do is put all my AutoConfig code in a try/catch block like this:
[code type=”javascript”]
// First line is always a comment
try {
// My AutoConfig code.
} catch (e) {
Components.utils.reportError(e);
}
[/code]
If the browser then starts, I look in the browser console to see what the error was. If the browser still doesn’t start, I start removing pieces of my AutoConfig until it does.
The most common problem in the past with AutoConfig was the use of let instead of var. This was fixed in Firefox 42 and should no longer be an issue. Some other common problems were around the use of international characters, in particular saving AutoConfig files as UTF-8 versus ASCII. This should also be fixed. All AutoConfig files should be saved as UTF-8.
In general, as long as you don’t have JavaScript syntax errors in your AutoConfig file, they should just work. That’s been my experience, and I’ve written some pretty complicated AutoConfig files.
Leave a Reply