13

I have the following scenario: Ubuntu 16.04 machine with firefox and chrome installed, chrome being my default browser.

I check this actions in the shell :

cat /usr/share/applications/defaults.list
cat /etc/mailcap
cat /.config/mimeapps.list
cat /.local/share/applications/mimeinfo.cache

x-www-browser-> chrome is launch
xdg-mime query default text/html
response:
google-chrome.desktop

And does not appear firefox by any side, always chrome. This is fine. Also check:

Click on a desktop file file.html -> chrome is launch

And now comes the strange, if I run:

xdg-open "http://www.example.com"

For some strange reason it always opens firefox. I do not know why, could anyone help me?

mike
  • 149
  • 1
  • 1
  • 6

3 Answers3

26

To set a default browser, make sure that a .desktop file exists for your preferred browser. I'll be setting Mozilla Iceweasel for this example:

$ ls /usr/share/applications/iceweasel.desktop
iceweasel.desktop

Assured you have the file, run:

$ xdg-settings set default-web-browser iceweasel.desktop
# Test that it works
$ xdg-open "http://example.com"

If you don't have a .desktop file:

I use the program surf, which doesn't have a .desktop file. To set this as your web browser, first create the file ~/.local/share/applications/surf.desktop with this following content:

[Desktop Entry]
Type=Application
Name=surf
Comment=Surf minimal web browser
Terminal=false
Exec=surf
Categories=Network;WebBrowser

While not all of this content is required, it helps categorize the file for any future use.

Set the default browser like normal:

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

And now you're good to go!

Lawful Lazy
  • 729
  • 7
  • 20
  • 2
    For me "xdg-settings get default-web-browser" returned "firefox.desktop" already. But running "xdg-settings set default-web-browser firefox.desktop" fixed my problem anyway. – user2707671 Jan 27 '19 at 22:47
  • I faced with same problem after adding Postman **.desktop** file following [their doc](https://learning.getpostman.com/docs/postman/launching_postman/installation_and_updates/#linux-installation) `xdg-settings get default-web-browser` returned proper value. Running @user2707671 advice to try to setup proper browser again fixed the problem – Pavlo Zhukov Apr 30 '19 at 20:31
  • I use Luuntu and still cannot fix this. `xdg-open` always open Firefox. – Minh Nghĩa Feb 18 '20 at 08:24
  • on kde, if set fails, try: https://askubuntu.com/questions/62182/how-do-i-change-the-default-browser-that-konsole-opens-urls-with#comment1584875_216342 – geekley Sep 01 '20 at 06:34
1

text/html is for html files, i.e. if you open a html file then it would open in google chrome. For opening urls, you need to have the x-scheme-handler/https and x-scheme-handler/http entries.

you can set that either with xdg-mime. For example to set google chrome as the default browser for xdg-open:

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

Or you can put the following lines in ~/.config/mimeapps.list

x-scheme-handler/http=google-chrome.desktop
x-scheme-handler/https=google-chrome.desktop

The above command basically insert these lines to that file.

Note: you should obviously have the google-chrome.desktop file under ~/.local/share/applications or the systemwide alternative location - /usr/share/applications.

Just Khaithang
  • 252
  • 1
  • 2
  • 9
-5

Solved, just open chrome browser and set as default browser. This fix the problem.

mike
  • 149
  • 1
  • 1
  • 6