Obsidian doesn't use default browser on Ubuntu / Snap

Still same here… I’m so frustrated it’s insane. I have tried everything with xdg-mime, xdg-settings, .desktop files, update-alternatives and everything was set to Brave snap - still nothing. I uninstalled the Brave snap and installed the deb package, still nothing. I uninstalled every possible browser on my system and FINALLY I saw that a new browser windows opened up (not the new tab - which sucks equally as bad!). The cherry on the is present on the screenshot below. Somehow the browser window is considered to be an “Obsidian” process instead of running the actual app. Spaghetti must be strong with this one.

image

1 Like

Fix in my case

  1. If xdg-open works fine from console but obsidian still opens wrong browser, and you are using Snap you can use following hack to fix it:
  • ensure that ~/bin is on your PATH (echo $PATH) - or use different location
  • create ~/bin/xdg-open with following content:
#!/bin/bash

# fix for obsidian opening URLs in wrong browser
if [[ $SNAP_INSTANCE_NAME == "obsidian" && $1 =~ ^(https?://) ]]; then
        unset XDG_DATA_HOME
        unset XDG_CONFIG_HOME
fi

exec /usr/bin/xdg-open "$@"
  • save the script
  • make it executable: chmod +x ~/bin/xdg-open

Now obsidian should run correct browser.

DISCLAIMER: There may be some unexpected downsides coming from this solution. It wasn’t tested very deeply. USE AT YOUR OWN RISK. Maybe there is better solution but this piece of “duct tape” solved my case :wink:

  1. If xdg-open run from the console opens wrong browser, use the solution suggested by others (to fix your system level configuration):
xdg-mime default google-chrome.desktop x-scheme-handler/http
xdg-mime default google-chrome.desktop x-scheme-handler/https

Why this (1) works?

From my quick investigation:

  • strace shows that obsidian searches for xdg-open on PATH and invokes the first one found
  • xdg-open executed from console normally opens the right browser
  • xdg-open executed by obsidian opens wrong browser

After comparing the env output I’ve spotted that Snap crates it’s own XDG “environment”, where especially the two variables cause trouble (although there may be more…):

XDG_DATA_HOME=/home/youruser/snap/obsidian/24/.local/share
XDG_CONFIG_HOME=/home/youruser/snap/obsidian/24/.config

The XDG_CONFIG_HOME messes with configuration (which browser should open) and the XDG_DATA_HOME messes with browser (at least chrome does respect this variable - Chromium Docs - User Data Directory - and due to this it starts new process with empty profile).

So removing those two from environment before invoking real xdg-open falls back to your default config.

6 Likes

@osomdev Thanks for sharing your findings!

How can I do that when starting obsidian from the launcher icon (I am using Ubuntu 23.10) ? Will it not use a the Ubuntu default PATH in that case? And that PATH will not include ~/bin I guess. I observed that I have xdg-open installed in both /bin and /usr/bin. I tried to replace the /bin/xdg-open with the script you provided, but when I click a link in obsidian it just hangs (nothing happens, it does not even open the link in the wrong browser). (After reinstalling the original version of the xdg-open in /bin/xdg-open obsidian opens the link in the wrong browser again)

Any changes for this bug to be fixed without any witchcraft?

Hi again,

A comment on the findings posted by @osomdev. Maybe it helps someone.

I went into my obsidian snap installation directory
~/snap/obsidian/x2/.config and I found that it indeed has a mimeapps.list file which has firefox a the default application.

Naively, I attempted to change this to chrome, and It semi-worked. I got obsidian to open links in chrome, however, it always opening a new window (Perhaps because I am using several different chrome profiles). I would of course want it to open a new tab in the currently opened (or latest used) chrome window as is usually the case.

I can only assume that I encountered the empty profile mentioned in:

the XDG_DATA_HOME messes with browser (at least chrome does respect this variable - Chromium Docs - User Data Directory - and due to this it starts new process with empty profile).

After trying out osomdevs xdg-open script my problem went away, and everything works great!

@hakonhagland You should probably not replace any existing binaries. I assume that osomdevs script (which is a wrapper) works by ~/bin being earlier in the PATH than wherever your usual xdg-open binary is located, thereby executing the wrapper first, which in turn does: exec /usr/bin/xdg-open "$@"

I placed mine in ~/.local/bin/xdg-open and that worked fine

I have the same problem. This workaround from @osomdev worked for me as well, thanks!

It would be great to see this fixed in Obsidian.

Thanks to @osomdev reply I think I found a different way to do this that doesn’t require changing files outside of Obsidian Snap.

First, run these two commands to set up the default browser to Chrome on the isolated environment that Obsidian uses:

XDG_DATA_HOME=$HOME/snap/obsidian/current/.local/share XDG_CONFIG_HOME=$HOME/snap/obsidian/current/.config xdg-mime default google-chrome.desktop x-scheme-handler/http
XDG_DATA_HOME=$HOME/snap/obsidian/current/.local/share XDG_CONFIG_HOME=$HOME/snap/obsidian/current/.config xdg-mime default google-chrome.desktop x-scheme-handler/https

If you want to keep the same browser profile for Chrome when using Obsidian, then run this:

ln -s ~/.config/google-chrome ~/snap/obsidian/current/.config/google-chrome

I’m not sure if this would be needed every time you update the Snap, but in that case just rerun the commands.
Hope this helps!

2 Likes

I juste tested,
this issue only appears with the snap package,
debian, flatpak and appImage are not affected

Same here, Obsidian snap install bug opening the wrong browser fixed using osmodev’s wrapper method. Thanks!!!

Any external URLs in Obsidian open in Chromium by default, even though I confirmed that Firefox is my default browser.

I’d like to open links in my default browser.

Things I have tried

I looked through Obsidian’s settings and I don’t see anything that would let me set a different browser to default to. I also searched this help forum for “default browser” and see at least one other Ubuntu user dealing with this issue, but no solutions:

Just to keep me on my toes, that user says their instance is opening links in Firefox and their default browser is Brave.

I also searched the help pages (which also opened in Chromium, not Firefox) for “browser” (nothing); “external links” (Markdown instructions, but nothing about designating a browser), “default” (nothing relevant)

What I’m trying to do

When I link to a web page in a note, I want to come back and use that link later.

Right now any external links are opening in Chromium. To open in my default browser (Firefox), I have to copy the URL and paste it.

4 Likes

Check help resources for Ubuntu. I vaguely remember seeing rare inconsistent treatment of default browser when I was on Linux (before I used Obsidian), possibly having to do with multiple ways of setting defaults.

Did you manage to solve this? I’m stuck with the same issue here :frowning:

This seems to be related to the snap packages, as both the appimage and .deb versions are opening external links using the correct browser.

1 Like

Can we fix this please? Opening external links is a trash experience under this bug

4 Likes

Created an account to vote on this issue being fixed. I want to open links in Chrome, but Obsidian always opens in Firefox despite my OS (Ubuntu 22.04.6 LTS) default browser being set to Chrome. No other applications exhibit this behavior except Obsidian.

I tried using the following community plugin which will force Chrome to launch, but sadly cannot get it to use the correct profile:

Upon further investigation, I was able to get Obsidian to launch Chrome by selecting a different default browser then re-selecting Chrome.

Unfortunately, Obsidian always launches a new Chrome process instead of using the currently running one, which results in the desired profile not being used. So you get a ‘blank’ browser profile, which doesn’t have any of your bookmarks/extensions/history and is basically useless.

Check this pstree output, which shows 2 trees of Chrome, the second one being opened by Obsidian:

        ├─systemd─┬─(sd-pam)
        │         ├─chrome─┬─2*[cat]
        │         │        ├─chrome───chrome─┬─chrome
        │         │        │                 └─10*[{chrome}]
        │         │        ├─chrome─┬─chrome─┬─chrome───4*[{chrome}]
        │         │        │        │        ├─4*[chrome───15*[{chrome}]]
        │         │        │        │        ├─chrome───20*[{chrome}]
        │         │        │        │        ├─2*[chrome───31*[{chrome}]]
        │         │        │        │        ├─2*[chrome───16*[{chrome}]]
        │         │        │        │        ├─2*[chrome───7*[{chrome}]]
        │         │        │        │        ├─9*[chrome───29*[{chrome}]]
        │         │        │        │        ├─3*[chrome───28*[{chrome}]]
        │         │        │        │        ├─4*[chrome───30*[{chrome}]]
        │         │        │        │        ├─chrome───21*[{chrome}]
        │         │        │        │        ├─chrome───23*[{chrome}]
        │         │        │        │        └─chrome───34*[{chrome}]
        │         │        │        └─nacl_helper
        │         │        ├─chrome───10*[{chrome}]
        │         │        ├─chrome───6*[{chrome}]
        │         │        └─34*[{chrome}]
        │         ├─chrome─┬─2*[cat]
        │         │        ├─chrome───chrome─┬─chrome
        │         │        │                 └─7*[{chrome}]
        │         │        ├─chrome─┬─chrome─┬─chrome───5*[{chrome}]
        │         │        │        │        ├─chrome───9*[{chrome}]
        │         │        │        │        └─chrome───7*[{chrome}]
        │         │        │        └─nacl_helper
        │         │        ├─chrome───9*[{chrome}]
        │         │        └─35*[{chrome}]
1 Like

Just wanted to state that I am having the same issue as acc3d, with Obsidian opening new, blank browser profile processes each time I click on a hyperlink. Currently on Ubuntu 22.04.2 LTS and Obsidian v1.2.8 is installed via snap.

I was having same issue, ubuntu 22.04 desktop.

I uninstalled with snap and installed with the .deb option. Works like it’s supposed to now.

2 Likes

Had the same issue as @acc3d, just with Vivaldi instead of Chromium.
As for @jackreid, switching from Ubuntu 22.04’s snap to deb fixed it.

1 Like

I’ve been experiencing this issue on Kubuntu 22.04 LTS, using the snap package.

I found this Snapcraft thread and after investigation, I figured out that Obsidian always opens the registered browser just before my actual default.

My Default browser is currently Vivaldi, but links in Obsidian opens in Microsoft Edge .
Running gio mime x-scheme-handler/https results in:

Default application for “x-scheme-handler/https”: vivaldi-stable.desktop
Registered applications:
        brave-browser.desktop
        firefox.desktop
        google-chrome.desktop
        microsoft-edge.desktop  # Used by Obsidian
        vivaldi-stable.desktop  # Default
        firefox_firefox.desktop
[...]

Changing it to Google Chrome (with gio mime x-scheme-handler/https google-chrome.desktop) makes it open Vivaldi, since the order changed and Vivaldi is just before Chrome in the list:

Default application for “x-scheme-handler/https”: google-chrome.desktop
Registered applications:
        brave-browser.desktop
        firefox_firefox.desktop
        vivaldi-stable.desktop  # Used by Obsidian
        google-chrome.desktop  # Default
        firefox.desktop
        microsoft-edge.desktop
[...]

Could this be because the code references the wrong index? (i.e. Arrray starts at 0, not 1)

Weirdly enough tho, it launches a completely different instance of Vivaldi that doesn’t have my browser profile, extensions, settings, etc. :thinking:

In the meantime, I’ll install the deb version.
Hope this is helpful for debugging!