Skip to main content

Prototype for stdlib webbrowser.open functionality

Project description

webbrowser_open

prototyping opening things with the default webbrowser

Use

The simplest way to use this package is to replace:

import webbrowser

...
webbrowser.open(url)

with

import webbrowser_open

...
webbrowser_open.open(url)

You can also launch a URL with

python3 -m webbrowser_open URL

to see the difference (if any) in your environment.

The only difference in behavior is that webbrowser_open looks up the default browser application before opening the URL. This should only result in a change in behavior for opening file:// URLs where the default application associated with the file type is used instead of the default browser.

The $BROWSER environment variable still takes priority, if defined, in which case webbrowser_open.open just wraps a call to webbrowser.open with no changes.

This package uses the following APIs to explicitly launch the default browser:

platform API notes
mac URLForApplicationToOpenURL implemented via applescript
Windows HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice I don't yet know which cases this might not work for (UWP, minumum Windows versions, etc.), but it works in my own limited tests
linux xdg-settings get default-webbrowser or xdg-mime query default x-scheme-handler/https plus gtk-launch or gio launch gtk-launch appears to locate .deskop files correctly, while gio launch only appears to accept absolute paths. I'm not sure how many different ways there are to lookup and/or launch default browsers on linux.

Background

Most platforms have at least a semi-standard way to open URLs and discover the default browser.

webbrowser.open uses generic not-browser-specific APIs (e.g. open, xdg-open, os.startfile), which works fine with http[s] URLs. However, all of these systems associate file:// URLs with the default application for the file type, not necessarily a webbrowser, which webbrowser.open is meant to launch. The result is often webbrowser.open("file:///path/to/page.html") launching a file editor instead of a browser.

webbrowser.open does not work reliably with file:// URLs on any platform, though it may if the default application for HTML files is a browser, which it often is, except for developers.

Linux is in the best situation by default, because it does call xdg-settings get default-web-browser to actually lookup a browser, but it only uses this if a matching browser is already known ahead of time and found in register_X_browsers. This is still known to fail at least sometimes.

This is a prototype package for testing implementations to be submitted to the standard library.

ref: https://github.com/python/cpython/issues/128540

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

webbrowser_open-0.2.1.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

webbrowser_open-0.2.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file webbrowser_open-0.2.1.tar.gz.

File metadata

  • Download URL: webbrowser_open-0.2.1.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for webbrowser_open-0.2.1.tar.gz
Algorithm Hash digest
SHA256 4eab2756adc9fb0ce1a158cb88ed7951793078477f2b9be9bd541e7d6950c644
MD5 50670080528981f2a032949b13d12483
BLAKE2b-256 ead29d68a9a7ad3c6a502ec167e21471effe5718d3e5f960e8137234406139b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for webbrowser_open-0.2.1.tar.gz:

Publisher: release.yaml on minrk/webbrowser_open

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file webbrowser_open-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for webbrowser_open-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 85d1a4d4d58db274107465bcd8b75e746552bfafb8aecbf90f01d1ea6f674c48
MD5 d9bb290e2846a8cd785134b7b0e52eb8
BLAKE2b-256 53b4bb301439f82bcba910f02399df7a5432917ad61b7c81c1662347c0899627

See more details on using hashes here.

Provenance

The following attestation bundles were made for webbrowser_open-0.2.1-py3-none-any.whl:

Publisher: release.yaml on minrk/webbrowser_open

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page