The Default Browser on Linux Debacle

The concept of a default browser on Linux is a complete mess. There doesn't seem to be any central, agreed-upon method of defining what the default browser is. First, there is the $BROWSER environment variable. This seems like a good idea, it can be set globally, and on a per user basis. On the command line, all you need to do is type $BROWSER http://... and you on your way to the website of your choice. If only it were that easy...

Unfortunately, this isn't widely adopted. In fact on my Gentoo system, it doesn't seem to have any real effect at all. I set in my ~/.bashrc, export BROWSER=/usr/bin/chromium, and yet in the chromium preferences, it still complains that it isn't the default browser. I know, it would probably be more seamless if I used another distro, but I feel the upstream maintainers of the applications need to agree on a default browser concept, which would make the choice of distro irrelevant.

So on to choice B, I use KDE so I look in the KDE system-settings. In the "Default Applications" section, there is an option for web browsers, looks promising. Once again, foiled by the fact that the setting is not universally used. The value chosen is stored in ~/.kde4/share/config/kdeglobals and is only respected by KDE/Qt applications. This does most of the job, but I like most users don't exclusively use just KDE applications, I choose my applications based on how useful they are, not which widget set they are built with. So pretty much all the Gtk/Gnome/other applications still don't respect the setting. For example, links in thunderbird always want to open with firefox. I even tried creating a user.js file in my thunderbird profile directory and setting to my choice of browser, no joy. In the "about:config" the settings are there, the application just didn't seem to care. I am sure I did something wrong, but even if I did, it shouldn't be so hard. There should be a dirt-simple way to set the default browser for all applications for my user and then, if they like, applications can provide some mechanism to override this.

I am sure that Gnome has there own way of setting the default browser, and I think it is likely that it works great for Gnome applications and KDE/Qt applications probably ignore it.

The Debian folks have a nice idea, they leverage the "alternatives" mechanism to provide "x-www-browser" which is (I think) in the end a symlink to the browser of your choice. This is great if everyone agrees to launch the browser with this, but has a minor downside. It only addresses system-level preferences, not user-level. So while you can hypothetically set the default browser system-wide (probably good enough considering how many users are the only user of their systems), if an individual user wants to override this, I'm not sure there is an elegant way to do this. "x-www-browser" just ends up being a less flexible variation of the $BROWSER environment variable.

Also, I've looked into xdg-settings, looks promising, from which a lot of people have been working on standardizing with. Let's see what happens when I play with it.

$ xdg-settings --list                                           
Known properties:
  default-web-browser           Default web browser

Ohh, looking good!

$ xdg-settings get default-web-browser
which: no chromium in (/usr/bin/chromium
in (/usr/bin)l-workbench

Crap, what the heck does that mean? Why is "MySQLWorkbench.desktop" mentioned? What is going on? Ok, I'm done with my little panic, I'll try to fix it:

$ xdg-settings set default-web-browser /usr/bin/chromium
xdg-settings: invalid application name
Try 'xdg-settings --help' for more information.

OK, usage, not as obvious as I thought...

$ xdg-settings --help                                   
xdg-settings - get various settings from the desktop environment


xdg-settings { get | check | set } {property} [value]

xdg-settings { --help | --list | --manual | --version }

Use 'man xdg-settings' or 'xdg-settings --manual' for additional info.

Help... not so helpful. Aha, I figured it out from looking at the manual!

$ xdg-settings set default-web-browser chromium-chromium.desktop

Did it work?

$ xdg-settings get default-web-browser
which: no chromium in (/usr/bin/chromium
in (/usr/bin)l-workbench


Alright, xdg-settings while I nice concept, simply isn't working. So disappointing.

So I've got a lot of options, none of which are 100% effective.

So what's the ideal solution? It's hard to say, probably a hybrid of some of these ideas. I think a single binary/script named /usr/bin/www-browser, that would look first in the user's home directory for a setting and if not found, look /etc/ for a global setting. And would launch the browser of choice. Why not just get everyone to agree on $BROWSER? Well, unfortunately, the different browsers have different command-line switches. Have a script/binary gives us the opportunity to normalize how the common ones are accessed (if any). More generally, it would allow the config file to have more advanced options than just specifying the path of the default browser. xdg-settings does look like it is on the right track, but I honestly couldn't get it to do anything that made sense.

Most importantly the application writers (I'm looking at you KDE and Gnome) need to agree upon whatever method they think is best. I honestly don't care too much about how it works, as long as it works.