Customizing Firefox - Disabling Safe Mode

NOTE: None of the methods documented in this post work anymore. The safe mode dialog was changed and I can find no way to prevent it from displaying.

I have one more post planned about customizing Firefox with add-ons and the CCK Wizard, but I wanted to get this out in the mean time.

A lot of people ask how to disable safe mode in Firefox in an enterprise environment. This post will tell you how to do it with an add-on.

In my previous post about Integrating Add-ons into Firefox, I talked about putting add-ons into the distribution/bundles directory. The important thing to realize about putting add-ons into this directory is they become a part of Firefox. They are not disabled when Firefox is placed into safe mode (and they shouldn't be!). So we can build an add-on that disables safe mode and by placing it here, it will always be executed.

Unfortunately, we can't completely remove the concept of safe mode. The code that makes safe mode happen is in C++ startup code, so we can't mess with that. But we can make it so that when the safe mode dialog appears, it simply is ignored and the browser is restarted. We do that by overriding the safe mode dialog and forcing it to press the "Make Changes and Restart" button without actually making any changes.

This is a very simple add-on that will consist of two files. I'll tell you exactly where to put them and where to name them.

Note: There is no need for an install.rdf when you put add-ons in distribution/bundles. (I just discovered this.) Also, it doesn't matter what the directory is called under bundles.

chrome.manifest goes in distribution/bundles/disablesafemode and looks like this:

content disablesafemode content/

overlay chrome://browser/content/safeMode.xul chrome://disablesafemode/content/safeMode.xul

safeMode.xul goes in distribution/bundles/disablesafemode/content and looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<dialog hidden="true" id="safeModeDialog" onload="onOK()"/>
</overlay>

You can test it by starting Firefox with the -safe-mode parameter or holding down the shift key on Windows or option key on Mac. You'll see the safe mode window show up for a second (sized very small) and then the browser will restart.

33 Responses to “Customizing Firefox - Disabling Safe Mode”

  1. Ian Thomas (@ianmthomasuk) April 10, 2012 at 4:16 pm #

    Why would you want to disable safe mode? If you just want to force the user to run particular add ons, then why not just have those add-ons in the distribution/bundles directory.

    The other features of safe mode are all about resetting to factory defaults. Would those defaults include any CCK customisations? If not, then they probably should.

    • Mike Kaply April 10, 2012 at 4:35 pm #

      > Why would you want to disable safe mode?

      "Ours is not to question why, Ours is but to do and die."

      People ask me how to do things, I show them how to do them :)

      > If you just want to force the user to run particular add ons, then why not just have those add-ons in the distribution/bundles directory.

      I agree. That would be the right thing to do. But I also know there are cases where add-ons are placed in the browser in other ways than that and you don't want a user to be able to disable them via safe mode. This solves that problem.

      > The other features of safe mode are all about resetting to factory defaults. Would those defaults include any CCK customisations? If not, then they probably should.

      It depends on how the CCK is installed. If you reset prefs, it would reset the CCK prefs and cause it to firstrun again.

  2. Ian Thomas (@ianmthomasuk) April 10, 2012 at 6:32 pm #

    > “Ours is not to question why, Ours is but to do and die.”

    > People ask me how to do things, I show them how to do them :)

    I disagree. As a web developer, clients often ask me to implement strange solutions. Often, I find I can offer better suggestions if I just ask them why they want to do something. (of course if the answer is something like "my manager said so" or "corporate policy" then you've just got to go ahead and implement the sub-optimal solution anyway).

    • Mike Kaply April 10, 2012 at 7:21 pm #

      I'll certainly recommend better solutions, but if a customer wants something done and they think they need it, I'll build it for them.

      The core problem with safe mode is that Mozilla made it too easy. If it was just a command line option, I'd be fine with it.

      The problem is all it takes is holding down the shift key to enter safe mode on Windows.

      This means that even someone who doesn't have access to the command line can enter safe mode.

      So if you have a kiosk, shift can be held when it restarts. Or you can mess with other types of locked down machines.

      I should be able to customize a machine and prevent a user from messing with it.

      • pd April 11, 2012 at 7:00 am #

        Just out of curiosity though, what does safe mode give a kiosk user that normal mode doesn't? Do some kiosks use an add-on(s) to monitor time or data usage for charging users? I've only ever seen that done with platform-level custom software.

        • Mike Kaply April 12, 2012 at 3:13 pm #

          The issue would be somehow using safe mode to hack a kiosk. Perhaps to reset preferences, or disable things or something.

          I understand there are better ways to lock down a kiosk, but you want to prevent as much as possible.

          (and there are entire sites dedicated to hacking kiosks)

  3. Stuart Ballard April 13, 2012 at 11:11 am #

    I have a definite use case for disabling safe mode: I use Selenium Webdriver for testing websites, and it causes repeated Firefox windows to pop up while I'm trying to do other work. If I happen to have Shift held down at the time the firefox window pops up, it opens in Safe Mode and selenium won't function. It would be very useful if Selenium could launch Firefox with Safe Mode disabled!

    (I'm linking this blog entry from the selenium bug on this issue, http://code.google.com/p/selenium/issues/detail?id=1706#makechanges, in case it is helpful to the selenium devs...)

  4. Klaus Azesberger April 20, 2012 at 9:52 am #

    Yes we recently ran into this problem with webDriver and Firefox too. you get something like this:
    org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
    *** LOG addons.xpi: startup
    *** LOG addons.xpi: Skipping unavailable install location app-system-local
    *** LOG addons.xpi: Skipping unavailable install location app-system-share

    i will try this workaround within the next days, but for now I'll enjoy my much deserved weekend :>

  5. Chad Burt May 10, 2012 at 12:35 pm #

    How would I go about doing this on OS X? I can't find any distribution/bundle folder.

    • Mike Kaply May 10, 2012 at 12:37 pm #

      The distribution/bundles directory doesn't exist by default on Firefox.

      You can just create it in the directory where the Firefox executable is located. On Mac that is:

      /Application/Firefox.app/Contents/MacOS

  6. Chad Burt May 10, 2012 at 12:56 pm #

    I've put the xul file under ./MacOs/disablesafemode/content/safeMode.xul but that isn't working.

    I think it can't find the xul file. If I point my browser to chrome://disablesafemode/content/safeMode.xul it cannot find the file. If I enter chrome://browser/content/safeMode.xul it finds that one. Would chrome.manifest need to reference safeMode.xul differently on OS X?

    Thanks

    • Mike Kaply May 10, 2012 at 1:02 pm #

      The XUL file needs to be under MacOS/distribution/bundles/disablesafemode/content/safeMode.xul.

      Then you should be able to reference it.

  7. Chad Burt May 10, 2012 at 1:19 pm #

    Hi Mike. Thanks for the quick replies. Sorry to be a pest, but it's still not working for me. Looked over and over this for typos.

    I still get a 404 on chrome://disablesafemode/content/safeMode.xul

    This is my setup:

    $ less MacOS/distribution/bundles/disablesafemode/content/safeMode.xul

    $ less MacOS/chrome.manifest

    manifest components/binary.manifest

    content disablesafemode content/

    overlay chrome://browser/content/safeMode.xul chrome://disablesafemode/content/safeMode.xul

    • Chad Burt May 10, 2012 at 1:20 pm #

      Ah, looks like the xml won't go through. Probably isn't that helpful for debugging anyways though.

    • Mike Kaply May 10, 2012 at 1:21 pm #

      So close :)

      The chrome.manifest goes in distribution/bundles as well.

      You might check my latest post - http://mike.kaply.com/2012/05/10/customizing-firefox-extensions/

      It gives some more detail on putting stuff in distribution/bundles

      • Mike Kaply May 10, 2012 at 1:21 pm #

        Sorry, distribution/bundles/disablesafemode

        • Chad Burt May 10, 2012 at 1:31 pm #

          Thanks! It looks like the bundle is registered. I don't get a 404 browsing to chrome://disablesafemode/content/safeMode.xul anymore.

          Unfortunately it doesn't seem to prevent the safemode popup from showing when running selenium tests like I was hoping. The combo of TotalTerminal, Selenium, and Firefox seems to always trigger safe mode. I'll keep digging for an hour and report back, otherwise I'm giving up :(

          • Chad Burt May 10, 2012 at 1:44 pm #

            So.. I'm no closer to getting this working. The extension seems to be there but if I hold down option when starting firefox I still get the safe mode modal.

            ... But I did solve my problem with my selenium tests and TotalTerminal. TotalTerminal allows you to bring up a fullscreen terminal using a hotkey. I have KeyRemap4Macbook installed and configured to translate the eject key to Command+option+shift+whatever as my hotkey in TotalTerminal. The option key was what was causing the problem as I would use the terminal to start my tests, then press eject again to exit the terminal. I just ended up binding eject and TotalTerminal to F13 and all is well.

            Sorry if that's a lot of detail, but I figured if I wound up on this page trying to solve this problem, someone else might too!

  8. Jeff Kouzmanoff May 25, 2012 at 2:31 pm #

    Thank you. Works great. I can see FF restarting over and over until I release the shift key.

    This is a necessity for Windows 7 where you use the shift key to launch a new instance of applications pinned to the taskbar.

    (Edit suggestion, copy the instructions for creating the subdirectories here so it's all in one spot.)

  9. Richard June 24, 2012 at 11:27 am #

    I followed the instructions on OS X, Firefox 13.0.1 and when I start FF with the Option key pressed, FF crashes and I get the crash reporter window. If I start FF without Option pressed, it starts as usual. Any ideas?

  10. Ben Tube August 21, 2012 at 6:03 am #

    Great post!!!
    Very useful !

  11. Sky Nelson September 10, 2012 at 6:18 pm #

    Unfortunately, you lost me at the line:

    chrome.manifest goes in distribution/bundles/disablesafemode

    because that "distribution" directory does not exist. Apparently I have to create it (?) but where do I create it? Can you be more explicit about this? I guess I don't know as much as I thought! lol

    I am on Windows 7.

    • Mike Kaply September 10, 2012 at 9:35 pm #

      Yes, you create the distribution directory in the same place as the Firefox executable.

  12. Marc September 17, 2012 at 5:06 pm #

    Hello Mike,

    i'm from Germany and build currently a Windows-Kiosk-Terminal with Firefox. My Question: Can you tell me exactly what i have to do ?

    1.
    Create a folder named 'distribution' in the folder where the firefox executable is (e.g. C:\Progam Files\Mozilla Firefox\distribution)

    2.
    Create a folder named 'bundles' in the 'distribution'-folder

    3.
    Create a folder named 'disablesafemode' in the 'bundles'-folder

    4.
    Create a file named 'chrome.manifest' and put

    'content disablesafemode content/

    overlay chrome://browser/content/safeMode.xul
    chrome://disablesafemode/content/safeMode.xul'

    into it

    5.
    Create a folder named 'content' in the 'disablesafemode'-folder

    6.
    Create a file named 'safeMode.xul' and put

    '

    '

    into it.

    Is is right ? I have done so an it will not work. Can you help me ?

    Greets from Germany,
    Marc

    • Mike Kaply October 6, 2012 at 11:18 pm #

      Unfortunately it appears that the safe mode dialog has been modified and there is no way to prevent entering safe mode.

      I'm still researching to see if I can figure out a new way.

  13. trlkly October 26, 2012 at 8:05 pm #

    Easy solution. Don't disable safe mode, just put all the same addons that prevent modifying things in regular mode in that directory you mention. That way Safe Mode is identical to regular mode.

    • Mike Kaply January 20, 2013 at 3:25 pm #

      Totally agree.

      But if you are installing third party add-ons, some of them don't work properly in the distribution directory.

  14. Bill January 3, 2013 at 12:04 pm #

    I've used an add-on to hide the help menu option. Is there any way to prevent safemode while holding shift and restarting?

  15. Monty January 18, 2013 at 3:31 pm #

    Thanks a lot for this post Mike. Do you have any steps for the latest version of FirefoxPortable? The steps above doesn't seem to work on it.

    • Mike Kaply January 20, 2013 at 2:54 pm #

      I don't work with FirefoxPortable at all, so I have no idea. Sorry.

  16. webgeloggt January 27, 2013 at 3:11 am #

    Hi Mike,

    with following changes (http://webgeloggt.blogspot.de/2012/09/customizing-firefox-disabling-safe-mode.html) your great Add-on is functional again.

Trackbacks/Pingbacks:

  1. Disabling Safe Mode in Firefox 17 | Mikes Musings - January 11, 2013

    [...] an earlier post, I showed how to disable safe mode, but unfortunately that method doesn't work anymore. I've since [...]

Leave a Reply:

Gravatar Image