13

My problem is that many programs call xdg-open to open websites but on my Manjaro system (based on Arch Linux) this is somehow bound to cups :)

When such a call to xdg-open happens, the CPU usage goes up a lot, without anything happens. I restart because the laptop gets hot very quickly.

~ $ xdg-settings get default-web-browser
cups.desktop

When I want to change that, I get the following response:

~ $ xdg-settings set default-web-browser firefox.desktop
xdg-settings: $BROWSER is set and can't be changed with xdg-settings

I can go ahead and change the environment variable for the browser and I'm fixed, BUT only for this one terminal. How could I make this change permanent or add it to autostart?

I'm using: i3 4.12, fish shell

2
  • I don't use a desktop, so don't have the right setup and cannot say what GUI tool does this for you, but there is a file ~/.local/share/applications/preferred-web-browser.desktop on my system that has Exec=firefox %u in it.
    – meuh
    Sep 3, 2016 at 19:02
  • thanks meuh. my issues arise from programs calling xdg-open though which then calls the connected '.desktop' file, that is connected with the task (=default-web-browser in this case). The .desktop file that gets called is cups.desktop, which i find a bit weird and i'm considering deleting cups, because i don't print anyway :)
    – joemaro
    Sep 9, 2016 at 15:34

4 Answers 4

16

I had this issue since Chromium made itself the default browser each time I installed it.

Using xdg-mime fixed it:

xdg-mime default firefox.desktop x-scheme-handler/https x-scheme-handler/http

On my Arch Linux system, this added two lines to ~/.config/mimeapps.list, associating HTTP and HTTPS with Firefox.

Now I can have both Firefox and Chromium installed with Firefox being the default browser.

2
  • 2
    Add text/html as an argument to also handle .html files in the file system.
    – Alicia
    Dec 20, 2020 at 16:28
  • Thanks, this worked for me in Crostini to keep using garcon to open the native browser in ChromeOS but use the chrome binary for running selenium Mar 3, 2021 at 21:08
4

Check the BROWSER variable in /etc/profile and /etc/environment and eventually in your ~/.bashrc. It is probably set to /usr/bin/xdg-open so you should consider to change it to avoid the recursive call.

2
  • I have no browser variable in any of those files, is this no longer viable for recent vers?
    – Mark Deven
    Jan 26, 2020 at 3:30
  • 3
    My experience: I had BROWSER=firefox in ~/.bashrc but an application still opened URLs in chromium. xdg-settings get default-web-browser produced chromium.desktop, but wouldn't let me set it due to $BROWSER existing. I had to open a new terminal, do export BROWSER="", then run xdg-settings set default-web-browser firefox.desktop and then the application opened urls in firefox. I find that weird, as it's acting like $BROWSER supersedes (and thus won't set), but it wasn't occuring like this in practice. Adding note for anyone else running into this.
    – Hendy
    Mar 27, 2020 at 20:14
1

Apparently, xdg-settings doesn't like that BROWSER variable is set in the current shell. Removing it will make it happy:

~ $ unset BROWSER
~ $ xdg-settings set default-web-browser firefox.desktop

The first command above will change the variable only for this one terminal, but the second one (which is the objective) will take effect across terminals.

On my machine, it looked like this:

~ $ grep -sch BROWSER /etc/* ~/.*rc | uniq
0

~ $ xdg-settings get default-web-browser
cups.desktop

~ $ xdg-settings set default-web-browser firefox.desktop

xdg-settings: $BROWSER is set and can't be changed with xdg-settings

~ $ (
  unset BROWSER
  xdg-settings set default-web-browser firefox.desktop
)

~ $ xdg-settings get default-web-browser
firefox.desktop
0

For me what worked was editing the file ~/.config/mimeapps.list. This is what you do under the hood with the xdg-mime command mentioned earlier. The good thing is that you can easily look which are your defaults and for which files. Some more details:

  • The dir ~/.local/share/applications contains .desktop files for each user application that you can "link" to xdg-open.
  • As I mentioned, to set one of these applications as default for any desired file type, edit the file ~/.config/mimeapps.list
  • Tip: Although deprecated, several applications still read/write to ~/.local/share/applications/mimeapps.list. To simplify maintenance, simply symlink it to ~/.config/mimeapps.list
  • More info and reference

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .