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.0.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.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: webbrowser_open-0.2.0.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.0.tar.gz
Algorithm Hash digest
SHA256 9aaeca34e343856a2caed4f03d41c3bad972dc5aa47cf75a0da9e85240966d2a
MD5 ee501e217b4559b938ebeaebf5f54cc0
BLAKE2b-256 ff59800aa9ed5ad324479395151cfbcbe0ea0fc7ab6c460f1550bb044b7ab99c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for webbrowser_open-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 59fa0e8cb7c9fd11281062bec15372268ef4942cd3407dd58e628029b95e9ce7
MD5 6ff96c3af7563d0b1278818e1e9929c5
BLAKE2b-256 ab628ce03db002faa767953f12b5de6138a61f985db53ba3816d59281b2a4ce4

See more details on using hashes here.

Provenance

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