Keeping Firefox clean

Message
Author
User avatar
b3ta
Posts: 64
Joined: Mon Aug 20, 2018 4:34 am

Keeping Firefox clean

#1 Post by b3ta »

This might be of use to those who have a similar use case to me.

I want a Firefox profile that stays "clean" ­— one that doesn't store anything between runs. I thought I had it set up properly, only to discover that even if I set it to delete "everything", the profile directory continues to grow over time.

After spending ages reading release notes I eventually decided to use the bigger hammer approach: just start over each time, but with all my settings and extensions.

I use the command line, so if someone wants to explain how to get it integrated into the various desktop paradigms, feel free to share. I suppose the next question is which extensions should be installed ;-)



Setting it all up

- Create the master profile: firefox -createprofile "CLEAN_MASTER $HOME/.mozilla/firefox/profiles/CLEAN_MASTER"
- Run the first time: firefox -no-remote -P CLEAN_MASTER
- Set up all the extensions you use and make all the configuration changes you want. It is important to ensure that nothing (extensions included) gets updated automatically. See below for more on dealing with Firefox or extension updates.
- Quit Firefox.
- Create a backup:

Code: Select all

cd $HOME/.mozilla/firefox/profiles/
tar czvf CLEAN_MASTER.tgz CLEAN_MASTER
- Create a script in your path called rff to run Firefox. I run it from the command line, but someone may want to write up how to create a .desktop file for this and integrate it into the menu of whichever desktop you use.

Code: Select all

#!/bin/bash

cd $HOME/.mozilla/firefox/profiles
rm -Rf CLEAN_MASTER
tar xzvf CLEAN_MASTER.tgz
firefox -no-remote -P CLEAN_MASTER
Updating Firefox

The reason the rff script starts by replacing the existing profile (instead of deleting it at the end) is that you'll have to recreate the .tgz file after you've made any changes, such as updating an extension. It is of course up to you to ensure that the only thing you do in such an update session is only those updates, as otherwise your profile will grow exactly as in the way which led me to set up all of this in the first place.

Note that you'll have to go through the same process after a Firefox update, as it can do all manner of things to its profiles.ini and installs.ini files, and you want those changes to take into account your CLEAN_MASTER profile as well.

Jakob77
Posts: 652
Joined: Thu Feb 09, 2023 3:09 am

Re: Keeping Firefox clean

#2 Post by Jakob77 »

b3ta wrote: Mon Apr 28, 2025 12:21 pm I thought I had it set up properly, only to discover that even if I set it to delete "everything", the profile directory continues to grow over time.

After spending ages reading release notes I eventually decided to use the bigger hammer approach: just start over each time, but with all my settings and extensions.

I use the command line, so if someone wants to explain how to get it integrated into the various desktop paradigms, feel free to share.

Thank you for an interesting post. :-)
I don't understand it well enough but I like the way you think about handling as much as possible from the outside by Terminal command.
If someone wants to make advanced Terminal commands work by desktop icon in Xfce I can recommend this subject:
viewtopic.php?t=75323

Have you looked deeper into what the exact content is of the files that Firefox is growing and you don't like.?
Can you suggest some specific sub folder names to keep an eye on.?

User avatar
b3ta
Posts: 64
Joined: Mon Aug 20, 2018 4:34 am

Re: Keeping Firefox clean

#3 Post by b3ta »

Jakob77 wrote: Mon Apr 28, 2025 3:37 pm Have you looked deeper into what the exact content is of the files that Firefox is growing and you don't like.?
Can you suggest some specific sub folder names to keep an eye on.?
The reason I settled on this approach is that each profile directory tree is effectively one large data base, with the files depending on each other. You can spend days figuring it all out, then they change things in an update.

For example, for years there was no installs.ini file, and then when it appeared it also changed the format of the profiles.ini file. Yes, that is at a level higher than the profile(s), but the concept is the same. I understand why the things change, but unless you're deeply involved it simply takes too much time to be sure you're not breaking something.

From my perspective, this approach may feel like work (and it is), but it's a lot less hassle than trying to sort it out the other way, as it is guaranteed to be as complete as their own upgrade mechanism is.

Of course, you could just give up and let it do its thing.

User avatar
CharlesV
Global Moderator
Posts: 7351
Joined: Sun Jul 07, 2019 5:11 pm

Re: Keeping Firefox clean

#4 Post by CharlesV »

