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

webbrowser.get("firefox") does not work on Mac with installed Firefox #51441

Closed
dalke mannequin opened this issue Oct 23, 2009 · 11 comments
Closed

webbrowser.get("firefox") does not work on Mac with installed Firefox #51441

dalke mannequin opened this issue Oct 23, 2009 · 11 comments
Assignees
Labels
OS-mac stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@dalke
Copy link
Mannequin

dalke mannequin commented Oct 23, 2009

BPO 7192
Nosy @ronaldoussoren, @bitdancer
Files
  • webbrowser.py.diff
  • 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/ronaldoussoren'
    closed_at = <Date 2010-06-22.11:00:15.680>
    created_at = <Date 2009-10-23.14:07:35.578>
    labels = ['OS-mac', 'type-feature', 'library']
    title = 'webbrowser.get("firefox") does not work on Mac with installed Firefox'
    updated_at = <Date 2010-06-23.05:49:13.568>
    user = 'https://bugs.python.org/dalke'

    bugs.python.org fields:

    activity = <Date 2010-06-23.05:49:13.568>
    actor = 'ronaldoussoren'
    assignee = 'ronaldoussoren'
    closed = True
    closed_date = <Date 2010-06-22.11:00:15.680>
    closer = 'ronaldoussoren'
    components = ['Library (Lib)', 'macOS']
    creation = <Date 2009-10-23.14:07:35.578>
    creator = 'dalke'
    dependencies = []
    files = ['15188']
    hgrepos = []
    issue_num = 7192
    keywords = ['patch']
    message_count = 11.0
    messages = ['94387', '104776', '104777', '104786', '108357', '108358', '108360', '108365', '108366', '108431', '108435']
    nosy_count = 4.0
    nosy_names = ['dalke', 'ronaldoussoren', 'r.david.murray', 'l0nwlf']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue7192'
    versions = []

    @dalke
    Copy link
    Mannequin Author

    dalke mannequin commented Oct 23, 2009

    I have Firefox and Safari installed on my Mac. Safari is the default.

    I wanted to try out Crunchy (http://code.google.com/p/crunchy/). It's
    developed under Firefox and does not work under Safari. I tried. ;)

    It starts the web browser with the following.

    try:
        client = webbrowser.get("firefox")
        client.open(url)
        return
    except:
        try:
            client = webbrowser.get()
            client.open(url)
            return
        except:
            print('Please open %s in Firefox.' % url)
    

    On my Mac, webbrowser.get("firefox") fails, so this ends up opening in
    Safari. Which does not work to view the code.

    Thing is, I have Firefox installed, so it should work. But the Mac code in
    webbrowser appears to only open in the default browser.

    The following bit of code works well enough to get crunchy to work

        class MacOSXFirefox(BaseBrowser):
            def open(self, url, new=0, autoraise=True):
                subprocess.check_call(["/usr/bin/open", "-b", 
    "org.mozilla.firefox", url])
    register("firefox", None, MacOSXFirefox('firefox'), -1)
    

    but I don't know enough about the Mac nor about webbrowser to know if I'm
    the right path. For example, I don't know if there are ways to support
    'new' and 'autoraise' through /usr/bin/open or if there's a better
    solution.

    Attached is the full diff.

    @dalke dalke mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Oct 23, 2009
    @ronaldoussoren
    Copy link
    Contributor

    Firefox doesn't seem to support a full scripting api, which makes opening tabs and windows harder.

    I've committed an alternate version of your patch in r80698: This uses osascript to open the url instead of the open command. I've also added a registration for "safari".

    The main reason to use osascript instead of just open is that it might be possible to add support for opening new tabs or windows later on by adjusting the script.

    @ronaldoussoren
    Copy link
    Contributor

    I've ported the change to 3.2 as well.

    @bitdancer
    Copy link
    Member

    bpo-8238 notes the problem with autoraise and new on windows. I believe when I looked at that issue that I confirmed that the syntax webbrowser uses on Linux to support those options works on windows with the current firefox, even though I couldn't find them documented anywhere. If I'm remembering correctly, then I would expect them to work on Mac, as well.

    Webbrowser needs to be refactored so that browser specific support is not not required to be also platform specific.

    @ronaldoussoren
    Copy link
    Contributor

    R. David Murray: the issue you refer to isn't the one you intend to link to, it is related to proxy settings and doesn't contain a patch related to firefox.

    @ronaldoussoren
    Copy link
    Contributor

    BTW. The firebox-bin binary in Firefox.app/Contents/MacOS does not support the command-line arguments that Firefox on Linux supports. That is, the following command does not work:

    /Applications/Firefox.app/Contents/MacOS/firefox-bin -remote 'openURL("http://www.apple.com/",new-tab)'

    This will start the firefox binary, but that complains that firefox is already running (because I already had FF open)

    This means that it won't be possible to have one Firefox support class that works the same on all platforms.

    @l0nwlf
    Copy link
    Mannequin

    l0nwlf mannequin commented Jun 22, 2010

    16:05:57 l0nwlf-MBP:/Applications/Firefox.app/Contents/MacOS$ ./firefox-bin 'http://www.google.com'
    says firefox is already running as ff is open.
    After we quit ff,
    16:09:05 l0nwlf-MBP:/Applications/Firefox.app/Contents/MacOS$ ./firefox-bin -remote 'http://www.google.com'
    Nothing happens.
    16:09:14 l0nwlf-MBP:/Applications/Firefox.app/Contents/MacOS$ ./firefox-bin 'http://www.google.com'
    Opened firefox with url(google homepage) as mentioned.

    Also,
    >>> import webbrowser
    >>> url = 'http://www.google.com'
    >>> c = webbrowser.get('safari')
    >>> c.open(url)
    True
    Opens two instances of safari, one with home-page and another with url mentioned. Initially safari was not running and firefox is my default browser. Incase safari is running it opens only one instance with url(google homepage) opened.

    @ronaldoussoren
    Copy link
    Contributor

    I'm closing this issue:

    1. webbrowser.get("firefox") currently works

    2. firefox on OSX doesn't provide hooks to open tabs instead of windows (neither through the command line nor though AppleScript) which means that the 'new' and 'autoraise' options of webbrowser.open cannot be supported due to lack of support in FF itself.

    @l0nwlf
    Copy link
    Mannequin

    l0nwlf mannequin commented Jun 22, 2010

    I searched for proxy+firefox on roundup and the only two issue I got was bpo-8238 and bpo-1160328. None of them seems related to webbrowser.

    @bitdancer
    Copy link
    Member

    Sorry, I have no idea where that issue number came from. The correct issue is bpo-812089.

    I just retested, and despite -remote being currently undocumented, it works on my windows VM with a current (3.6) version of firefox, and that the actions (eg: new-window) work as well.

    I don't currently have an OS X machine to test on, although that may change this week.

    @ronaldoussoren
    Copy link
    Contributor

    I tested on OSX with a current version of FF and it didn't work.

    @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
    OS-mac stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants