Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
minrk wants to merge5 commits intopython:main
base:main
Choose a base branch
Loading
fromminrk:default-browser-xdg

Conversation

@minrk
Copy link
Contributor

@minrkminrk commentedFeb 25, 2025
edited
Loading

especially for file:// URLs

  • add support forgtk-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)
  • add support forexo-open --target WebBrowser on XFCE (nice: it allows specifying that a browser should be launched)
  • explicitly prevent non-browser launchers likexdg-open,gvfs-open,gio open from launchingfile:// URLs, since those open applications associated by file type instead of browsers.

Addressesgh-128540 on linux, etc.

gh-50920: addressed by adding support forexo-open --launch WebBrowser on XFCE (only identified via the standard XDG_CURRENT_DESKTOP, which seems appropriate in 2025)

For users wherexdg-settings get default-web-browser returned anexact 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 ingh-108172), not just those in the hardcoded list.

Note thatunlike the mac and Windows implementations, this opts out offile:// 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:

  • shouldgtk-launch be gnome specific?
  • shouldgio launch be included, since it requires implementing a search of $XDG_DATA paths (aside: is there a standard call for resolving a .desktop file?)?
  • shouldxdg-open and friends should be skipped for file URLs, since it does the wrong thing and is top priority in most cases?
  • shouldxdg-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/

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
@hugovkhugovk changed the titlegh-128540: launch default browser more often on linuxgh-128540: launch default browser more often on LinuxFeb 25, 2025
@eli-schwartz
Copy link
Contributor

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*-open programs other than xdg-open except if you don't trust xdg-open to perform said browser detection (or from within a DE-specific component calling out to other parts of said DE).

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.

sbivol reacted with thumbs up emoji

@eli-schwartz
Copy link
Contributor

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.

@minrk
Copy link
ContributorAuthor

gio launch and gtk-launch won't exist on all systems.

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.

Ifxdg-open supported passing an app for a standard 'open with ...', that would be awesome and the simpler way to go. Apparently someone madexdg-launch, which seems to be exactly this. I wishxdg-open had this, andreally hope I'm just missing it somewhere and someone can point me to the xdg command to launch an app by name (or default mime-type) with a URL.

What's the story for supporting KDE?

I'm not very familiar with KDE, butlooking at docs, I think this should be:

kfmclient exec URL BROWSER_NAME

but it's unclear from the docs if the current defaultkfmclient openURL behavior opens in the default browser or default app. If anyone knows the way to spell "open $url with $app" for KDE, I'll add it.

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.

Would folks prefer that? It is simpler, in a way.

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.

Yeah, that makes sense as a feature request, and is already at#47427 (opened 17 years ago). But it isn't what thewebbrowser module claims to do, so doesn't seem actionable here.

@eli-schwartz
Copy link
Contributor

I'm not very familiar with KDE, butlooking at docs, I think this should be:

kfmclient exec URL BROWSER_NAME

but it's unclear from the docs if the current defaultkfmclient openURL behavior opens in the default browser or default app. If anyone knows the way to spell "open $url with $app" for KDE, I'll add it.

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 compatiblemimetype options for "inode/directory" or "text/html"

kfmclient exec file:///tmp
screenshot

kfmclient exec https://example.com
screenshot-https

Note also that xdg-open internally uses kde-open "for recognized versions of KDE" and the fallback for really old KDE versions is...kfmclient exec, in remembrance of the fact that in the long ago, konqueror was available in all KDE sessions.

Yeah, that makes sense as a feature request, and is already at#47427 (opened 17 years ago). But it isn't what thewebbrowser module claims to do, so doesn't seem actionable here.

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.

@minrk
Copy link
ContributorAuthor

kfmclient exec file:///tmp

Yeah, I don't think we should add any calls tokfmclient exec URL, since that aims to do the same default-opener action asxdg-open. I would only use it in the form that allows specifyingexplicitly to launch in a browser.

I just did a fresh install of kubuntu 24.04, and observed:

  1. kfmclient is not available, the current implementation is apparentlykioclient
  2. kioclient exec file://url without specifying what to launch definitely isn't what we want, as you demonstrated
  3. the what-to-launch apparently wants a url scheme, not an app name, so the right command iskioclient exec file://$PWD/file.html x-scheme-handler/https (i.e. open url X with default handler for mime Y). Advantage: we don't need to lookup the browser name for this to work.
  4. gtk-launchis present andgtk-launch $(xdg-settings get default-web-browser) file://$PWD/file.html does the right thing, so the desired behavior does happen by default with this PR as-is (forkubuntu, at least). I don't know how common that will be.

Rekioclient --commands output:

 kioclient exec 'url' ['mimetype']            # Tries to open the document pointed to by 'url', in the application            # associated with it in KDE. You may omit 'mimetype'.            # In that case the mimetype is determined automatically.            # 'url' can be the URL of a document, a *.desktop file,            # or an executable.

I've addedkioclient exec {url} x-scheme-handler/https on KDE and support for the gtk4-launch name.

@eli-schwartz
Copy link
Contributor

gtk-launch will be available only if the user happens to have gtk 3.x apps installed. Many users of KDE desktops only have Qt apps installed.

gtk4-launch is similar but for gtk 4.x

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 theini files directly.

@minrk
Copy link
ContributorAuthor

You need to check both and you cannot assume either one.

Yup, that's done here.

You need a fallback for those people

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, soxdg-open remains the top priority ifgtk[4]-launch is not found. The only change that's not purely an addition is skippingxdg-open (and a couple similar entries) forfile:// URLs, at which point it proceeds through the fairly lengthy fallback chain of about 15 browsers by name.

Andall of these remain lower priority than the longstanding behavior of launching the default browser directlyif it's found by name (e.g. if default browser isfirefox.desktop andfirefox is on $PATH). That's all unchanged by this PR.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@minrk@eli-schwartz

[8]ページ先頭

©2009-2025 Movatter.jp