Jakob77 wrote: Mon Apr 28, 2025 3:37 pm
Have you looked deeper into what the exact content is of the files that Firefox is growing and you don't like.?
Can you suggest some specific sub folder names to keep an eye on.?
On my systems (which kill ALL data when closed - except for 3 websites), the big areas of retention were in the storage/permanent/chrome/idb folder. You have to make sure you clear for all time and all of it - these are site settings for locations you visit and keep / contain a lot of varied settings - and it is not unusual to find 500mb to over 4gb in there for systems that do not cleanup
*QSI = Quick System Info from menu (Copy for Forum)
*MXPI = MX Package Installer
*Please check the solved checkbox on the post that solved it.
*Linux -This is the way!

User avatar
j2mcgreg
Global Moderator
Posts: 6813
Joined: Tue Oct 23, 2007 12:04 pm

Re: Keeping Firefox clean

#5 Post by j2mcgreg »

I will add that when ever I use Firefox and even though it is configured to never remember history, I always go in after and clean it out manually.
HP 15; ryzen 3 5300U APU; 500 Gb SSD; 8GB ram
HP 17; ryzen 3 3200; 500 GB SSD; 12 GB ram
Idea Center 3; 12 gen i5; 256 GB ssd;

In Linux, newer isn't always better. The best solution is the one that works.

User avatar
DukeComposed
Posts: 1399
Joined: Thu Mar 16, 2023 1:57 pm

Re: Keeping Firefox clean

#6 Post by DukeComposed »

b3ta wrote: Mon Apr 28, 2025 3:58 pm Of course, you could just give up and let it do its thing.
Another option is to use Firejail, which allows for process sandboxing and lets you use a browser without permanently writing changes to the profile. You could also put everything into source control and revert any changes made. There are probably more ways to do it, and different approaches to this problem, and they all boil down to different methods of finding ways to go back to a known-good initial state.

Jakob77
Posts: 652
Joined: Thu Feb 09, 2023 3:09 am

Re: Keeping Firefox clean

#7 Post by Jakob77 »

b3ta wrote: Mon Apr 28, 2025 3:58 pm Of course, you could just give up and let it do its thing.
In the big picture I am mostly naive enough to trust Firefox but I still find your point of view very interesting. :-)

If you go by script you can use all the Terminal commands you want.

Maybe erasing a folder or two when closing Firefox could be another hammer. If you just know what folder to hit, and the procedure is forward compatible with Firefox.



Or maybe even a bigger hammer by making a new MX install and update Firefox completely but before you start using it you pack all of ~/.mozilla into a file "firedatapack.zip"

And then the script for opening Firefox will start by making sure ~/.mozilla/firedatapack.zip is the only file in the folder.
And then it will unpack it and start Firefox pure as new.
And when Firefox is closed the script will automatically erase all files except the pack-file.

I can have overlooked some implications but I imagine before an update you have to unpack and afterwards make a new pack-file.

I guess for some it might be too slow for opening Firefox, and maybe it won't even work well.?
However if it works, it will clean.! :-)

Stuart_M
Posts: 692
Joined: Wed Aug 07, 2019 7:10 pm

Re: Keeping Firefox clean

#8 Post by Stuart_M »

After reading the original post I thought it would be easier and simpler to just copy a "clean" Firefox profile that is kept with your data files somewhere. Then copy that "clean" profile in place of the Firefox "used" profile that increases in size.

I present two ways to do this, using the following criteria in this example:
  • Used MX-23.5 Xfce
  • The saved "clean" Firefox profile is the firefox directory that is under the ~/.mozilla directory. This of course includes the installs.ini and profiles.ini files.
  • The "clean" firefox directory is kept in the ~/Documents/ directory and the name that Firefox assigns to the profile is kept as is.
  • The user's name used is "b3ta".

In this example I want to start using the "clean" profile when I first log in to the desktop at the start of every day. I boot up ever day so I would make an entry in "Session and Startup" to run a command that will copy the "clean" Firefox into the .mozilla directory every time I log in.

In this case no script is needed. This is what will happen when the command in "Session and Startup" is run:

1. A rsync command is used that will copy the "clean" Firefox profile kept in the ~/Documents/ directory to the ~/.mozilla/ directory.

2. Because the rsync command uses the "--delete" option, any files that are in the destination directory (~/.mozilla) but NOT in the source directory ("clean" profile), will be removed (deleted). This eliminates the need for using the "rm" command.

Note that I did not use the copy command because "rsync" can delete any files that exist on the destination that do NOT exist on the source, which in this case is the "clean" profile. If the copy command were to be used then I would have used the "rm" command first. Not a big deal, it's just easier using rsync.

3. The "Session and Startup" command would be something like the command in the below code window. I tested this and works fine (using "Demo" as the user name):

Code: Select all

rsync -ar --delete /home/b3ta/Documents/firefox /home/b3ta/.mozilla/
Now every time you log into your account you will have a "clean" Firefox profile to use. If you keep the computer powered on all the time then I could just create a cron job to make the copy at any interval and time period that Firefox would be closed, e.g. when sleeping, etc. Maybe run once a week or so.




This is how I would do the same as the above except using a compressed zip file as the source, like was used in Post #1.

If a compressed zip file for the "clean" firefox directory (profile) is used, then the command to use in Session and Startup would be something like the command in the below code window.

Regarding the command:

1. No dash is needed before the "xf" options in the tar command in case anyone thinks I forgot it...
2. First the ~/.mozilla/firefox/ directory will be be removed (deleted).
3. Then the tar command will decompress the .gz file and then install the "clean" profile to the ~/.mozilla/ directory recursively.

This is the command that would be put in the "Session and Startup" command field. I tested it and it works like a charm:

Code: Select all

bash -c "rm -r /home/b3ta/.mozilla/firefox && tar xf /home/b3ta/Documents/firefox.tar.gz -C /home/Demo/.mozilla"

Jakob77
Posts: 652
Joined: Thu Feb 09, 2023 3:09 am

Re: Keeping Firefox clean

#9 Post by Jakob77 »

This is a good discussion about safety.
We don't even have to do any more.
When the firefox-crackers read it then they will have an acute nervous breakdown and the police will be able to peacefully pick them up from the emergency room tomorrow, where they will sit depressed and introverted while resenting their poor lifestyle. ;)

I don't know how much of it I want to implement IRL.
If Firefox is updated when ~/.mozilla is packed I feel sure it can all crash completely.
So it will be needed to take percussion before updating and that is a downside.
A delay in updating can also be a safety problem.
Further more about updating. I am not sure if Firefox might run something automatically in the background that will be missing and cause errors the next time Firefox is opened with the old database.?
What ever we want to do with a bigger hammer it might be wise to ask Mozilla before implementing it and expecting it to be a stable solution on a computer for serious work. IMO :-)

User avatar
b3ta
Posts: 64
Joined: Mon Aug 20, 2018 4:34 am

Re: Keeping Firefox clean

#10 Post by b3ta »

Thank you for everyone's input. A few comments, given my use case.

Firejail is very useful and highly recommended, with these two caveats:

- Those times when I am upgrading extensions or when Firefox has been upgraded, I actually do want changes to be made to the profile, so then I would not run Firefox via Firejail.
- Using Firejail should be part of a defence in depth approach. Who knows if one of its bugs bites you because you depend on it alone? Its latest set of release notes (0.9.74) lists 13 bug fixes, including "various resource leaks" and a race condition. This is not a criticism of Firejail — by all means use it! — but it is a very complex piece of software working at a very low level as root.

The reason I do not include files outside of the profile directory is that they can (and in the case of profiles.ini and installs.ini they do) impact profiles. Because I have many different profiles, I don't want to mess any of them up without realising it.

Using rsync could be very useful, especially if your drive is some form of silicon, where extra writes shorten its life considerably (but see below). The only thing with rsync is to be sure that the arguments you specify will do exactly what you want — it's one of those commands that really punishes a bad memory. It does of course have the benefit of being able to tell it not to over-write or delete specific files in the destination (such as cert_override.txt in the relative root of the profile directory), but then we're back at keeping things between runs and also having to know what's going on in the profile directory tree.

Speaking of arguments:

- With rsync, -a implies -r.
- The reason I included -f in my rm command is that experience has forced me to alias rm to rm -i, and in this instance I don't want to be queried for every read-only file.
- I used z with tar because I didn't read the release notes when tar became clever enough to figure out which compression algorithm was used ;-) I've also spent time on non-GNU Unices where these niceties don't exist, so it's force of habit, but useful to know I don't have to remember things like j for bzip2 and J for xz when using GNU tar.

Doing the profile replacement automatically at log-in won't really help me, as I close Firefox when I use the PC for processor- or memory-intensive tasks and I don't want the clean profile to remember things between runs.

I might move to using rsync to save some silicon, but I'm honestly not sure how helpful that will be, as Firefox likes to save files that it opened, even if the contents didn't change (then you'd need to use --ignore-times and --checksum). It will also update many files with things like last-run information, in which case it's going to be over-written, even if that's the only change. I'm happy to be proven wrong, as I'm not going to invest the time to check ;-)

Again, thank you all for your input.

Post Reply

Return to “Software / Configuration”