Skip to content
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

Make webbrowser support Chrome on Mac OS X #68640

Closed
nedbat opened this issue Jun 14, 2015 · 17 comments
Closed

Make webbrowser support Chrome on Mac OS X #68640

nedbat opened this issue Jun 14, 2015 · 17 comments
Assignees
Labels
3.7 (EOL) end of life OS-mac stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@nedbat
Copy link
Member

nedbat commented Jun 14, 2015

BPO 24452
Nosy @ronaldoussoren, @orsenthil, @nedbat, @ned-deily, @dhellmann, @PedanticHacker, @Mariatta
PRs
  • [Do Not Merge] Convert Misc/NEWS so that it is managed by towncrier #552
  • Files
  • issue24452.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/orsenthil'
    closed_at = <Date 2016-10-13.20:31:28.103>
    created_at = <Date 2015-06-14.21:33:25.968>
    labels = ['OS-mac', 'type-bug', 'library', '3.7']
    title = 'Make webbrowser support Chrome on Mac OS X'
    updated_at = <Date 2017-03-31.17:12:04.962>
    user = 'https://github.com/nedbat'

    bugs.python.org fields:

    activity = <Date 2017-03-31.17:12:04.962>
    actor = 'Mariatta'
    assignee = 'orsenthil'
    closed = True
    closed_date = <Date 2016-10-13.20:31:28.103>
    closer = 'gvanrossum'
    components = ['Library (Lib)', 'macOS']
    creation = <Date 2015-06-14.21:33:25.968>
    creator = 'nedbat'
    dependencies = []
    files = ['44978']
    hgrepos = []
    issue_num = 24452
    keywords = ['patch']
    message_count = 17.0
    messages = ['245351', '245355', '245359', '278167', '278257', '278585', '278588', '278589', '278590', '278591', '278592', '278605', '278607', '278608', '281155', '290924', '290926']
    nosy_count = 9.0
    nosy_names = ['ronaldoussoren', 'orsenthil', 'nedbat', 'ned.deily', 'doughellmann', 'python-dev', 'jbmilam', 'PedanticHacker', 'Mariatta']
    pr_nums = ['552']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue24452'
    versions = ['Python 2.7', 'Python 3.5', 'Python 3.6', 'Python 3.7']

    @nedbat
    Copy link
    Member Author

    nedbat commented Jun 14, 2015

    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.
    

    @nedbat nedbat added the stdlib Python modules in the Lib dir label Jun 14, 2015
    @ned-deily ned-deily changed the title Make webbrowser support Chrome on Mac OS/X Make webbrowser support Chrome on Mac OS X Jun 14, 2015
    @PedanticHacker
    Copy link
    Mannequin

    PedanticHacker mannequin commented Jun 14, 2015

    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

    @jbmilam
    Copy link
    Mannequin

    jbmilam mannequin commented Jun 15, 2015

    Boštjan Mejak the windows issue has been addressed in bpo-8232 and recently patched for 3.5. http://bugs.python.org/issue8232

    @Mariatta
    Copy link
    Member

    Mariatta commented Oct 6, 2016

    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 :)

    @orsenthil
    Copy link
    Member

    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).

    @orsenthil orsenthil added the 3.7 (EOL) end of life label Oct 7, 2016
    @orsenthil orsenthil self-assigned this Oct 7, 2016
    @gvanrossum
    Copy link
    Member

    OK, this seems to work for me. I'm, applying this to 3.5, 3.6 and 3.7 (default).

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 13, 2016

    New changeset bd0f502c5eea by Guido van Rossum in branch '3.5':
    Issue bpo-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 bpo-24452: Make webbrowser support Chrome on Mac OS X (merge 3.5->3.6)
    https://hg.python.org/cpython/rev/64a38f9aee21

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 13, 2016

    New changeset 4e2cce65e522 by Guido van Rossum in branch 'default':
    Issue bpo-24452: Make webbrowser support Chrome on Mac OS X (merge 3.6->3.7)
    https://hg.python.org/cpython/rev/4e2cce65e522

    @gvanrossum
    Copy link
    Member

    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?

    @Mariatta
    Copy link
    Member

    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.

    @orsenthil
    Copy link
    Member

    Applying on 2.7 seems alright. Bug fix.

    @gvanrossum
    Copy link
    Member

    OK will do.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 13, 2016

    New changeset bc8a4b121aec by Guido van Rossum in branch '2.7':
    Issue bpo-24452: Make webbrowser support Chrome on Mac OS X (backport to 2.7)
    https://hg.python.org/cpython/rev/bc8a4b121aec

    @gvanrossum
    Copy link
    Member

    Thanks everyone! Applied to 2.7, so closing as fixed now.

    @gvanrossum gvanrossum added the type-bug An unexpected behavior, bug, or error label Oct 13, 2016
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Nov 18, 2016

    New changeset 0c8270cbdc62 by Brett Cannon in branch 'default':
    Issue bpo-24452: add attribution
    https://hg.python.org/cpython/rev/0c8270cbdc62

    @PedanticHacker
    Copy link
    Mannequin

    PedanticHacker mannequin commented Mar 31, 2017

    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.

    @Mariatta
    Copy link
    Member

    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.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life OS-mac stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants