Update webbrowser.py to use Microsoft Edge as fallback instead of IE

webbrowser.py currently uses Internet Explorer as the fallback browser on Windows, if the user has not set a default browser.

# 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 shutil.which(browser):
            register(browser, None, BackgroundBrowser(browser))

I propose to update this code to point directly to Microsoft Edge, for the following reasons:

-IE is deprecated and no longer functional on most Windows installations today.
-Any Windows installation with current Python has had Microsoft Edge installed since release.
-It seems that certain enterprise policies will block the user from directly invoking IE (See this Github issue).

Here is my idea of how to implement this. edge32 is the installation directory for 32 bit windows. I am not sure if it’s really necessary to define as 32bit windows is also deprecated and market share data indicates it’s extremely low and shrinking.

# Detect some common Windows browsers, fallback to Edge
        edge = os.path.join(os.environ.get("PROGRAMFILES(x86)", "C:\\Program Files (x86)"),
                            "Microsoft\\Edge\\Application\\msedge.exe")
        edge32 = os.path.join(os.environ.get("PROGRAMFILES", "C:\\Program Files"),
                             "Microsoft\\Edge\\Application\\msedge.exe")
        for browser in ("firefox", "firebird", "seamonkey", "mozilla", "opera", edge, edge32):
            if shutil.which(browser):
                register(browser, None, BackgroundBrowser(browser))

This is my first time contributing an idea so any thoughts/suggestions/feedback is welcome. Is this worth creating a PR for?

As an aside, webbrowser.py contains handling for some ancient browsers (Mosaic, Netscape, Grail) with comments indicating they are rarely still used even in 2005. Should the handling for these be removed?

    # Next, Mosaic -- old but still in use.
    if shutil.which("mosaic"):
        register("mosaic", None, BackgroundBrowser("mosaic"))

    # Grail, the Python browser. Does anybody still use it?
    if shutil.which("grail"):
        register("grail", Grail, None)
2 Likes

Am I misremembering, or does start https://someurl.example/ open the user’s default web browser on Windows? That ought to be the preference if possible (like using xdg-open or equivalent on a Linux system).

Yes definitely, webbrowser.py first tries to access the users default browser and then tries a few other common browsers like chrome and firefox. This should be kept as is.

However, if both of these checks fail to find a browser I suggest the fallback should invoke Microsoft Edge directly instead of Internet Explorer.

1 Like

Ah yeah, so this is all handling the “we couldn’t figure out the default browser” case. Then sure, shouldn’t hurt to modernize it a tad.

1 Like

For reference:

1 Like