Firefox is a great and powerful web browser by Mozilla, and Plasma is a great and powerful desktop by KDE.
The problem is that one of the most powerful features of Plasma – Activites – do not work well with Firefox.
There are several pain points in this combination out of the box, including:
- a link opened in one Activity could open in a Firefox window in a different Activity (sometimes even starting that extra Activity, if it was stopped)
- when resuming a stopped Activity with Firefox in it, it would sometimes spawn other Firefox windows that are not related to that Activity
- in general Firefox windows tend to move around Activities where you do not expect them to be
This small script tries to work around those limitations.
In short, using activityfirefox you can have a Firefox window (or several) in each Plasma Activity, and they will be bound to that Activity.
What activityfirefox does is to create a Firefox Profile for the Activity (using its unique ID) it was ran in.
Then every next time you run activityfirefox in that Plasma Activity, it will start the Firefox Profile associated with it.
There is a CHANGELOG that is maintained based on Keep a Changelog.
For summaries of bigger changes and other news, Matija Šuklje has a blog series about it, the first post is here, and any newer will be linked there.
Activity-aware Firefox is packaged for a few distributions already (at least Debian- and Arch-based ones):
Save the activityfirefox script to somewhere in your $PATH.
In my case, I saved it to ~/.local/bin/activityfirefox and have that folder in my $PATH.
E.g. in Fish shell, this is what I did:
git clone https://gitlab.com/hook/activity-aware-firefox.git
mkdir -p ~/.local/bin/
cp activity-aware-firefox/activityfirefox ~/.local/bin/
set -U fish_user_paths ~/.local/bin/ $fish_user_pathsNext, make sure your desktop knows about this “new” browser, by giving it a .desktop file. For example copy the one provided in this repository:
mkdir -p ~/.local/share/applications/
cp activity-aware-firefox/activityfirefox.desktop ~/.local/share/applications/And finally, make sure that Plasma uses your new ”Activity-aware Firefox” as the default browser:
- open System Settings
- either search for “browser” or navigate manually to: Personalisation ↦ Applications ↦ Default Applications
- and there under Web Browser select the new entry called “Activity-aware Firefox”
From this point onward, just use the “Activity-aware Firefox” browser as your browser of choice and be happy about it :)
On its absolute first run, activityfirefox will create a template profile: ~/.mozilla/firefox/????????.template-profile
You can copy (or create) settings you want to be present in ever new Activity-aware Firefox Profile into that. An example set-up useful for Tree-Style Tabs is present in <./template_example> (see Hiding the tab row for what it does).
On any first run within a new Activity, activityfirefox will prompt you whether you want to:
- New – This option will create a fresh new profile without copying anything. This is the fastest method, but you will end up with Firefox default settings, so you might need to manually modify settings yourself.
- Minimal – This is a good trade-off between convenience and resource usage. Only a few important files will be copied over:
- Bookmarks, Downloads and Browsing History
- Passwords
- Site-specific preferences
- Search engines
- Personal dictionary
- Autocomplete history
- Cookies
- Security certificate settings
- Download actions
- Toolbar customization
- User preferences
- Template profile copy – It will copy everything, and only what is in
~/.mozilla/firefox/????????.template-profile - Full copy – This option will copy all data found in the default Firefox Profile. Please mind it might take a long time and take a lot of disk space. WARNING: Please note that Mozilla developers advise against making full profile copy!
- Migrate from pre-0.3 profile – Use in case you used
activityfirefoxin its early (0.1 and 0.2) days and want to simply move the old profile into the new one.
More on this subject: https://support.mozilla.org/en-US/kb/profiles-where-firefox-stores-user-data
On launch activityfirefox will automatically search for any stale Firefox Profiles that it created and which do not have a matching KDE Plasma Activity (anymore, because the Activity was deleted). In that case it will pop up a dialog asking you for confirmation whether you want to delete the unused Profile or not.
NB: the script intentionally does not touch any Profiles that were not created by activityfirefox. The best way to clean those out is to manage your existing Profiles through the means of firefox --ProfileManager.
As with any hack, are a few caveats, of course:
The biggest annoyance is that due to the fact that Firefox kills itself if it has been sleeping for a certain period of time after receiving e.g. SIGSTOP, if you resume a stopped Activity, Firefox will start with the default Profile. This can be quite annoying, especially when several Activities are running.
To work around this issue, it is suggested to make sure Firefox does not automatically launch. In Plasma 6 you can do so by:
- open KDE Plasma System Settings (
systemsettings) - in the Session module
- go to Desktop Session and there
- under Ignored applications add the following into the text field:
activityfirefox,firefox
A limitation of this script is that add-ons, bookmarks, settings, etc. are not copied (except for chrome/) – I suggest using Firefox Sync to sync all of this between Firefox Profiles. This is is also needed if you want to move tabs between Profiles/Activities.
Syncing everything through Firefox Sync can take some time when you run the “Activity-aware Firefox” in a new Plasma Activity for the first time – depending on how much stuff you sync, of course.
On the first run activityfirefox asks you what you want to copy (if anything) from the default or template Profile (see Creating a new Profile above); or migrate the profile from an old (pre-0.3) version of this script.
Depending on your installation, your default Firefox Profile will either be in ~/.mozilla/firefox/????????.default-release/ or ~/.mozilla/firefox/????????.default/.
You can find the exact folder by going through the menu Help ↦ More Troubleshooting Information and in the tab that pops up search for “Profile Directory”.
With Firefox Sync you can decide (per Profile/device) which of the following you want to sync:
- bookmarks
- history
- open tabs – does not auto-sync tabs, but allows you to move tabs between Profiles (and devices)
- logins and passwords – uses Firefox Lockwise
- credit card info
- add-ons
- preferences – not all preferences are synced though, as some are deemed too specific to be safely synced (to work around this you can also use
user.jsor force tweak your Syncing preferences)
If you use Firefox Sync, it makes sense to rename each “device”, so you know which Profile is which. A good option is to include the Activity name and the machine name. We are trying to figure out how to automate this step, help is welcome (see issue #8).
In case you want to more easily identify which Firefox window belongs to which Plasma Activity, you can use the Window Titler add-on to change the names of Firefox windows.
Apparently it should be possible to do this through the Desktop as well using Native Messaging WebExtension, but that is beyond my skills.
If you use the Tree Style Tab add-on or Sidebery, you probably want to hide the tab row on the top.
For your convenience, see template_example/chrome/userChrome.css in this repository and copy it to your default – or better yet, your template – profile. If the chrome/ (sub)folder does not exist yet there, create it.
Although the chrome/ folder is copied when you first run this script, since Firefox 57 user chrome is by default disabled. So even after everything syncs over Firefox Sync, you will need to enable user chrome yourself. An easy way to modify the settings from about:config by storing the settings you want to override into user.js and store that in the Profile folder. The included template_example/user.js does that for you.
The following command should copy all that is needed to your template profile:
cp -r template_example/* ~/.mozilla/firefox/????????.template-profile/If the *.template-profile/ directory does not exist yet, run activityfirefox once and either quit or keep the dialog window open while you populate the now created template folder with all that you need.
Since there is no Web Extension API to send tabs between Firefox Sync devices, moving whole branches of tabs (in our case: a Firefox window in a different Plasma Activity) relies on different creative work-arounds from different add-ons.
In short:
- with Tree Style Tab you can send tab branches via Firefox Sync, but needs extra setting-up for each Profile
- with Sidebery you can drag-and-drop tab branches between Profiles (but not via Firefox Sync)
Luckily Tree Style Tab have worked around this issue in a way, but you need to manually set the name of the sync device again in the Tree Style Tab settings. To do so head out to about:addons ↦ Tree Style Tab ↦ Preferences ↦ Context Menu ↦ Send Tabs to Other Devices with the context menu via Firefox Sync and follow the instructions there.
You will need to do this for every Profile that you want to tab trees to and from, as unfortunately this add-on can not see the device names of Firefox Sync.
In Sidebery they do not support sending tabs through Firefox Sync, but in addition to still being able to use Firefox Sync itself to send individual tabs between devices/Profiles, simply drag-and-dropping a tab branch from one window to another works even if the two windows are from a different Profile.
If you use the Multi-Account Containers add-on, it can sync its containers settings through Firefox Sync, but you need to trigger that through the add-on itself.
Some more complex add-ons that make use of local storage cannot sync through Firefox Sync. You have to take that into account.
If you already have a huge amount of tabs open that you want to migrate to your new Activity-aware Firefox Profiles, I suggest you use the Bulk URL Opener add-on.
This is where I pulled inspiration from to create this script.
- https://yuenhoe.com/blog/2012/08/associating-firefox-profiles-with-kde-activities/
- https://cukic.co/2016/02/08/heavy-activities-setup/
- https://bbs.archlinux.org/viewtopic.php?id=137941
- https://adrian15sgd.wordpress.com/2012/12/16/soporte-de-actividades-para-firefox/
I would also like to thank the official #general:mozilla.org Mozilla Matrix channel, Ivan Čukić, Kai Uwe Broulik, and Lim Yuen Hoe for all their help with the first version.