Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.1k
Description
Bug report
Checklist
- I am confident this is a bug in CPython, not a bug in a third-party project
- I have searched theCPython issue tracker,
and am confident this bug has not been reported before
CPython versions tested on:
3.11
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.11.4 (main, Jun 9 2023, 07:59:55) [GCC 12.3.0]
A clear and concise description of the bug:
I'm using a custom desktop entry (Linux application launcher) that starts Google Chrome with my custom data dir (or any other setting that is relevant). The custom desktop entry is calledgoogle-chrome-work.desktop
(I have a few other Google Chrome custom launchers for other cases where I need the data dir separated), and this is set as the default browser in the operating system:
$ xdg-settings get default-web-browsergoogle-chrome-work.desktop
When using thewebbrowser
to open a URL, without first registering any specific browser, it callsregister_standard_browsers()
and that in turn runsxdg-settings get default-web-browser
, and if that succeeds - sets up the resulting string (which is expected to be a.desktop
entry) in_os_preferred_browser
. After thatregister_X_browsers()
gets run which knows about a bunch of browsers one might expect to find on Unix systems and tries to register each found with a call toregister()
. The first such "browser" to be registered isxdg-open
- which will automatically use the system preferred web browser (using the XDG spec, that was consulted earlier), and one can always expect to find whenxdg-settings
is available (both are part of the same spec and always come from the same software package).
All this is great. The problem is thatregister()
wants to check if the registered browser is supposedly the_os_preferred_browser
and uses sub string comparison to check that:name in _os_preferred_browser
. In my case - because the text "google-chrome" (which is a browser name thatregister_X_browsers()
knows) is a substring ofgoogle-chrome-work.desktop
- it chooses to have the bare command for Google Chrome as the preferred browser, even though this is definitely not what is needed.
I've looked at the code, and_os_preferred_browser
isonly used to handle the result ofxdg-settings get default-web-browser
, so this substring search makes no sense - if_os_preferred_browser
is set and has a value - it is guaranteed that usingxdg-open
is the correct command - we have basically verified that we have a valid FreeDesktop.org default browser configuration so using it is the only thing that is compatible with the FreeDesktop.org specifications (theoretically, we should execute the desktop entry file directly, but that is a lot more complicated and callingxdg-open
with an HTTP URL will do the Right Thing™️).
This issue should be fixed by:
- Removing the substring search - it makes no sense.
- Make sure to register "xdg-open" (here) in a way that is set as the preferred browser if
_os_preferred_browser
is set, for example:
ifshutil.which("xdg-open"):register("xdg-open",None,BackgroundBrowser("xdg-open"),_os_preferred_browserisnotNone)
I can offer a PR if this seems reasonable.
Linked PRs
- gh-108172: do not override OS preferred browser if it is a super-string of a known browser #113011
- [3.13] gh-108172: do not override OS preferred browser if it is a super-string of a known browser (GH-113011) #123527
- [3.12] gh-108172: do not override OS preferred browser if it is a super-string of a known browser (GH-113011) #123528