user.js icon indicating copy to clipboard operation
user.js copied to clipboard

A code snippet

Open Theemim opened this issue 9 years ago • 35 comments

Hi. I appreciate what you are doing. Thank you. This is something I am test driving:

// FIRST: Set starting milestone and create visual feedback that would indicate incompletion
lockPref("_autoconfigMilestone", "1 (First)");
lockPref("browser.display.background_color", "#ff9900");
lockPref("browser.display.document_color_use", 2);

// SECOND: Disable javascript and put into offline mode to reduce risk from incompletion
lockPref("javascript.enabled", false);
var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
var originalOfflineState = ioService.offline;
ioService.offline = true;

// Stuff

// LAST-1: Restore original offline state and enable javascript
ioService.offline = originalOfflineState;
lockPref("javascript.enabled", true);

// LAST: Eliminate visual feedback of incompletion and set final milestone
lockPref("browser.display.background_color", "#ffffff");
lockPref("browser.display.document_color_use", 0);
lockPref("_autoconfigMilestone", "100 (Last)");

See anything you like? Have any suggestions?

Theemim avatar Aug 01 '17 23:08 Theemim

Hi @Theemim and thanks for posting something completely new and fresh. 👍 This would run pretty early in the startup, even before loading prefs.js and user.js, and therefore, without knowing what you do in // Stuff, I don't really see its usefulness. Do you use this for Tor Browser? I think even in TBB this wouldn't guarantee that nothing runs before Tor and the browser is fully up and all the addons loaded and stuff. Basically this would run AND finish way too early, no? I guess it really depends on what you do in // Stuff. Care to elaborate?

earthlng avatar Aug 02 '17 08:08 earthlng

I'm doing what you are doing via autoconfig rather than user.js. You noticed that. I'm making pref changes which are nearly identical to yours, so for purposes of discussion here: The Stuff = ghacks-user.js with user_pref changed to lockPref.

I believe lockPref'd settings persist and "override" any pref changes made via prefs.js and user.js. But the browser and/or addons can change a lockPref'd item. So they can override something set that way. Which they can also do for something set via prefs.js and user.js. I haven't tried applying pref changes to TBB via autoconfig or user.js.

Several times I saw Firefox silently abort processing of autoconfig (due to an error) and proceed to startup. Normally that doesn't happen (an exception gets thrown, which you can catch) and what I saw may have been a glitch (in my code). I decided to play it safe and attempt the risk-reduction shown in the snippet. Some of which could be applied via user.js (which seems more likely to silently abort). Assuming the user confirms that their (modified) user.js has no syntax errors and can run to completion (parrot, nudge nudge, say no more) it is probably overkill.

Theemim avatar Aug 02 '17 10:08 Theemim

Oh okay I see.

I believe lockPref'd settings persist and "override" any pref changes made via prefs.js and user.js.

afaik that's correct.

But the browser and/or addons can change a lockPref'd item.

afaik that's incorrect. But it can be easily tested, simply run Services.prefs.setIntPref (or Bool or Char) in a scratchpad or browser console (with devtools.chrome.enabled;true) and see if the pref gets overwritten. Maybe there are other ways to change prefs as well, idk, but this is what most of the code uses anyway.

If you want to make sure nothing runs before the browser is fully up and all addons loaded, etc, you could just disable your network adapter, start FF or TBB, check parrot and enable the network again (and reconnect tor).

it is probably overkill.

yeah I agree. I haven't used autoconfig yet because it applies to all profiles and a user.js is just more convenient IMHO. I don't update my user.js very often anymore but when I do, I only need to check the parrot once and from then on I know that everything was and will be applied correctly all the time.

For our purposes here, locking prefs would be very inconvenient if users want to temporarily change a pref, fe because min.tls.version is set too high for a certain page to load, or whatever.

But I very much appreciate that you brought this up, very refreshing. It also reminded me that you can run and invoke other FF code that way. Pretty cool stuff, thanks 👍

earthlng avatar Aug 02 '17 11:08 earthlng

Normally they wouldn't, but if they want to they can unlockPref() and then make their change. An autoconfig can use pref() instead of lockPref() to allow the user to temporarily override. You can just let it apply to all profiles or you can set different prefs for different profiles, switch on environment variables, prompt for things, etc. But I still agree with you: many would prefer the user.js approach.

I don't know if autoconfig is usable with mobile versions. I also don't know how the shift to WebExtensions, and other planned changes, will impact what can be done in autoconfig (and elsewhere).

Do you mean can't be set via lockPref or have to be set via lockPref? I don't know of any that can't be set and that doesn't make sense to me. I think there are some that have to be set that way or just can't be set via prefs.js or user.js.

Theemim avatar Aug 02 '17 12:08 Theemim

I'll try that in FF54 portable and get back to you.

Theemim avatar Aug 02 '17 12:08 Theemim

balls have zero to me to me to me to me to me to me to me to me to

earthlng avatar Aug 02 '17 14:08 earthlng

