Changing default browser properly

This post is the start of a question and its own answer. Its purpose is to document a solution that has seemingly not been found before.
You can skip to the TLDR if you don’t want to read; it’s at the end of this post.
My post contained errors; they have been edited.
You can take a look at the replies under - there are additional explanations and corrections to my post, it’s interesting !


Hello Garuda Forums,
I have had an issue with changing default browsers from firedragon to librewolf. Firedragon feels a bit too feature-packed for me, so I simply feel more at home with Librewolf, while keeping firedragon as a secondary browser.

The problem I encountered was that despite the Default Web Browser (from KDE Settings Default Applications) being set to Librewolf, Firedragon would still open for different things (e.g. python webbrowser.open amongst others).
I quickly figured out that this was happening because the environment variable $BROWSER was set to firedragon explicitly.

A few quickfixes were already posted on this forum (and elsewhere), advising the setting of $BROWSER from a fish configuration file, e.g. from ~/.fish_profile, ~/.config/fish/config.fish or /etc/fish/config.fish.
While this fix may convince other people, I wanted to understand why my $BROWSER was acting like that.
Another possible quickfix probably was uninstalling firedragon (and maybe symlinking the executable to librewolf), but I wanted to keep the package.

I obviously searched in the different config dirs fish may have, to no avail.

I tried set -S | grep BROWSER (which shows variables’ history) said that it was defined in global scope as firedragon (the librewolf is from when I had .fish_profile):

set -S | grep BROWSER
$BROWSER: set in global scope, exported, with 1 elements
$BROWSER[1]: |librewolf|
$BROWSER: originally inherited as |firedragon|

I also could not find anywhere where this variable would be set by running fish_trace=1 fish -lic 'echo', which meant a definition from higher.

I ran multiple system-wide greps and finds, including these horrors (ran from /):

