Skip to content

gh-113539: Enable using $BROWSER to reorder default seach order in webbrowser.py #113561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 25, 2025

Conversation

ronaldoussoren
Copy link
Contributor

@ronaldoussoren ronaldoussoren commented Dec 29, 2023

This PR makes it possible to use $BROWSER to reorder the list of registered (default) browsers, instead of always interpreting values as command-line tools.

The PR also fixes the registration for "chrome" on macOS, the app name is "google chrome" (and has been for years)

This is particularly useful on macOS where the default way to start a browser is not a command-line tool.


📚 Documentation preview 📚: https://cpython-previews--113561.org.readthedocs.build/

ronaldoussoren and others added 5 commits December 29, 2023 11:14
…Dkv9O.rst

Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a usage example somewhere? This feature is rather hard to comprehend.

@ronaldoussoren
Copy link
Contributor Author

Should we add a usage example somewhere? This feature is rather hard to comprehend.

The feature was hard to fully comprehend even before I made it more complex :-(

Adding some examples would definitely help, and it would be even better to slightly restructure the description of this feature. I'll see if I can come up with a better description.

BTW. Some other things I noticed (for different PRs):

  1. The list of supported browsers on macOS is not complete, we should at least add support for Microsoft Edge and possibly other popular non-mainstream browsers like Brave and Chromium.
  2. The table below the description of webbrowser.register is not correct for macOS, e.g. "chrome" is registered as MacOSXOSAScript("google chrome") and not Chrome('chrome')

@hugovk
Copy link
Member

hugovk commented Dec 29, 2023

  1. The list of supported browsers on macOS is not complete, we should at least add support for Microsoft Edge and possibly other popular non-mainstream browsers like Brave and Chromium.

Not limited to macOS, but from the Plausible trial in July, here are the most popular browsers of people visiting docs.python.org:

Also not limited to macOS, here are the most popular desktop browsers used worldwide, from statscounter:

StatCounter-browser-ww-monthly-202211-202311-bar

And visitors to usa.gov sites (json), for macOS:

"Macintosh": {
"Safari": 260849550,
"Chrome": 201103500,
"Firefox": 16103981,
"Edge": 2024170,
"Mozilla Compatible Agent": 2018923,
"Opera": 552767,
"YaBrowser": 36155,
"Whale Browser": 15131,
"DuckDuckGo Browser": 5801,
"Coc Coc": 10339,
"SeaMonkey": 4535,
"Aloha Browser": 3174,
"Maxthon": 4181,
"Mozilla": 2253,
"Internet Explorer": 5163,
"Waterfox": 1837,
"PaleMoon": 139,
"(not set)": 215,
"Vivaldi": 748
},

@minrk
Copy link
Contributor

minrk commented Feb 21, 2025

Given how the mac launchers work, I think it would also be sensible for $BROWSER to accept application names, as the standard way to launch a URL with browser is e.g. open -a 'Google Chrome' URL (equivalent for tell application in current osascript implementation).

e.g.

if shutil.which(cmd[0]):
  # on the command-line
  GenericBrowser
else:
  # maybe check if app exists?
  OSAScript(app_name)

I'm not sure what the right backward-compatibility story is, or if that's appropriate if $BROWSER is a standard env expected to point to a shell executable.

Copy link
Member

@hugovk hugovk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, I added a What's New entry based on the blurb.

@hugovk hugovk merged commit 25e4984 into python:main Apr 25, 2025
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants