Using extra Firefox profiles to make my life better

October 19, 2023

At the moment I have two main browser instances, both using Firefox. My primary browsing is in my customized Firefox, with assorted strict settings and extensions that result in it mostly not running JavaScript, being logged in to places, and so on. Since browsing with JavaScript off can be annoying, I have a second Firefox instance that's my 'just make it work' browser; it runs JavaScript, accepts and gives back all of those cookies, and so on, and then it throws cookies and everything away when I close it.

(I implement this second stock Firefox environment not with a profile but by changing the $HOME environment variable before I run this Firefox. Firefox on Unix helpfully respects $HOME and having the two environments be completely separate avoids various potential problems.)

This second 'JavaScript' Firefox environment is what I normally use when I need to log in to sites I don't like (especially if they want to use JavaScript, which they usually do); I log in, do whatever, and close the browser, flushing my login session along with all of the other cookies. However, for my sins I use a number of websites that require both JavaScript and logins, and that have annoying or painful login procedures. These sites do things such as requiring multi-factor authentication every time with a physical token, or sending email every time I log in (or just a tediously long and slow multi-step login process). As a result I want to log in to them as infrequently as possible, which means keeping their login cookies.

(For some of these sites, I also don't want to casually browse other places while logged in to them, because they have some degree of important privileges. Otherwise, for some sites I could start my JavaScript Firefox environment at the start of the day and only exit it at the end, letting cookies and so on accumulate (only) over the course of the day. It's not perfect, but it is lazy.)

My solution to this is a set of additional profiles in the 'JavaScript' Firefox setup, one per annoying website. Each profile gets a standard set of Firefox addons, of which the critical ones are uBlock Origin and Cookie AutoDelete. In each profile, I set Cookie AutoDelete to keep the necessary cookies for the particular website (or related set of them), and then clean up everything else. Those additional cookies come from various things, including me browsing off that site by following links on it. It generally takes a little bit of initial work to figure out what sites need their cookies retained, but once that's set up, all of these profiles have been stable and trouble-free.