sudo find -name "*.fish" -not -path "proc*" -not -path "sys*" -not -path ".snapshots*"
sudo grep -rE  "set.{0,6}BROWSER" --exclude-dir=proc --exclude-dir=sys --color=auto --exclude-dir=.snapshots`

I did in fact look into lots of files.

In the end, the one that allowed me to find the right file was:
sudo grep -rE "BROWSER.*firedragon" --exclude-dir=proc --exclude-dir=sys --color=auto --exclude-dir=.snapshots
Which gave me a hit at /etc/skel/.config/environment.d/garuda.conf** ~/.config/environment.d/garuda.conf:

...
~/.config/environment.d/garuda.conf: BROWSER=firedragon
...

As I had already gone through a lot to find a match (4 hours of searching !!), I was sure it was the culprit. I changed it to BROWSER=librewolf and rebooted : voilà, fixed.

I really wish this was documented somewhere before, this search was painful, but at least it’s here now, so enjoy and I hope this post helped you :slight_smile:
I’m actually interested in seeing what other things this folder contains. When I have time maybe.

**: While it did hit /etc/skel/.config/environment.d/garuda.conf, this is not the file that affects existing user sessions; the right one is in your home config folder. Read the next post for explanation !


TLDR : Run

sudo sed -i 's/firedragon/librewolf/' ~/.config/environment.d/garuda.conf

and reboot

Post #1 is not exactly the solution, please read further for explanations

Hello @0bdc9c966fd8a4e720ef, good for you for sticking with it and digging deep to try to find a solution. I have a couple notes about your topic if you are interested.

The files in /etc/skel have no effect on the user session at all. No applications refer to any of the configurations in these files, and the system does not look here for environment variables or other settings.

In fact, making changes to files in /etc/skel will not even persist because the next time the package providing a config in /etc/skel is updated (in this example, the package is garuda-dr460nized), all of the changes you have made will be overwritten with whatever values are defined in the package.

The purpose of the files in /etc/skel is to populate a user’s /home directory with a bunch of default configs when a new user is created on your system. Whenever a new user is created on your system (including during the initial installation), all the files in /etc/skel/ are copied over to /home/*user_name*/.

Unlike the files in /etc/skel (which do nothing), the files in the user’s home directory should be honored by applications and system processes. It is the files in /home you need to modify to make the changes you want.

The counterpart in your home directory for /etc/skel/.config/environment.d/garuda.conf will be ~/.config/environment.d/garuda.conf. This is the file which is able to set environment variables for your user when you log in. If you have not changed this file yet, then the environment variable which sets your default browser to Firedragon is still active.

You can see for yourself like this:

echo $BROWSER

If you want to update the BROWSER value in ~/.config.environment.d/garuda.conf with sed, the command would be:

sed -i 's/firedragon/librewolf/' ~/.config/environment.d/garuda.conf

Notice the “g” is not needed in this case since there is only one replacement.


On top of all of that, you should be aware that most graphical applications will not honor the BROWSER=librewolf environment variable anyway. Command-line programs traditionally use environment variables, but graphical applications typically use the XDG MIME Applications specification instead. XDG MIME Applications - ArchWiki

To change your default browser from Firedragon to Librewolf, you should update the values in ~/.config/mimeapps.list. This is the file where you can declare user overrides for default applications. It takes precedence over system configurations.

If you want to make this adjustment with sed, that would look like this:

sed -i 's/firedragon/librewolf/g' ~/.config/mimeapps.list

Notice in this case, the “gis used because we are specifying a global replacement for the file.

Before you run that command, take a look at the file to see what is actually set as the default. It is possible to have multiple “default” applications set for any given MIME type, which would look like this for example:

[Default Applications]
application/pdf=firedragon.desktop;librewolf.desktop
application/json=firedragon.desktop;librewolf.desktop
application/x-xpinstall=firedragon.desktop;librewolf.desktop
x-scheme-handler/http=firedragon.desktop;librewolf.desktop
application/xhtml+xml=firedragon.desktop;librewolf.desktop
x-scheme-handler/https=firedragon.desktop;librewolf.desktop
...

If you have something like that, you would need to amend the sed command accordingly. In this example, to set Librewolf to be the preferred default browser would be like this:

sed -i 's/firedragon.desktop;librewolf.desktop/librewolf.desktop;firedragon.desktop/g' ~/.config/mimeapps.list

I hope that helps. :slightly_smiling_face:

5 Likes

Thank you for this good and comprehensive explanation.
I have marked this as solution.

Just to add a detail to the excellent explanation above: there is also
xdg-settings set default-web-browser xyz.desktop
except it will refuse to operate if the BROWSER variable is set

fish❯ xdg-settings get default-web-browser
firedragon.desktop
fish❯ xdg-settings set default-web-browser firedragon.desktop
xdg-settings: $BROWSER is set and can't be changed with xdg-settings

and (in my case) I found it being set at login by the ~/.profile script.
Note that I use the Sway edition though, also mine is a ~2 years old install where I probably forgot to update a couple things along the way. “Your mileage may vary” as they say.

I guess both methods are used by the distro because

P.S. Yeah, finding where some environment variable was set is a bit of a nightmare.
I commend the determination and willingness to help. Seriously.
And thanks for reminding about environment.d and set -S, I never noticed the latter before.

3 Likes

Hey, thanks everyone for the additional corrections and explanations !

It must have been late at the time I found the garuda.conf files and the grep probably also hit the local configuration file at ~/.config/environment.d/garuda.conf. As I probably edited the two at the same time, I have taken the modification of the one at /etc/skul as the one that did fix it - thank you for the correction !

Also thanks for the tips on what /etc/skel does and how sed works, I have a lot to learn :slight_smile:

Yes, I noticed most apps do not use $BROWSER for their links, but some other apps (including Codium, Jupyter, and the webbrowser python module amongst others) would still prefer it over file associations and defaults, so I wanted a proper fix for them too :stuck_out_tongue:

~/.config/mimeapps.list seems to be the file edited by KDE Settings when changing Default Applications and File Associations and was ordered with librewolf placed before firedragon so all good there

There are so many places where variables could be defined it’s a bit overwhelming but hey that also means a lot of possibilities for configuration, it’s a double edged sword :wink:

2 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.