How do I change my default browser in Sway?

How do I change my default browser in Sway? I tried setting the BROWSER variable in /etc/environment to waterfox-g3 and rebooting, but when I open a link in a program like WezTerm or Discord, firefox is opened instead.

At first you should check if the variable is actually set (echo $BROWSER). If it isn’t set, you should try to change the variable inside the “.profile” file in your home folder, if you are using the eOS community install.

For me it has always been a mystery what file will set the environment variables under what conditions.

1 Like

I opened my shell and typed echo "$BROWSER" and it’s set to waterfox-g3, as I had configured it. Just in case, I also added "export BROWSER=waterfox-g3" to ~/.profile and rebooted to see if it changed anything and it appears that nothing changed. However, right as I was typing this response, I had the idea to uninstall firefox, since I did that on my previous installation and haven’t had this issue then and it seems to have worked. Thanks anyways for your help.

This is not a solution to this problem. All you accomplished was to make waterfox the only availiable browser on your system to be used (default). It would be misleading to others to leave your post marked as the solution.

4 Likes

Oh, sorry about that.

1 Like

I think we need a flag setup for “Workaround” as well as “Solution”. Sometimes that’s all you get…

2 Likes

We could actually try to find an actual fix as well. Try:
xdg-settings set default-web-browser <insert the filename>.desktop
You would need to do this for each application you want to open with waterfox.

@Shjim @OdiousImp any input?

3 Likes

that be my guess … i only use firefox on sway …

Test in terminal

xdg-open htps:// " what you want "

if want full function need change firefox in configs ( say if want mod+o to open waterfox )

1 Like

It would seem xdg-settings dictates the actual browser to use.
It just refuses to change it while BROWSER is defined.

I removed the variable from /usr/lib/environment.d/ and it now works fine.

2 Likes

I’ve just started using endeavour a couple days ago and haven’t checked if 3rd party programs will open in the new default but I hope this helps.

Navigate your way to [user]/.config/sway/config.d/, from there open application_defaults and change every instance of “firefox” to [whatever you want].
(after a quick check “echo $BROWSER” still returns firefox so this might not help you :frowning: )

If you want mod+o to be different you can change it in the “default” file in the same directory

1 Like

The changes to application_defaults only affects how sway will open the browser. To be more precise it defines on which workspace Firefox (or any program) will open , if the focus should be on the newly opened window and, in the case of Firefox, if it should inhibit the idle state when full screen. It doesn’t have any effect on what the default browser is and even if those lines are deleted, Firefox should work just the same.

I see.

Hmm, my searches just don’t return #BROSWER anywhere in the .bashrc. it looks like it’s defined somewhere in /etc/pacman.d/gnupg/S.dirmngr but I can’t even sudo my way into it which means I(and others, this means you reader) should NOT edit it.

That said, after some troubleshooting(sorry new users, I’ll try to pinpoint where the change occurred after some gardening) if I echo $BROWSER I get /usr/bin/chromium and calling just $BROWSER brings up an instance of chromium.

I’ll try a link through IRC soon to see if this is a true fix.

Work like a charm. Since I installed calibre, sway was opening calibre instead of firefox.
Problem Solved. :+1:

Welcome to the EndeavourOS forum. I hope you enjoy your time here.

I’m glad you found an answer for your problem.

Pudge

TL;DR

You need to change the default app using xdg-mime. Don’t forget to change the default app for other mime types (application/xhtml+xml, text/html, x-scheme-handler/http, x-scheme-handler/https). (src)

You might also want to check the mimeapps.list files where you can find out which apps are set as default for which apps. There are multiple locations, so check out the ArchWiki. I have noticed that xdg-mime (which does not recommend to use xdg-mime default as root in its man page) changes the preferred apps in ~/.config/mimeapps.list.

# Variables
app_url='firefox-nightly.desktop'
app_file='sublime_text.desktop'
file="$HOME/.bashrc"
url='https://google.com'

# [files only] Get a mime type of a file (the file must exist,
#              which is not the case for URLs)
mime_file="$(xdg-mime query filetype "$file")"  # text/plain

# [URLs only, not `file://` scheme] Get a mime type of a URL
# Note: The algorithm is taken from `xdg-open`.
scheme="$(sed -n 's/\(^[[:alnum:]+\.-]*\):.*$/\1/p' <<< "$url")"  # https
mime_url="x-scheme-handler/$scheme"  # x-scheme-handler/https

# Get list of available desktop files
# Note: You can only set a default app that has a desktop file created,
#       but you can create custom desktop files if you want.
# Note: I have defined the preferred app desktop filename to `app_url`
#       and `app_file` variables above.
ls /usr/share/applications/*.desktop | xargs -n1 basename

# Get the default app of a mime type
xdg-mime query default "$mime"  # firefox.desktop

# Change the default app of a mime type
xdg-mime default "$app_url" "$mime_url"
xdg-mime default "$app_file" "$mime_file"

# Test `xdg-open`
# Note: This should open the "$url" in "$app_url"
xdg-open "$url"
# Note: This should open the "$file" in "$app_file"
xdg-open "$file"

Long version

I have experienced the same problem (both on EndeavourOS and on Fedora Sway).

I have three browsers installed: Firefox, Firefox Nightly and Vivaldi Snapshot. I prefer using Firefox Nightly as my default browser, however, every time I open a link from any GUI app, the URL is opened in Firefox instead of Firefox Nightly.

I have set BROWSER to firefox-nightly (installed in /usr/bin; I have also tried to set the env var to /usr/bin/firefox-nightly) and xdg-settings are also configured to firefox-nightly.desktop (verified using xdg-settings get default-web-browser). The URLs are still opened in Firefox.

I have noticed that xdg-open $url opens the URL in Firefox, therefore I presume all/most GUI apps use that to open files, therefore I started to debug it. /usr/bin/xdg-open is a plain SH script, therefore the debugging was quite easy for me. All it did is to add some logs and running xdg-open https://google.com between the file changes.

First, I have verified that BROWSER and PATH env vars are set to the expected values and they were. Then I continued traversing from there towards the place where which opens the URL in the browser.

xdg-open defines DE variable based on the value of XDG_CURRENT_DESKTOP. In my case it was sway, however, the case switch does not check such value, therefore it is evaluated to generic.

So, basically it uses xdg-mime to get the mime type of a file and also to query the default app for that mime type and opens the URL (or file) in that app. I had x-scheme-handler/https mime type set to firefox.desktop. After changing it to firefox-nightly.desktop, the URLs are (finally!!!?? :sweat_smile:) opening in my preferred web browser.