(In theory I could try to put limits of what websites can use JavaScript in these profiles, but in practice it's too much of a pain in the rear.)

In theory perhaps I could use something like Firefox Multi-Account Containers for this, but I prefer separate profiles. They're probably more work to set up in the beginning, but I feel more confident about what they're doing and how various aspects interact with each other. Profiles are definitely completely separate from each other, including for extension settings and so on. Containers, well, it depends.

Sidebar: my usual Firefox addons for these profiles

In addition to uBlock Origin and Cookie AutoDelete, I also add Foxy Gestures (which is a critical part of my Firefox experience), Cookie Quick Manager, and generally Certainly Something (for TLS certificate viewing). Some of these profiles have accumulated additional addons over time, usually ones that mitigate tracking. These days I also install my bookmarklet buttons (for readable and fixed).


Comments on this page:

By Ibrahim at 2023-10-20 05:33:20:

You don't need Certainly Something anymore.

From https://github.com/april/certainly-something/blob/master/README.md :

Note: Certainly Something has been integrated into Firefox 72, and is no longer necessary for viewing certificates.

By Craig McConomy at 2023-10-20 09:21:59:

For firefox, I've been a huge fan of uMatrix - https://addons.mozilla.org/en-CA/firefox/addon/umatrix/

It's ideal for users who want a powerful and efficient lens through which to accept and deny resources by type and source (javascript, iframes etc per source host) and I think you might find you like it too.

By Bryan at 2023-10-20 11:18:13:

In my experience, sharing HOME will actually work fine as long as you use a different LOGNAME environment variable for each profile. Firefox uses that to find a running instance, and fails if what it finds is from a different profile; and unlike HOME, almost no programs use LOGNAME for anything else that matters. A sample script might look like this:

#!/bin/sh
export LOGNAME=firefox-profile-javascript
exec firefox -P javascript --allow-remote --new-window "$@"

One should then be able to use that script to open a blank window or a URL in the instance of one's choosing.

For those who don't know, "bubblewrap" (/usr/bin/bwrap) is a good way to isolate processes on Linux. I currently run Firefox using a profile on an overlay filesystem, made up of a tmpfs above a read-only directory with some symlinks to files in a writable subdirectory (prefs.js and maybe some of the SQLite databases; this requires using bwrap --cap-add to hang onto user-namespace-admin privileges while running a wrapper script that sets up the mounts and then runs an unprivileged Firefox via setpriv). It turns out Firefox will always import a bookmarks.html if there's no places.sqlite; combined with a filter script referenced in .gitattributes (to remove cruft such as timestamps), the profile stays clean enough to store in git.

By Ian Z aka nonbrowser at 2023-10-20 17:28:20:

How do you actually control which profile to use when starting a new instance?

I know of 3 ways that work for sure, but each requires additional mousing or typing:

  • -P PROFILE-NAME on command line
  • -ProfileManager on command line
  • about:profiles and click on Start New Browser button

On the other hand, when I look at the profiles.ini file I see a couple of flags -- Default and StartWithLastProfile -- that should help, but I have never been able to determine their exact effect.

By Bryan at 2023-10-20 20:28:40:

Ian, I can't answer the specific question of how Chris does it, but I'd generally expect people to use scripts, hotkeys, desktop/menu icons, or the like, to pass either -P followed by a profile name or --profile followed by a directory path. --profile is useful if you want to put it under a non-default location (like $XDG_CONFIG_HOME or on a tmpfs or overlayfs); when using it, "mkdir" is sufficient to create a profile, and profiles.ini is ignored. Give the scripts short names like "ffoxj" to save on typing, and remember to have them override $LOGNAME when loading a non-default profile (to avoid that "in use" error).

From my experimentation, StartWithLastProfile in profiles.ini corresponds to the Profile Manager checkbox "Use the selected profile without asking at startup" (said profile being marked with Default=1). If set to 1, that's what happens when Firefox is not already running and is started with no -P or --profile parameter. If 0, the Profile Manager will appear—and if you're anything like me, that's kind of useless: I'm not gonna find and close every running browser window to switch profiles.

By cks at 2023-10-20 23:34:55:

Ian: I have scripts that I run through dmenu (currently they're in my custom dmenu $PATH, but they could be general X scripts). The scripts take arguments for optional URL(s) to open the applicable profile with the URLs, or they open some default page if there's no URL (generally the website's URL). So if I want to go to the university's designated all-encompassing 'messaging' web application (which I won't name but you've definitely heard of), I have a one-word command that brings up the browser profile that is logged in and authenticated and all.

(My co-workers and I don't use the university's chosen system for this, but other people at the university sure do, so I keep needing to check in there.)

Craig McConomy: I use uMatrix in my main Firefox, but so far I haven't found a compelling reason to run it in these 'allow JavaScript by default' profiles. I have uBlock Origin to block all of the usual bad things, so I think it'd have to be a pretty targeted annoyance to need uMatrix's selective power.

Doesn't `firefox --profile <dir>` do exactly the same thing? My understanding is that `firefox --profile=` is pretty much identical to `chromium --user-data-dir=`.

Unless you actively want something infectious enough to affect xdg-open, etc.

By Ian Z at 2023-12-02 23:49:50:

@Bryan: The confusion with StartWithLastProfile is the profiles.ini apparently isn't a pure config file, but Firefox modifies is each time it runs to set the Default variable to 1 on the profile it is starting with. There seems to be no clean and easy option to have a static default profile that is used without further ado -- as you note, StartWithLastProfile=0 forces the profile selector to appear, even if there is a profile with Default=1. This whole interface is quite mad, IMO.

The implication is that I need a script even to start the most vanilla Firefox, just to hardcode the profile name.

Written on 19 October 2023.
« WireGuard is pleasantly easy to set up on smartphones (if you're experienced)
Changing the menu bar order of Emacs easy-menu menus »

Page tools: View Source, View Normal.
Search:
Login: Password:

Last modified: Thu Oct 19 22:45:00 2023
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.