Another thing to note is that the cfg's pref() will override user.js

wow, wtf!?! This is so confusing. If you use pref() in mozilla.cfg it acts like user_pref() from user.js (=pref shows as "user set"), but if you use pref() in the user.js it acts like defaultPref() ... ! where is the logic in that??! And the user.js is supposed to be loaded last, then why the hell can it not overwrite pref() or user_pref() configs from any and all previously loaded preferences files?! What I also don't really understand is why it needs a mozilla.cfg at all, if you need to load that from another preferences file anyway? Why not use that directly?!

balls have zero to me to me to me to me to me to me to me to me to

earthlng avatar Aug 02 '17 16:08 earthlng

PS: WebExtensions are locked out of about:config internals

except https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/privacy

earthlng avatar Aug 02 '17 16:08 earthlng

You can just let it apply to all profiles or you can set different prefs for different profiles, switch on environment variables, prompt for things, etc.

Interesting, thanks, I never thought about that. I should play with it sometime. Probably looking at the source code for the WE privacy API and locking all those, wouldn't be a bad idea.

earthlng avatar Aug 02 '17 16:08 earthlng

I took the 2017-07-09 ghacks-user.js. Extracted all lines with string "user_pref". Removed the double slash comment prefixes to make all user_pref calls active. Removed 25 duplicative parrot sets and one duplicative set of urlclassifier.trackingTable. Then I replaced user_pref with lockPref. Result: 593 unique lockPref() sets. Which I put into a FF54 autoconfig file.

Three calls threw exceptions:

lockPref("security.sandbox.content.level", "donotuse");
lockPref("dom.ipc.plugins.sandbox-level.default", "donotuse");
lockPref("dom.ipc.plugins.sandbox-level.flash", "donotuse");

So I changed those illegal values to non-default integer values and tried again. Browser started without error dialogs. I used an extension to extract type and values for those 593 prefs, reading from getBranch(''). Then compared that to what I set. Looks like everything took.

I don't think this proves that there are zero issues using lockPref on any of the prefs in your user.js. There could still be an issue with a certain pref or particular value.

Did that comment about some prefs' values being ignored if changed via prefs.js and user.js ring a bell? I think I read Mozilla was doing something like that to reduce the chances of unexpected tampering with important ones, but I don't remember where I read that. Maybe it is no longer even done.

Theemim avatar Aug 02 '17 16:08 Theemim

Thanks @Theemim! Really glad you found us here, we need more people like you around here ❤️ #nohomo xD

earthlng avatar Aug 02 '17 16:08 earthlng

looking at the source code for the WE privacy API and locking all those, wouldn't be a bad idea.

https://dxr.mozilla.org/mozilla-central/source/toolkit/components/extensions/ext-privacy.js

edit: There also seems to be a 'privacy.services' property which isn't documented just yet

earthlng avatar Aug 02 '17 16:08 earthlng

in my book an APP or system directive should always override a user one

yeah I agree but I don't understand why pref() in cfg doesn't allow a user.js to overwrite it - you can change it in about:config but not from user.js?! why?. Makes no sense to me. If an admin wants to lock prefs that totally makes sense but the other functions/methods are just confusing to me.

I am of course going on the word of @berrythesoftwarecodeprogrammar

I tried it myself today and can confirm what he wrote.

earthlng avatar Aug 02 '17 17:08 earthlng

https://mike.kaply.com/2012/03/16/customizing-firefox-autoconfig-files/ has some more interesting information

earthlng avatar Aug 02 '17 18:08 earthlng

@earthlng user.js, that is in profile folder is not processed the last.

crssi avatar Aug 02 '17 19:08 crssi

privacy.disable_button.*

check your about:config?filter=disable_button, most (?) [or all??] of these get set automatically. His article is from 2012

earthlng avatar Aug 02 '17 19:08 earthlng

@earthlng user.js, that is in profile folder is not processed the last.

yes I know. I meant in the context of the loading order in regards to "config", as described here: https://developer.mozilla.org/en-US/docs/Mozilla/Preferences/A_brief_guide_to_Mozilla_preferences It should, according to that, be loaded after the config file and the prefs.js. The preferences folder in the profile dir isn't even documented anywhere, afaik.

earthlng avatar Aug 02 '17 19:08 earthlng

autoadmin.refresh_interval is used in downloadAutoConfig(). I'm not sure but I think that this only does a re-download of the autoconfig, and not actually run the autoconfig.

earthlng avatar Aug 02 '17 19:08 earthlng

cfg is touched by admins with tools like this.

Atavic avatar Aug 02 '17 23:08 Atavic

PS: WebExtensions are locked out of about:config internals

That is going to be a problem. Especially for me because I like to compare exports and have been using "legacy" extensions for that. Alright then... bananas! See what you started? I meant Plan B. Which is https://github.com/Theemim/GeckoPrefsExporter. I'm totally open to alternatives though. I know you are diffing things. How are you going about it?

Theemim avatar Aug 04 '17 10:08 Theemim