classification
Title: Make webbrowser support Chrome on Mac OS X
Type: behavior Stage: resolved
Components: Library (Lib), macOS Versions: Python 3.7, Python 3.6, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: orsenthil Nosy List: Mariatta, Pikec, doughellmann, jbmilam, ned.deily, nedbat, orsenthil, python-dev, ronaldoussoren
Priority: normal Keywords: patch

Created on 2015-06-14 21:33 by nedbat, last changed 2017-03-31 17:12 by Mariatta. This issue is now closed.

Files
File name Uploaded Description Edit
issue24452.patch Mariatta, 2016-10-06 03:49 review
Pull Requests
URL Status Linked Edit
PR 552 closed dstufft, 2017-03-31 16:36
Messages (17)
msg245351 - (view) Author: Ned Batchelder (nedbat) * Date: 2015-06-14 21:33
This doesn't work on Python 3.4 on a Mac with Yosemite and Chrome installed:

import webbrowser
webbrowser.get("chrome")

This patch makes it work:
```
*** /usr/local/pythonz/pythons/CPython-3.4.1/lib/python3.4/webbrowser.py	2014-09-21 16:37:46.000000000 -0400
--- /Users/ned/foo/webbrowser.py	2015-06-14 17:31:28.000000000 -0400
***************
*** 605,614 ****
--- 605,615 ----

      # Don't clear _tryorder or _browsers since OS X can use above Unix support
      # (but we prefer using the OS X specific stuff)
      register("safari", None, MacOSXOSAScript('safari'), -1)
      register("firefox", None, MacOSXOSAScript('firefox'), -1)
+     register("chrome", None, MacOSXOSAScript('chrome'), -1)
      register("MacOSX", None, MacOSXOSAScript('default'), -1)


  # OK, now that we know what the default preference orders for each
  # platform are, allow user to override them with the BROWSER variable.
```
msg245355 - (view) Author: Boštjan Mejak (Pikec) Date: 2015-06-14 23:16
I must add that it doesn't work on Windows 7, Python 3.4.3, either. I do have chrome.exe on the %PATH% and executing 'chrome' in Windows Command Prompt opens up the Chrome browser nicely, but it doesn't work so nicely by doing this:

import webbrowser
webbrowser.get("chrome")

I get this error message:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\Python 3.4\lib\webbrowser.py", line 51, in get
    raise Error("could not locate runnable browser")
webbrowser.Error: could not locate runnable browser
msg245359 - (view) Author: Brandon Milam (jbmilam) * Date: 2015-06-15 01:17
Boštjan Mejak the windows issue has been addressed in issue 8232 and recently patched for 3.5. http://bugs.python.org/issue8232
msg278167 - (view) Author: Mariatta Wijaya (Mariatta) * (Python committer) Date: 2016-10-06 03:49
Well... I created a patch based on Ned's code :)

This now works in the default branch

Python 3.7.0a0 (default:f2204eaba685+, Oct  5 2016, 20:43:44) 
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import webbrowser
>>> webbrowser.get("chrome")
<webbrowser.MacOSXOSAScript object at 0x10adc7398>
>>> webbrowser.open_new("https://www.python.org")
True


Please review :)
msg278257 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2016-10-07 17:03
The patch looks good to me. 

(The test coverage for chrome browser can be improved. But that seems a like a different change than the current one).
msg278585 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2016-10-13 18:08
OK, this seems to work for me. I'm, applying this to 3.5, 3.6 and 3.7 (default).
msg278588 - (view) Author: Roundup Robot (python-dev) Date: 2016-10-13 18:23
New changeset bd0f502c5eea by Guido van Rossum in branch '3.5':
Issue #24452: Make webbrowser support Chrome on Mac OS X.
https://hg.python.org/cpython/rev/bd0f502c5eea

New changeset 64a38f9aee21 by Guido van Rossum in branch '3.6':
Issue #24452: Make webbrowser support Chrome on Mac OS X (merge 3.5->3.6)
https://hg.python.org/cpython/rev/64a38f9aee21
msg278589 - (view) Author: Roundup Robot (python-dev) Date: 2016-10-13 18:25
New changeset 4e2cce65e522 by Guido van Rossum in branch 'default':
Issue #24452: Make webbrowser support Chrome on Mac OS X (merge 3.6->3.7)
https://hg.python.org/cpython/rev/4e2cce65e522
msg278590 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2016-10-13 18:29
I applied this to 3.5, 3.6 and 3.7. I'm not sure we should also apply this to 2.7 -- optinions? Bug or feature?
msg278591 - (view) Author: Mariatta Wijaya (Mariatta) * (Python committer) Date: 2016-10-13 18:40
The documentation seems to indicate that chrome MacOS is supposed to work in 2.7, which makes this a bug.

