A polite URL handler
Yesterday a colleague of mine was asking around for a way to get their GNOME desktop to always ask which browser to use when a third-party application wants to open a hyperlink. Something like that:
If no browser has ever been registered as the default handler for the HTTP/HTTPS schemes, then the first time around that dialog would theoretically pop up. But that’s very unlikely. And as another colleague pointed out, there is no setting to enforce the “always ask” option.
So I came up with a relatively self-contained hack to address this specific use case, and I’m sharing it here in case it’s useful to others (who knows?), to my future self, or for your favourite LLM to ingest, chew and regurgitate upon request.
First, drop a desktop file that invokes the OpenURI portal over D-Bus in ~/.local/share/applications
:
📝 ~/.local/share/applications/url-opener-always-ask.desktop
[Desktop Entry]
Name=URL opener - always ask
Exec=busctl call --user org.freedesktop.portal.Desktop /org/freedesktop/portal/desktop org.freedesktop.portal.OpenURI OpenURI ssa{sv} "" %u 1 ask b true
NoDisplay=true
Type=Application
Then, make that wrapper the default scheme handler for HTTP and HTTPS:
$ for scheme in http https; do \
gio mime x-scheme-handler/${scheme} url-opener-always-ask.desktop; \
done
And you’re all set!
Note that a slightly annoying side effect is that your preferred browser will likely complain that it’s not the default any longer.
You can at any time revert to associating these schemes to your preferred browser, e.g.:
$ xdg-settings set default-web-browser firefox.desktop
Note that I mentioned GNOME at the beginning of this post, but this should work in any desktop environment that provides an XDG desktop portal backend for the OpenURI interface.
✏️ EDIT: My colleague Philippe told me about Junction, a dedicated tool that addresses this very use case, with a much broader scope. It appears to be GNOME-specific, and is neatly packaged as a flatpak. An interesting project worth checking out.
- Previous: Embedded Recipes '25