Customizing Firefox – Hiding Private Browsing – Continued

I was reminded that there is one more way to get to private browsing – typing about:privatebrowsing in the URL bar. This gives us a chance to talk about another thing you can do in chrome.manifest – override.

Override allows us to completely replace a built in URL in Firefox with another URL. I use this in my Rebrand extension to override certain images and other things. We can also use it to override built in URLs like about:config and about:privatebrowsing. There is a catch though.

When a URL begins with about, that’s not the true URL; all about URLs map to a corresponding chrome URL. The easiest way to see this mapping is by looking at AboutRedirector.cpp or nsAboutRedirector.cpp. These files contain the mappings of just about every about command to a corresponding chrome URL. For about:privatebrowsing, that’s chrome://browser/content/aboutPrivateBrowsing.xhtml

So to override the about:privatebrowsing, we just need to give it a suitable replacement. Put this line in your chrome.manifest:

override chrome://browser/content/aboutPrivateBrowsing.xhtml data:text/html,Disabled

You’ll see the word “Disabled” when you type about:privatebrowsing.

Alternatively, you could create your own custom HTML file and place it in your content directory and point to that:

override chrome://browser/content/aboutPrivateBrowsing.xhtml chrome://myextension/content/myfile.html

This method can be used to override just about any of the about pages. For instance, to override about:config, do this:

override chrome://global/content/config.xul data:text/html,Disabled

Using override is a powerful way to prevent access to things you don’t want your users messing around with.

Please note: I reserve the right to delete comments that are offensive or off-topic.

Leave a Reply

Your email address will not be published. Required fields are marked *

21 thoughts on “Customizing Firefox – Hiding Private Browsing – Continued

  1. Until someone opens a new tab, pops open the Web Console and pastes in
    window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIWebNavigation).QueryInterface(Components.interfaces.nsIDocShellTreeItem).rootTreeItem.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindow).gPrivateBrowsingUI.toggleMode();

    So I guess you’d have to disable the Web Console too, although there’s probably several other clever ways to run JavaScript in chrome context. It seems to me a bit like trying to plug holes in a dike with your fingers.

    • Yes, you probably would disable the Web Console.

      It’s also possible to completely remove private browsing by simply overriding gPrivateBrowsingUI, but I haven’t gotten into that yet.

      The goal here is to prevent the average user from being able to do these things. Obviously if someone is willing to go to those lengths to get private browsing, more power to them.

      You seem to be arguing that since you can’t do everything, you shouldn’t do anything. If that was the case, every enterprise should use Internet Explorer.

  2. do you have any idea on how to remove the option from the task bar jumplist?(open mozilla, click and hold on the task bar, then move mouse upward)

    • Yes I do.

      There are two preferences you can set to false to remove it.

      Setting browser.taskbar.lists.enabled to false removes everything from the jump list.

      Setting browser.taskbar.lists.tasks.enabled to false just removes the tasks (leaves the history).

      You can’t remove just private browsing.

      All these prefs take effect immediately, so you can test them in about:config

      • I’ve done some googling (and probably not enough).. Anyways, can I set either of these preferences to false via extension? If yes, please share.

        • yes. preferences are set via an extension by putting them in defaults/preferences/prefs.js and then just setting them as:

          pref(“foo”, false);

          • I’ve tried this and for some reason

            pref(“browser.taskbar.lists.enabled”, false);

            yet if i attempt to set it to a string it will work.. any thoughts?

            ex:
            pref(“browser.taskbar.lists.enabled”, “HelloWorld”);

          • I honestly have no idea. browser.taskbar.lists.enabled is definitely a preference.

            Making it a string would just cause the code to fail (which is OK in this case).

            What version of Firefox and where are you setting the pref?

            Did you verify the new value is used in about:config?

          • Yes I have verified that it changes if I use a string value. However, if i use a bool value such as false it doesn’t change.

            I’m testing on FF 14.0.1, on my local computer.

            • I have to be honest, I’m at a loss.

              When you create a new profile, does it say “Boolean” in about:config?

      • Could you possibly edit WindowsJumplists.jsm (the text version) to comment out the lines that create that link in the jumplist?

        • That would require modifying the actual Firefox install which is something I don’t do with the CCK. There’s really no good way to modify this JSM.

          What is really needed is a way to globally disable private browsing.

          • I wonder why I can’t disable the -private-window option in the command line? I tried searching for the relevant code, but I’ve proven that the lines in nsBrowserContentHandler.js that check for the presence of it do absolutely nothing. Is the functionality built into a binary component in a DLL file somewhere? (version 21.0 for windows, release channel)

    • So it appears something got broken in Firefox 14.

      Can you try putting your files in defaults/preferences instead of defaults/prefs (you’ll have to create the directory).

      I’m trying to get to the bottom of what exactly happened.

  3. Hey Mike,

    thanks a lot for your guides on how to disable private browsing!
    I know, these posts are already half a year old, but I still have
    a question to ask:
    How can I disable the possibility to clear the history by users?
    I’ve searched on your links, google etc, but it seems like I’m
    to stupid to find the correct prefs to do so.

    Due to the fact, that hiding/disabling the privatebrowsing using
    chrome.manifest and ‘browseroverlay,xul’ is working pretty well,
    it would be great to hide/disable cleaning of history in that way
    as well. Could you please help me out?

    Thanks a lot in advance!

    • Disabling the clearing of history requires quite a view things. Besides handling the basic menu item and key stroke, you also have to handle the individual deletion of entries from history sidebar and window.

      I’ll be honest, though. Figuring this one out would take a few hours that I don’t have time to spare. My suggestion would be you look through the Firefox code for Tools:Sanitize – that will cover the menus and keystrokes for history. Then you’ll have to overlay chrome://browser/content/history/history-panel.xul and chrome://browser/content/places/places.xul to remove the delete key and the Delete menuitem. That should cover it.

      Hope that helps.

  4. Mike,

    What’s the command needed to override chrome netError.xhtml and add a custom html message? Do I place the command in the url bar and where should I put the custom html message? Can the custom html message be a black page?

    • I realize my question is somewhat off topic and perhaps I should have asked the question @ http://mike.kaply.com/2013/05/06/dont-unpack-and-repack-omni-jar/ and if you prefer then you or I can move this post there.

      I tried using the following command in the url bar:

      override chrome://global/content/netError.xhtml data:text/html,Disabled

      And there was no change to the neterror message or icon and no Disabled message when I then entered the about:neterror command.

      When I entered: override chrome://global/content/netError.xhtml the same web page opened up as when I entered: about:neterror command so at least that portion of the command is accurate. I have a vast number of add generating web addresses in my hosts file so my aim is to get rid of the ugly netError message and icon and somehow replace it with a blank white page.