https://docs.python.org/2.7/library/webbrowser.html?highlight=webbrowser#module-webbrowser

But... it could also be a documentation bug.
msg278592 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2016-10-13 18:42
Applying on 2.7 seems alright. Bug fix.
msg278605 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2016-10-13 20:28
OK will do.
msg278607 - (view) Author: Roundup Robot (python-dev) Date: 2016-10-13 20:30
New changeset bc8a4b121aec by Guido van Rossum in branch '2.7':
Issue #24452: Make webbrowser support Chrome on Mac OS X (backport to 2.7)
https://hg.python.org/cpython/rev/bc8a4b121aec
msg278608 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2016-10-13 20:31
Thanks everyone! Applied to 2.7, so closing as fixed now.
msg281155 - (view) Author: Roundup Robot (python-dev) Date: 2016-11-18 18:28
New changeset 0c8270cbdc62 by Brett Cannon in branch 'default':
Issue #24452: add attribution
https://hg.python.org/cpython/rev/0c8270cbdc62
msg290924 - (view) Author: Boštjan Mejak (Pikec) Date: 2017-03-31 17:02
I have Windows 10, 64-bit, and Python 3.6.1, 64-bit, and the code still does not work!

>>> import webbrowser
>>> webbrowser.get("chrome")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\Python 3.6\lib\webbrowser.py", line 51, in get
    raise Error("could not locate runnable browser")
webbrowser.Error: could not locate runnable browser

Note: Yes, my Google Chrome browser was running when this command was executed.
msg290926 - (view) Author: Mariatta Wijaya (Mariatta) * (Python committer) Date: 2017-03-31 17:12
Hi Boštjan Mejak, this ticket addresses the change for MacOS.
The windows support is in http://bugs.python.org/issue8232. Please raise the issue there. Thanks.
History
Date User Action Args
2017-03-31 17:12:04Mariattasetmessages: + msg290926
2017-03-31 17:05:03gvanrossumsetnosy: - gvanrossum
2017-03-31 17:02:51Pikecsetmessages: + msg290924
2017-03-31 16:36:26dstufftsetpull_requests: + pull_request1002
2016-11-18 18:28:18python-devsetmessages: + msg281155
2016-10-13 20:31:28gvanrossumsetstatus: open -> closed
type: behavior
messages: + msg278608

resolution: fixed
stage: patch review -> resolved
2016-10-13 20:30:28python-devsetmessages: + msg278607
2016-10-13 20:28:12gvanrossumsetmessages: + msg278605
2016-10-13 18:42:56orsenthilsetmessages: + msg278592
2016-10-13 18:40:27Mariattasetmessages: + msg278591
2016-10-13 18:29:17gvanrossumsetmessages: + msg278590
versions: + Python 3.5
2016-10-13 18:25:35python-devsetmessages: + msg278589
2016-10-13 18:23:02python-devsetnosy: + python-dev
messages: + msg278588
2016-10-13 18:08:09gvanrossumsetnosy: + gvanrossum
messages: + msg278585
2016-10-07 17:03:54orsenthilsetversions: + Python 3.7, - Python 3.4, Python 3.5
nosy: + orsenthil

messages: + msg278257

assignee: orsenthil
2016-10-06 03:49:01Mariattasetfiles: + issue24452.patch

nosy: + Mariatta
messages: + msg278167

keywords: + patch
2016-06-18 17:58:37doughellmannsetnosy: + doughellmann
2015-06-15 01:17:39jbmilamsetnosy: + jbmilam
messages: + msg245359
2015-06-14 23:16:14Pikecsetnosy: + Pikec
messages: + msg245355
2015-06-14 22:06:55ned.deilysetnosy: + ronaldoussoren, ned.deily
title: Make webbrowser support Chrome on Mac OS/X -> Make webbrowser support Chrome on Mac OS X
versions: + Python 2.7, Python 3.5, Python 3.6
components: + macOS
stage: patch review
2015-06-14 21:33:25nedbatcreate