User:Dickvl/Private Browsing disable: Difference between revisions

From MozillaZine Knowledge Base
Jump to navigationJump to search
(moved private browsing disable extension)
(No difference)

Revision as of 05:46, 24 February 2010

Private Browsing

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 code doesn't hide "Tools -> Options -> Privacy" to start PB mode automatically and you need to add code to userChrome.css to do that. The code in userChrome.css also hides the menu entries if the extension is disabled or not installed. Current Firefox versions still process code in userChrome.css if started in Safe_mode. 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]

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 pbs = Components.classes["@mozilla.org/privatebrowsing;1"].getService(Components.interfaces.nsIPrivateBrowsingService);
var oldPM = pbs.privateBrowsingEnabled;
var newPM;
pbs.privateBrowsingEnabled = !pbs.privateBrowsingEnabled;
void(alert('PB is '+((newPM=pbs.privateBrowsingEnabled)?'on':'off')+((oldPM==newPM)?' (failed)':'')));

Add this code to userChrome.css below the @namespace line (only add the @namespace line if it is missing).
See http://kb.mozillazine.org/Editing_configuration#How_to_edit_configuration_files

@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");

/* Hide PB and Sanitize item in Tools menu */
#sanitizeSeparator, #privateBrowsingItem, #sanitizeItem {display:none!important;}

/* Hide AutoStart PB and some History settings in Options > Privacy */
#rememberHistoryDays,#historyDays,#rememberAfter,
#privateBrowsingAutoStart, #clearDataBox {display:none!important;}

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

Copy and paste the full DATA code in the location bar and press the Enter key. Save the file as pbdisable.xpi (version 1.2, updated Feb 23, 2010)
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 [2].

data:application/octet-stream;base64,
UEsDBBQAAAAIAHuYPzw3xI8ySQAAAHwAAAAPABUAY2hyb21lLm1hbmlmZXN0VVQJAAMJxmVLCcZl
S1V4BADoA2QAS87PK0nNK+EsSErJLE5MyknlTM4oys9N1U+GSOjzcvFy5ZelFuUkVkKlrPT1k4ry
y4tTi+CKoHy9itIchCK4kXBlcBGQQl4uAFBLAwQUAAAACAAMa1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4Y13c0fg8zsPc4cqZLcws6tV+vV
MWKgkrAh6LN/3FxV0965YRiqX8FCdh1NAYtSdi0qdUTJWruZqeJSSfRTNfZ+83RYPLcFIyvPdCKL
hyr5GbYp882kdZahcGzflYKhf8xlhC9LnzxO+yiRHjgkyYpRD99meSd/7VVOar+bR+MJ8xsq1jL+
5/EDUEsBAhcDFAAAAAgAe5g/PDfEjzJJAAAAfAAAAA8ADQAAAAAAAQAAAO2BAAAAAGNocm9tZS5t
YW5pZmVzdFVUBQADCcZlS1V4AABQSwECFwMUAAAACAAMa1c8Bng+p3kBAAD9AgAACwANAAAAAAAB
AAAA7YGLAAAAaW5zdGFsbC5yZGZVVAUAA/jIg0tVeAAAUEsBAhcDCgAAAAAADaV2OwAAAAAAAAAA
AAAAAAcADQAAAAAAAAAQAO1BQgIAAGNocm9tZS9VVAUAA6mTCUtVeAAAUEsBAhcDCgAAAAAAWJg/
PAAAAAAAAAAAAAAAAA8ADQAAAAAAAAAQAO1BfAIAAGNocm9tZS9jb250ZW50L1VUBQADx8VlS1V4
AABQSwECFwMUAAAACADbrVc8ZVBE8yoDAADXBwAAHAANAAAAAAABAAAA7YG+AgAAY2hyb21lL2Nv
bnRlbnQvcGJkaXNhYmxlLnh1bFVUBQADvT6ES1V4AABQSwECFwMUAAAACAARp1c8I6u19tYAAAA7
AQAAHAANAAAAAAABAAAA7YE3BgAAY2hyb21lL2NvbnRlbnQvcGJkaXNhYmxlLmNzc1VUBQAD8jKE
S1V4AABQSwUGAAAAAAYABgDKAQAAXAcAAAAA

Byte Shift JavaScript

You can use this JavaScript code to encode (+13) and decode (-13) the file mozila.cfg

/* Paste this file into Firefox's JavaScript console and evaluate it encode or decode the file mozilla.cfg via a byte shift of 13 - dickvl@kb.mozillazine.org */
(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('Shift value:','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();
 }
})();