-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
webbrowser.py cannot use a non-standard browser under MacOS #113539
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
Comments
It might be better to tweak the code that calls osascript -e 'tell application "chrome"
activate
open location "https://www.python.org"
end' I don't have Chrome installed, could you check if this command opens the python website for you? If not, try the same with "chrome" replaced by "google chrome". |
@ronaldoussoren I have chrome installed on macos, it does not work for me:
But, this one works:
Also works with: |
The diff below seems to work, but I haven't fully thought through the consequences on platforms other than macOS. That's why I haven't created a PR at this time. diff --git a/Lib/webbrowser.py b/Lib/webbrowser.py
index 636e8ca459..310c6d58ce 100755
--- a/Lib/webbrowser.py
+++ b/Lib/webbrowser.py
@@ -114,7 +114,21 @@ def _synthesize(browser, *, preferred=False):
executable for the requested browser, return [None, None].
"""
- cmd = browser.split()[0]
+ parts = browser.split()
+ if len(parts) == 1:
+ # Assume this the name of a registered command, use
+ # that unless it is a GenericBrowser.
+ try:
+ command = _browsers[browser.lower()]
+ except KeyError:
+ pass
+
+ else:
+ if not isinstance(command[1], GenericBrowser):
+ _tryorder.insert(0, browser.lower())
+ return [None, command[1]]
+
+ cmd = parts[0]
if not shutil.which(cmd):
return [None, None]
name = os.path.basename(cmd)
@@ -466,9 +480,10 @@ def register_standard_browsers():
if sys.platform == 'darwin':
register("MacOSX", None, MacOSXOSAScript('default'))
- register("chrome", None, MacOSXOSAScript('chrome'))
+ register("chrome", None, MacOSXOSAScript('google chrome'))
register("firefox", None, MacOSXOSAScript('firefox'))
register("safari", None, MacOSXOSAScript('safari'))
+ register("safari-preview", None, MacOSXOSAScript('safari technology preview'))
# OS X can use below Unix support (but we prefer using the OS X
# specific stuff) Ignore the registration of "safari-preview", I added that because that's the only alternative browser on the system I'm working on. A PR for this issue should not contain that. |
…rder in webbrowser.py
I've added a PR and I'm being very conservative with this: the PR phrasing and documentation changes assume this is a new feature and not a bug fix. The reason is that the documentation for webbrowser module mentions that values in the
|
Any update or recommended workaround for this? @sobolevn's osascript works for me by itself, and from within a script, but the webbrowser module doesn't seem to use it even when it's on my PATH. |
…n webbrowser.py (#113561) Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
This will be in the next release (3.14.0b1) in a couple of weeks. |
@hugovk thanks for the update. Is there a recommended workaround for affected versions? |
No official recommendation, you could patch the module. |
Bug report
Bug description:
webbrowser.py reads the environment variable "BROWSER" to find executable using "_synthesize".
This does not work with macOS, where the browser is open by either
or
open -a "Google Chrome"
it doesn't match the list of configured browsers
Workaround is to create a zsh script in the path called 'chrome':
"_synthesize" needs to be fixed.
CPython versions tested on:
3.11
Operating systems tested on:
macOS
Linked PRs
$BROWSER
to reorder default seach order in webbrowser.py #113561The text was updated successfully, but these errors were encountered: