-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-128540: launch default browser more often on Linux #130541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
especially for file:// URLs - add support for `gtk-launch` and `gio launch` if default browser is found via `xdg-settings` - add support for `exo-open --target WebBrowser` - explicitly prevent xdg-open and other non-browser-specific openers from launching `file://` URLs
With regard to all of your questions: In general the DE specific opener command is preferred as it will do DE specific things such as e.g. record opened files in "recently opened" lists and whatnot. xdg-open will proxy out to those commands by doing DE detection, so there's no reason to even consider various gio launch and gtk-launch won't exist on all systems. In particular, systems without gnome installed. Such as KDE. What's the story for supporting KDE? gtk-launch will be called "gtk4-launch" on various gnome systems depending on whether one has gtk 3 or 4. The best way to handle this is actually just to go ahead and implement the Desktop File Specification and parse the Exec= line yourself then directly execute the relevant command. |
I will say that I've essentially never actually wanted a module to open a local filesystem file in a web browser. I've wanted a module to open a local filesystem file in "the default application handler, like xdg-open but portable to non Linux operating systems" all the time though. Unsure what, if anything, you should derive from that. |
Yeah, that's handled by the detections already in place. The goal here is to use "launch app by name" where available, which is why it's currently purely additive to what's there already. If
I'm not very familiar with KDE, but looking at docs, I think this should be:
but it's unclear from the docs if the current default
Would folks prefer that? It is simpler, in a way.
Yeah, that makes sense as a feature request, and is already at #47427 (opened 17 years ago). But it isn't what the |
kfmclient is part of the konqueror package and openURL opens the url in Konqueror (a somewhat popular browser in the KDE world). It is no different from hardcoding firefox. kfmclient exec pops up an empty (unpopulated) dialog asking you to choose an application. Maybe I'm misusing it, since KDE isn't my primary desktop. The box at the top does allow you to type in the name of a program executable to launch with. It's not remembering anything for me either. Note "remember application association" indicates it's in theory supposed to be offering xdg-open compatible mimetype options for "inode/directory" or "text/html"
Note also that xdg-open internally uses kde-open "for recognized versions of KDE" and the fallback for really old KDE versions is...
Yeah I know. The point was rather that if I were the one designing a "webbrowser" module from scratch I would simply reject any urls that didn't have a protocol which targets the World Wide Web. :P I'm biased though. |
Yeah, I don't think we should add any calls to I just did a fresh install of kubuntu 24.04, and observed:
Re
I've added |
You need to check both and you cannot assume either one. Users using Qt-based window managers or EFL or various minimalist ones in combination with their favorite set of Qt apps but who don't have the KDE Framework installed. xdg-open will still work and still exist albeit it will open https urls in the default webbrowser while violating the webbrowser.open module docs for files, because people mostly assume xdg-utils is all that needs to be portable and broadly available. You need a fallback for those people and I don't think you will get one unless you implement the Desktop File specification yourself and read the |
Yup, that's done here.
To be clear, the changes here are (almost) purely in addition to what's already there, which is a pretty long try sequence, so all the fallbacks that already exist for that case remain present. I've only added a couple and removed none, so And all of these remain lower priority than the longstanding behavior of launching the default browser directly if it's found by name (e.g. if default browser is |
especially for file:// URLs
gtk-launch
andgio launch
if default browser is found viaxdg-settings
, since these allow launching a.desktop
by name (gio launch
requires an absolute path, so an implementation of searching XDG_DATA is included, whilegtk-launch
searches XDG_DATA path itself and only needs a name)exo-open --target WebBrowser
on XFCE (nice: it allows specifying that a browser should be launched)xdg-open
,gvfs-open
,gio open
from launchingfile://
URLs, since those open applications associated by file type instead of browsers.Addresses gh-128540 on linux, etc.
gh-50920: addressed by adding support for
exo-open --launch WebBrowser
on XFCE (only identified via the standard XDG_CURRENT_DESKTOP, which seems appropriate in 2025)For users where
xdg-settings get default-web-browser
returned an exact match to one of the known browsers, there is no change in behavior. For users withgtk-launch
orgio launch
, any.desktop
should work (e.g. thegoogle-chrome-work
example in gh-108172), not just those in the hardcoded list.Note that unlike the mac and Windows implementations, this opts out of
file://
URLs for generic launchers instead of opting them in forhttp[s]
. This only has an effect on other URLs, likessh://
, for which behavior is still undocumented. But it is easy enough to make the switch from_supports_file
to_http_only
(or_supported_protocols
)Questions:
gtk-launch
be gnome specific?gio launch
be included, since it requires implementing a search of $XDG_DATA paths (aside: is there a standard call for resolving a .desktop file?)?xdg-open
and friends should be skipped for file URLs, since it does the wrong thing and is top priority in most cases?xdg-open
and friends be restricted to http[s] URLs to avoid launching non-browsers for custom URLs, as is done on mac/Windows and when the default browser is successfully recognized on linux?Links:
📚 Documentation preview 📚: https://cpython-previews--130541.org.readthedocs.build/