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.3.0.tar.gz (14.7 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.3.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: webbrowser_open-0.3.0.tar.gz
  • Upload date:
  • Size: 14.7 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.3.0.tar.gz
Algorithm Hash digest
SHA256 d751dd76e888d105d786b86ac890b9c0dd7b273d6f39e67c57a1cc7ddefe03a2
MD5 6160040074b073e46fee78c78dc43b40
BLAKE2b-256 48402e6eb1c513b60fe489da49bbdfca3e0d8c4ae5657352c90dad1dde2cc3c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for webbrowser_open-0.3.0.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.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for webbrowser_open-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bd44ce80df1db634df3156f6b56ec2b445812e7bcff82d9f22b2217acaede23f
MD5 d66ef7cf10ec2ce55d6ed436473e3bce
BLAKE2b-256 2d0e16fa8d77cfefd4f09c7c21e518e8f7cc5d0c1b80c57048a38deabc13b96b

See more details on using hashes here.

Provenance

The following attestation bundles were made for webbrowser_open-0.3.0-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