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

webbrowser.open with file: URLs may launch editor instead of browser #128540

Open
Labels
stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@minrk

Description

@minrk

Bug report

Transferred tohttps://discuss.python.org/t/support-for-file-urls-in-webbrowser-open/81612 until consensus is reached.

Bug description:

In the code:

importwebbrowserfrompathlibimportPathindex_html=Path.cwd()/"index.html"webbrowser.open(index_html.as_uri())

It is common forxdg-open (on linux) oropen location (on mac) oros.startfile (on windows) to be selected as the default browser. This is great and simple forhttp[s] urls, but when these are passedfile:// urls, all of the above select the default opener for HTMLfiles, which may not be a browser at all (commonly a text editor for developer systems).

I don't know if there's a way to indicate that Browser entries can handle given URL schemes, but when selecting a browser from the try list, ideally these generic 'open' mechanisms should be skipped forfile: URLs. Even better, use standard APIs to lookup the default browsers forhttp[s] and invoke that explicitly, rather than relying on an interpretation of "open URL" which is only valid for http URLs.

I believeURLForApplicationToOpenURL is the current macOS API to look up the application forhttp:, which could be used to launch explicitly with a browser. I guessxdg-settings get is already the equivalent for most linux situations and preferred if available, which is great. I'm not sure there's a more general way to discover whatxdg-open will do withhttp://, but we haveoccasional reports wherexdg-settings get default-web-browser doesn't work andxdg-open is invoked and doesn't launch a browser (or launches adifferent browser). I've no idea what the Windows call would be, butthis looks like the same question.

This appears to have been opened long ago as#37540 and erroneously closed as an Apple bug (all platforms exhibit this behavior, and I think the bug is pretty clearly in webbrowser's assumption that "open file://path.html" means "open file://path.html with a web browser" which does not appear to be what any of the platforms mean by the chosen API).

CPython versions tested on:

3.9, 3.10, 3.11, 3.12

Operating systems tested on:

Linux, macOS, Windows

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp