'xdg-open' does not open the default browser
Asked Answered
W

3

36

I have the following scenario:

Ubuntu 16.04 (Xenial Xerus) machine with Firefox and Google Chrome installed, Chrome being my default browser.

I check these 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 it does not appear Firefox by any side, always Chrome. This is fine. Also check:

Click on a desktop file file.html → Chrome is launched.

And now comes the strange behaviour. Say I run:

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

For some strange reason, it always opens Firefox. What should I do?

Wendolyn answered 15/12, 2016 at 20:19 Comment(1)
What is meant by "it does not appear Firefox by any side"? A machine translation masterpiece?Pickar
V
56

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

Output:

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!

Volvox answered 17/6, 2018 at 4:51 Comment(5)
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.Fannyfanon
I faced with same problem after adding Postman .desktop file following their doc xdg-settings get default-web-browser returned proper value. Running @Fannyfanon advice to try to setup proper browser again fixed the problemDanny
I use Luuntu and still cannot fix this. xdg-open always open Firefox.Ritchey
on kde, if set fails, try: askubuntu.com/questions/62182/…Headway
Also if you're on Ubuntu and your browser is packaged using a Snap, your application's desktop is not named like firefox.desktop (as you see under /snap/), it's like firefox_firefox.desktop or chromium_chromium.desktop, as found under /var/lib/snapd/desktop/applications/Cobalt
D
10

text/html is for HTML files, i.e., if you open an 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 add the following lines in file ~/.config/mimeapps.list:

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

The above commands basically insert these lines into that file.

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

For changing the default browser overall, you also have to use xdg-settings as shown by Nolan Akash. xdg-settings changes the value of $BROWSER, so another way to change it is to explicitly assign the program (not the .desktop file) to the $BROWSER environment variable and export it.

export BROWSER=google-chrome

You usually would want to keep this like in ~/.bashrc file (or the equivalent for the shell you use) or in the ~/.profile file and log out and log in to have the environment updated and available for other programs to see.

Deettadeeyn answered 20/4, 2021 at 19:56 Comment(0)
W
-8

Just open the Chrome browser and set as the default browser.

Wendolyn answered 17/12, 2016 at 9:40 Comment(1)
For some reason this never works for me. The above answer does work.Contactor

© 2022 - 2024 — McMap. All rights reserved.