简体   繁体   中英

Firefox preferences not saved when browser is force quit (XPCOM/javascript)

Working on a firefox extension. I'm trying to set preferences from javascript and observing some odd behavior.

  • Whenever I set a preference, I can see the changes immediately in about:config . But if firefox is force terminated (using a Ctrl+C), the preferences are not saved. (Can't see the entry in prefs.js in my profile)
  • Whenever I set a preference by using about:config toggle option (for boolean), or using a standard prefwindow prefpane, and even if I force terminate firefox, the preferences are saved.

If firefox is closed normally, everything is okay. But I'm just worried that if a force quit happens (like OS shutdown or user sends kill signal), then the user preferences are lost!

This is a bootstrapped addon, and I set default preferences during startup. I have event listeners to read user input, and set the user preference. For eg:

const prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
prefs.setBoolPref("extensions.myextension.test.ffterminate", false);

Am I doing something wrong here ? Should I be using storage instead of preference branch ?

EDIT : Raised a bug with Mozilla on this : https://bugzilla.mozilla.org/show_bug.cgi?id=981818

I'm thinking you didn't set it on the default branch.

This is how you set the pref on the default branch, so when pref is reset, it doesn't delete itself, it goes to this default value. I don't know why on browser force shutdown its losing this but try setting on the default branch:

Services.ps.getDefaultBranch('my_branch_name')['setBoolPref']('myprefname', false);

you were probably just setting on the non default branch liek this:

Services.ps.getBranch('my_branch_name')['setBoolPref']('myprefname', false);

note: if a value is already set on the non-default branch, setting default value will not change the current value of the pref, only if reset, will the pref go to this default value. so dont get confused when u set on default and it doesnt change. it is still working. it actually did change it, right click on the pref and click reset to see it jump to the value u set in default

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM