This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Improve webbrowser (.open) doc and behavior
Type: behavior Stage: needs patch
Components: Documentation, Library (Lib) Versions: Python 3.3, Python 3.4
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: eric.araujo, ezio.melotti, georg.brandl, orsenthil, terry.reedy
Priority: normal Keywords:

Created on 2010-12-31 03:47 by terry.reedy, last changed 2022-04-11 14:57 by admin.

Messages (8)
msg124949 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2010-12-31 03:47
webbrowser.open (and two aliases):

1. document return value, which seems to be: True if a browser tab or window is opened, regardless of whether or not the url is found; False otherwise.

2. document that (on Windows, at least) the default browser only gets used if a non .htm(l) url starts with 'www' or 'http:'.

This is true because os.startfile(url) apparently only works if above is true, as required for the Start/Run box to recognize an entry as a url.

In particular, I have Firefox as default and 'www.google.com' and 'http://bugs.python.org' get opened in Firefox (new tab as requested). However, 'google.com' and 'bugs.python.org' open with IE after some delay. [Start/run either opens with Firefox or reports 'cannot find'.]
-----

In the longer run, what I would really like is for webbrowser to be better at using the default or finding executables.

I thought of adding 'http://' if not present but that would disable opening files in a file browser.

I suspect there is a registry entry but do not know what it is. That would also pick up new browswers like Chrome.

It seems to me that the current behavior is a 'limitation' in this code:

    # Detect some common Windows browsers, fallback to IE
    iexplore = os.path.join(os.environ.get("PROGRAMFILES", "C:\\Program Files"),
                            "Internet Explorer\\IEXPLORE.EXE")
    for browser in ("firefox", "firebird", "seamonkey", "mozilla",
                    "netscape", "opera", iexplore):
        if _iscommand(browser):
            register(browser, None, BackgroundBrowser(browser))

Firefox is not being recognized as a command because _iscommand('firefox') does not not see firefox.exe as an executable because it only checks _isexecutable() in the hodgepodge list of paths in PATH. At one time (but no longer), executables were ofter put in c:/windows, which by default is in PATH.

Since you hardcoded the default real path for iexplore (C:\\Program Files\\"Internet Explorer\\IEXPLORE.EXE"), you could do the same for other programs: 

firefox = os.path.join(os.environ.get("PROGRAMFILES", "C:\\Program Files"), "Mozilla Firefox\\firefox.exe")
msg126056 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-01-12 00:23
> I thought of adding 'http://' if not present but that would disable opening files in a file browser.

I think that’s a Windows-specific behavior, not a promise of the *web*browser module.
msg126921 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2011-01-24 11:14
On Wed, Jan 12, 2011 at 12:23:31AM +0000, Éric Araujo wrote:
> > I thought of adding 'http://' if not present but that would
> > disable opening files in a file browser.
> 
> I think that’s a Windows-specific behavior, not a promise of the
> *web*browser module.

If being lenient with URLs which do not start with http:// is the
idea, then webbrowser module can do explicitly add that. Having a
default protocol option in the open method and we can set it to
'http'.  Many WWW browsers do that.

But, I agree that it should not be related to Windows file-browser
behavior (for whatever it's behavior is).
msg137614 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2011-06-04 00:13
Upon further experimentation, I realize that I can only open in Firefox because I have it set as my default browser. It would otherwise be inaccessible because it is not in the _browser registry. It also appears that I cannot intentionally use Internet Explorer because it also in not registered (except under the full path names used as a backup).

>>> webbrowser._browsers
{'windows-default': [<class 'webbrowser.WindowsDefault'>, None], 'c:\\program files\\internet explorer\\iexplore.exe': [None, <webbrowser.BackgroundBrowser object at 0x01000ED0>]}

If I understand the Windows code quoted before, the Class Names in the table would be different (BackgroundBrowser) on Windows if it did work.

Related issues
#8232 webbrowser.open incomplete on Windows
#8936 webbrowser regression on windows
#12237 Document how to open non-default webbrowser
msg182922 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-02-25 06:18
Before closing #8936, I realized that perhaps my user default browser *is* being called but is returning an error code. It does not really matter, where the error code comes from. I think 'using the default browser' should be expanded to ''using the first default browser that claims to succeed.'. Also, 'default browser list' should be explained in a sentence before the one about over-riding it with an env. var. It depends on the software on the machine at import in addition to the platform.
msg182923 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-02-25 06:21
I no longer think we should touch the url; just pass it to each browser in turn, as needed, and let the user get the result.
msg183108 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-02-27 03:49
On WinXP, if I try "firefox bugs.python.org", I get an error because it can not find firefox in the PATH.  This is probably what happens with _isexecutable("firefox").
However if I try "C:\Program Files\Mozilla Firefox\>firefox.exe bugs.python.org", Firefox correctly opens the page.

So I think that the problem here is not that the browser fails to open "bugs.python.org" or "google.com", but that the executable of the browser is not found, and whatever is used to open "bugs.python.org" (os.startfile()?) doesn't know that it should be opened with Firefox.

> In the longer run, what I would really like is for webbrowser to be
> better at using the default or finding executables.

I haven't looked at the code, but, if reasonable, it should search in some common folders for the executables of the supported browsers.

Should I create a separate issue for this?  If this solution is not viable, we can always document that the URLs have to start with 'http://' or 'www.'.
msg185444 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2013-03-28 12:57
I do not know if 'must' is true on all systems, but I certainly think we should say that a full url 'might be required' to succeed.

On win7, "C:/program files (86)/mozilla firefox" (until mozilla decides to distribute a 64-bit version ;-).
History
Date User Action Args
2022-04-11 14:57:10adminsetgithub: 55008
2013-03-28 12:57:16terry.reedysetmessages: + msg185444
2013-03-28 10:05:29georg.brandlsetassignee: georg.brandl ->
2013-02-27 03:49:21ezio.melottisetmessages: + msg183108
2013-02-25 06:21:18terry.reedysetmessages: + msg182923
versions: + Python 3.3, Python 3.4, - Python 3.2
2013-02-25 06:18:45terry.reedysetmessages: + msg182922
2011-08-13 09:58:06ezio.melottisetnosy: + ezio.melotti
2011-06-04 00:13:33terry.reedysettype: behavior
messages: + msg137614
components: + Documentation
title: Improve webbrowser.open doc (and, someday, behavior?) -> Improve webbrowser (.open) doc and behavior
2011-06-04 00:12:54terry.reedylinkissue12237 superseder
2011-01-24 11:14:06orsenthilsetnosy: + orsenthil
messages: + msg126921
2011-01-12 00:23:26eric.araujosetnosy: + eric.araujo
messages: + msg126056
2010-12-31 03:47:29terry.reedycreate