classification
Title: webbrowser.get("firefox") does not work on Mac with installed Firefox
Type: enhancement Stage: resolved
Components: Library (Lib), Macintosh Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ronaldoussoren Nosy List: dalke, l0nwlf, r.david.murray, ronaldoussoren
Priority: normal Keywords: patch

Created on 2009-10-23 14:07 by dalke, last changed 2010-06-23 05:49 by ronaldoussoren. This issue is now closed.

Files
File name Uploaded Description Edit
webbrowser.py.diff dalke, 2009-10-23 14:07
Messages (11)
msg94387 - (view) Author: Andrew Dalke (dalke) * (Python committer) Date: 2009-10-23 14:07
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.
msg104776 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2010-05-02 09:50
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.
msg104777 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2010-05-02 09:56
I've ported the change to 3.2 as well.
msg104786 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-05-02 13:09
issue 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.
msg108357 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2010-06-22 10:20
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.
msg108358 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2010-06-22 10:29
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.
msg108360 - (view) Author: Shashwat Anand (l0nwlf) Date: 2010-06-22 10:45
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.
msg108365 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2010-06-22 11:00
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.
msg108366 - (view) Author: Shashwat Anand (l0nwlf) Date: 2010-06-22 11:05
I searched for proxy+firefox on roundup and the only two issue I got was issue 8238 and issue 1160328. None of them seems related to webbrowser.
msg108431 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-06-23 02:00
Sorry, I have no idea where that issue number came from.  The correct issue is #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.
msg108435 - (view) Author: Ronald Oussoren (ronaldoussoren) * (Python committer) Date: 2010-06-23 05:49
I tested on OSX with a current version of FF and it didn't work.
History
Date User Action Args
2010-06-23 05:49:13ronaldoussorensetmessages: + msg108435
2010-06-23 02:00:14r.david.murraysetmessages: + msg108431
2010-06-22 11:05:13l0nwlfsetmessages: + msg108366
2010-06-22 11:00:15ronaldoussorensetstatus: open -> closed

messages: + msg108365
stage: resolved
2010-06-22 10:45:22l0nwlfsetnosy: + l0nwlf
messages: + msg108360
2010-06-22 10:29:11ronaldoussorensetmessages: + msg108358
2010-06-22 10:20:42ronaldoussorensetmessages: + msg108357
2010-05-02 13:09:51r.david.murraysetnosy: + r.david.murray
messages: + msg104786
2010-05-02 09:56:18ronaldoussorensetmessages: + msg104777
2010-05-02 09:50:14ronaldoussorensetresolution: fixed
messages: + msg104776
2009-10-28 09:16:37ned.deilysetassignee: ronaldoussoren

components: + Macintosh
nosy: + ronaldoussoren
2009-10-23 14:07:35dalkecreate