Default browser not used from within Snap?

Cross posting my solution as I walked on this thread and others may find it useful:

From my investigation it looks like the Snap creates extra XDG “environment” and due to this default user configuration doesn’t work as expected. Also the browser is run with it’s own profile.

Apparently clearing two environment variables (XDG_DATA_HOME, XDG_CONFIG_HOME) before invoking xdg-open brings the expected behavior.

No idea what’s the correct fix for this as I’m too familiar with Snap ideology in relation to environment separation but the hacky solution works. The workaround script (build specifically for obsidian):

~/bin/xdg-open:

#!/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 "$@"

The ~/bin must be on PATH for it to work.

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:

You can find more details here: https://forum.obsidian.md/t/obsidian-doesnt-use-default-browser-on-ubuntu-22-04/68177/21

2 Likes