A clean Firefox profile every time

Sometimes, you need a fresh Firefox. One that is exactly as if you had just installed it. Nothing cached, no cookies, clean. Or perhaps you use different Firefox profiles, for different purposes, and don’t want to have to install all your favourite extensions and configuration changes every time you create a new profile. This post describes one way to achieve both those things. While this post tells how to do it in Linux, you could certainly adapt the methods for Windows or whatever. All you need is Firefox, a way to start it, and a scripting language.

The method

The method is simple.

  • create a clean profile using the Profile Manager
  • run Firefox using the new profile
  • configure Firefox as required (configuration and extensions etc)
  • copy the profile every time we want a fresh start

The trick is never to actually use the clean profile itself (except optionally while setting it up); you always take and use a copy. That way the clean profile stays clean.

You can find out how to create and use a new profile using these instructions. If you are using Ubuntu and Unity, you can find out how to run different profiles from the Launcher using these instructions. Only the last step is new, so in the post you are now reading, we will cover how to copy and use the clean profile as needed.

1: Create a clean profile

For the following steps, I will assume you have set up a brand new profile, possibly using these instructions, and that your new profile is called “Clean”. Also, that your new profile is in the default location, namely ./~mozilla/firefox.

After creating “Clean”, start Firefox using that profile, and configure it to your requirements, then close that instance of Firefox.

If you want a completely clean profile with no configuration or extensions at all, then do NOT start Firefox with that profile at all, ever. If you are following these instructions, stop after Step 3.

“Clean” is your pristine profile. It will be copied to a new profile just before starting Firefox; Firefox will actually always be using a copy of of the “Clean” profile, while “Clean” remains untouched.

2: Get the directory name of the new profile.

The new profile will have been created in ./~mozilla/firefox.  Look in that directory to find the names of the new profile’s directory. You can use your favourite file manager or the command line. The name will look something like this:

5wreot6r.Clean

3: Create a script

Create this script using your favourite text editor (e.g. gedit). Save the script anywhere convenient. For the purposes of this exercise, let’s assume you have created it in your home directory and called it CopyCleanProfile.sh.

Substitute your clean profile’s directory name into this script as SRC, of course:

#!/bin/sh
SRC="5wreot6r.Clean"
DIR="~/.mozilla/firefox"

# Create a random profile name
RND=`dd if=/dev/urandom status=none bs=1024 count=1 | tr -cd '[:alnum:]' | fold -w8 | head -n1`
PRF="$RND.ReallyClean"
cd "$DIR"
rm -fr "$PRF" > /dev/null 2>&1
cp -a "$SRC" "$PRF"
firefox --profile "$PRF" --no-remote --new-window
rm -fr "$PRF" > /dev/null 2>&1

--no-remote makes sure that you get a new instance of Firefox, and that no other Firefox instances can open windows or tabs in your clean browser.

--profile specifies the actual path to the profile directory, rather than (as -P does) the name of a profile. This is so that we don’t have to fiddle with profiles.ini.

Make the script executable. Again, you can use your favorite file manager, or do it on the command line like this:

chmod u+x ~/CopyCleanProfile.sh

At this point you can get Firefox with a clean profile by just running that script on the command line. The next step ties the script into the Launcher, so you can get a clean profile using point and click.

4: Add a new entry to the desktop file

Follow as far as Step 2 in these instructions (if you haven’t already) to get to the point where you have a desktop file, locked to the Launcher, that you can edit to add new entries to.

Then edit the desktop file (as per Step 4 in these instructions), but instead of adding an entry that runs Firefox directly, add a new entry like this one:

[Desktop Action Clean]
Name=Clean Profile
Exec=~/CopyCleanProfile.sh

5: All done!

At this point, you should be able to select “Clean Profile” from the Firefox icon in the Launcher. When you do, the script copies your clean profile (“Clean”) to another profile with a random name, then starts Firefox using the copy. As soon as Firefox exits, the script deletes the profile copy.

Leave a Reply

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