MozillaZine

User:Dickvl/Private Browsing disable

From MozillaZine Knowledge Base

Here is a simple extension to disable the "Tools -> Start Private Browsing" menu entry and the "Tools > Clear Recent History" menu entry in Firefox 3.5/6.
The extension hides these menu entries and also disables their shortcut keys and should prevent Firefox from entering Private Browsing mode. The CSS code (chrome://pbdisable/content/pbdisable.css) in the extension also hides "Tools -> Options -> Privacy -> Automatically start Firefox in a private browsing session" and the History setting. You can copy that code to userChrome.css if you want these entries hidden if the extension is disabled. Current Firefox versions still process code in userChrome.css if started in Safe_mode. Keep in mind that removing or disabling "Private Browsing" will not make it impossible to delete private data like visited websites (history) or cache. It is possible to clear the cache via "Tools -> Options -> Advanced -> Network" and to clear history in the Library and History sidebar. See also [1]

Contents

Private Browsing toggle test

You can copy and paste this code in the "Tools > Error Console" to test if it is possible to toggle Private Browsing mode before and after you have installed the extension. It should not be possible, but what Firefox shows can be deceiving as it looks a bit buggy to me. You can check if new history is still kept.

var Cc = Components.classes, Ci = Components.interfaces;
var pbs = Cc["@mozilla.org/privatebrowsing;1"].getService(Ci.nsIPrivateBrowsingService);
var prs = Cc["@mozilla.org/embedcomp/prompt-service;1"].getService(Ci.nsIPromptService);
var oldPB = pbs.privateBrowsingEnabled, newPB;
if (prs.confirm(null, "Private Browsing", "PB is "+((pbs.privateBrowsingEnabled)?"on":"off"))) {
pbs.privateBrowsingEnabled = !pbs.privateBrowsingEnabled;
prs.alert(null, "Private Browsing", "PB is " + ((newPB=pbs.privateBrowsingEnabled)?"on":"off") + ((oldPB==newPB)?' (failed)':''));
}

Lock prefs with mozilla.cfg

You can lock some history prefs and reset pref browser.privatebrowsing.autostart to false with this version of the file mozilla.cfg.
Copy and paste the full DATA code in the location bar and press the Enter key. Save the file as mozilla.cfg (updated Feb 23, 2010) and copy the file to the Firefox program folder.

data:application/octet-stream;base64,
PDwaF31/cnM1L29/fISAcn87fX92g26Bcm9/fISAdnt0O26CgXyAgW5/gS85LXNueYByNkgaF3l8
cHhdf3JzNS9vf3yEgHJ/O3V2gIF8f4ZscoV9dn9ybHFuhoAvOS0+RT02SBoXeXxweF1/cnM1L29/
fISAcn87dXaAgXx/hmxyhX12f3JscW6GgGx6dnsvLTlGPTZIGhd5fHB4XX9yczUvfXlucHKAO3V2
gIF8f4Y7cntub3lycS85LYF/gnI2SBoXeXxweF1/cnM1L31/doNucIY7cHlybn9ce2B1goFxfIR7
O3V2gIF8f4YvOS1zbnmAcjZIGhd5fHB4XX9yczUvfX92g25whjtwfXE7dXaAgXx/hi85LXNueYBy
NkgaF3l8cHhdf3JzNS99f3aDbnCGO4Bue3aBdodyO4Bue3aBdodyXHtgdYKBcXyEey85LXNueYBy
NkgaFw==

You need to create a file local-settings.js with this line:

pref("general.config.filename", "mozilla.cfg");

Copy the file local-settings.js to the grefprefs folder or the defaults\pref folder in the Firefox program folder.
Prefs that are locked show as italic with Status is Locked on the about:config page and can't be changed.
For full instructions, see Locking_preferences

Extension code for pbdisable

Copy and paste the full DATA code in the location bar and press the Enter key. Save the file as pbdisable-1.6-fx.xpi (updated Aug 5, 2011)
You can install the extension via "File > Open File" or by dragging the file in a Firefox window.
You can move the extensions folder (pbdisable@mozillazine.org) from the extensions folder in the Profile Folder to the %AppData%\Mozilla\extensions\{ec8030f7-c20a-464f-9b0e-13a3a9e97384} folder or to the extensions folder in the Firefox program folder to make the extension work in all Firefox profiles. If you do that then you can't uninstall, but you can disable the extension. You can also drop the XPI file in that folder and the extension will be installed on the next start of Firefox. You may have to rename the extension to pbdisable@mozillazine.org.xpi to make that work [2].

data:application/octet-stream;base64,
UEsDBBQAAAAIANo4/j43xI8ySQAAAHwAAAAPABwAY2hyb21lLm1hbmlmZXN0VVQJAANskTNObJEz
TnV4CwABBOkDAAAEZAAAAEvOzytJzSvhLEhKySxOTMpJ5UzOKMrPTdVPhkjo83LxcuWXpRblJFZC
paz09ZOK8suLU4vgiqB8vYrSHIQiuJFwZXARkEJeLgBQSwMEFAAAAAgA0zj+PsCJa2J9AQAA/QIA
AAsAHABpbnN0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AABAA7UFUAgAAY2hyb21lL1VUBQADqZMJS1V4
AABQSwECFwMKAAAAAABYmD88AAAAAAAAAAAAAAAADwANAAAAAAAAABAA7UGOAgAAY2hyb21lL2Nv
bnRlbnQvVVQFAAPHxWVLVXgAAFBLAQIeAxQAAAAIAK04/j7R+Jq9vwMAAAoJAAAcABgAAAAAAAEA
AACkgdACAABjaHJvbWUvY29udGVudC9wYmRpc2FibGUueHVsVVQFAAMVkTNOdXgLAAEE6QMAAARk
AAAAUEsBAh4DFAAAAAgAK1IFPwFsJyD+AQAAyQQAABwAGAAAAAAAAQAAAO2B5QYAAGNocm9tZS9j
b250ZW50L3BiZGlzYWJsZS5jc3NVVAUAAxKnO051eAsAAQTpAwAABGQAAABQSwECHgMUAAAACADI
OP4+CDZYfvcAAAB+AQAACwAYAAAAAAABAAAApIE5CQAAdmVyc2lvbi50eHRVVAUAA0eRM051eAsA
AQTpAwAABGQAAABQSwECHgMUAAAACAClOP4+pnD1da4BAABdAwAAGQAYAAAAAAABAAAApIF1CgAA
Y2hyb21lL2NvbnRlbnQvcGJ0ZXN0Lnh1bFVUBQADBZEzTnV4CwABBOkDAAAEZAAAAFBLBQYAAAAA
CAAIAKYCAAB2DAAAAAA=

Byte Shift JavaScript

You can use this JavaScript program to encode mozila.cfg.txt to mozilla.cfg and decode mozila.cfg to mozilla.cfg.txt.

/*
 * Paste this file into Firefox's JavaScript console and click the Evaluate button to run the script - dickvl@kb.mozillazine.org 
 * use a byte shift of 13 to encode the file mozilla.cfg.txt to mozilla.cfg
 * use a byte shift of -13 to decode mozilla.cfg to mozilla.cfg.txt
*/
(function(){
 var Cc = Components.classes;
 var Ci = Components.interfaces;

 var fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
 var stream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream);
 var streamIO = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(Ci.nsIScriptableInputStream);
 var input,output='',i,s,sV=13;

 fp.init(window, "", fp.modeOpen);
 fp.appendFilter("", "*.txt; *.cfg");
 
 if (fp.show() == fp.returnCancel) return;

 stream.init(fp.file, 0x01, 0444, null);
 streamIO.init(stream);
 input = streamIO.read(stream.available());
 streamIO.close();
 stream.close();

 if((s=prompt('Byte Shift value (13 to encode and -13 to decode):','13'))!=null){
  sV=parseInt(s,10);
  for(i=0;i<input.length;i++){output+=String.fromCharCode(input.charCodeAt(i)+sV)}

  fp.init(window,"",Ci.nsIFilePicker.modeSave);
  fp.defaultString="mozilla.cfg";
  if (fp.show() == fp.returnCancel) return;

  var stream=Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
  stream.init(fp.file,0x04|0x08,0644,0);
  stream.write(output,output.length);
  stream.close();
 }
})();