[Greasemonkey] GM_setValue,
getValue and default values for preferences
Ori Avtalion
oavtal at bezeqint.net
Sun Sep 18 21:29:10 EDT 2005
Hi,
When creating new mozilla preferences with GM_setValue, they are saved
in about:config with no default value.
If a variable is non-existent, GM_getValue returns null or the second
argument given to it.
Imagine this scenario:
Joe Developer wants to check if a script that uses saved preferences
works for the first time it is run on a machine. Since he already ran it
on his machine, he goes to about:config and tries to delete the
preference. No luck. The only available option is "reset". He chooses
that, the value disappears and the status changes to "default".
Now whenever he calls GM_getValue he gets the error:
Error: Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED)
[nsIPrefBranch.getCharPref]
Source File: joescript.user.js
Line: 0
Source Code:
0
The problem:
The preferences API sets a 'default' default value when no explicit
default value was set in the creation of the value:
http://lxr.mozilla.org/mozilla1.8/source/modules/libpref/src/prefapi.cpp#700
Perhaps it's just me, but it seems the string value of defaultPref is
never set - not even to "\0". I'm not filing a bug report yet because
I'm not sure it's a bug.
Assuming it isn't, I suggest the following solutions
The solution(s) suggested:
1) GM_setValue could expose the third parameter of the ns function
PREF_Set*Pref, which states that the given value should be set as
default, to the developer.
2) GM_setValue could internally set the third parameter to always be
true, thus disabling the effect "defaulting" a value has in about:config.
Also, perhaps GM script-created values should register themselves as
"removable", so users could remove them from about:config by hand (a
firefox RFE is in order before that happens).
Although it's easy to blame the user on breaking the script by resetting
the preference by hand, I still think the error should be worked around
somehow.
I'd appreciate any feedback on the matter.
Thanks,
Ori
More information about the Greasemonkey
mailing list