0

How is it possible to program an Addon that changes a certain config value in Firefox, that usually is only accessible via about:config?

Is there a template I could use? Or Do I have to start from scratch?

rubo77
  • 19,527
  • 31
  • 134
  • 226
  • config file for firefox's `about:config` is a simple javascript file located in the user profile. Look for `pref.js` on your computer. It is easily modified via scripting, so it could surely be done with an addon as well – Aserre May 21 '14 at 13:17
  • 1
    Please ignore @Ploutox's suggestion and do **not** mess with the file yourself. – nmaier May 21 '14 at 14:33
  • @nmaier Why is that ? It is quite easy to do and quite common as well, at least in Unix environment – Aserre May 21 '14 at 14:35
  • @Ploutox Because add-ons have a dedicated and safe API to query and manipulate preferences. My answer will be up shortly. – nmaier May 21 '14 at 14:36
  • Here's a template that i use that gets notified whenever a pref changes (via observer) and offers an onChange function, I don't have any documentation on it, which i need to write some day. https://gist.github.com/Noitidart/e0d3c21ab38822fbfd17 – Noitidart May 21 '14 at 14:39
  • @Ploutox: PS: Also, modifying the file from an add-on while the browser is running isn't safe in general. The preferences will not be reloaded until a browser restart and might be overwritten in the mean time by the browser. – nmaier May 21 '14 at 14:43

1 Answers1

1

Please see the Preferences documentation and API reference, in particular Adding preferences to an extension and Code Snippets. Just to be clear: The nsIPreference* APIs can be used to query/modify any preference, not just add-on specific ones.

SDK users should use simple-prefs (for add-on prefs), and/or preferences/service.

nmaier
  • 32,336
  • 5
  • 63
  • 78
  • I used the Add-on SDK now and I created this plugin now: https://addons.mozilla.org/en-US/firefox/addon/response-timeout-24-hours/ using `Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch).setIntPref("network.http.response.timeout", 3600*24)` as described [here](http://stackoverflow.com/questions/23783375/how-can-i-display-the-network-http-response-timeout-in-firefox-with-javascript) – rubo77 May 21 '14 at 20:58