Skip to content

bpo-44844: Enable detection of Microsoft Edge browser in webbrowser module #29908

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

Merged
merged 1 commit into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Lib/test/test_webbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,31 @@ def test_open_new_tab(self):
arguments=[URL])


class EdgeCommandTest(CommandTestMixin, unittest.TestCase):

browser_class = webbrowser.Edge

def test_open(self):
self._test('open',
options=[],
arguments=[URL])

def test_open_with_autoraise_false(self):
self._test('open', kw=dict(autoraise=False),
options=[],
arguments=[URL])

def test_open_new(self):
self._test('open_new',
options=['--new-window'],
arguments=[URL])

def test_open_new_tab(self):
self._test('open_new_tab',
options=[],
arguments=[URL])


class MozillaCommandTest(CommandTestMixin, unittest.TestCase):

browser_class = webbrowser.Mozilla
Expand Down
16 changes: 16 additions & 0 deletions Lib/webbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,16 @@ def open(self, url, new=0, autoraise=True):
return ok


class Edge(UnixBrowser):
"Launcher class for Microsoft Edge browser."

remote_args = ['%action', '%s']
remote_action = ""
remote_action_newwin = "--new-window"
remote_action_newtab = ""
background = True


#
# Platform support for Unix
#
Expand Down Expand Up @@ -518,6 +528,10 @@ def register_X_browsers():
if shutil.which("grail"):
register("grail", Grail, None)

if shutil.which("microsoft-edge"):
register("microsoft-edge", None, Edge("microsoft-edge"))


def register_standard_browsers():
global _tryorder
_tryorder = []
Expand Down Expand Up @@ -545,6 +559,8 @@ def register_standard_browsers():
"netscape", "opera", iexplore):
if shutil.which(browser):
register(browser, None, BackgroundBrowser(browser))
if shutil.which("MicrosoftEdge.exe"):
register("microsoft-edge", None, Edge("MicrosoftEdge.exe"))
else:
# Prefer X browsers if present
if os.environ.get("DISPLAY") or os.environ.get("WAYLAND_DISPLAY"):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Enables :mod:`webbrowser` to detect and launch Microsoft Edge browser.