Skip to content

Commit fd1947e

Browse files
authored
bpo-44844: Enable detection of Microsoft Edge browser in webbrowser module (GH-29908)
1 parent 89e6a34 commit fd1947e

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

Lib/test/test_webbrowser.py

+25
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,31 @@ def test_open_new_tab(self):
9595
arguments=[URL])
9696

9797

98+
class EdgeCommandTest(CommandTestMixin, unittest.TestCase):
99+
100+
browser_class = webbrowser.Edge
101+
102+
def test_open(self):
103+
self._test('open',
104+
options=[],
105+
arguments=[URL])
106+
107+
def test_open_with_autoraise_false(self):
108+
self._test('open', kw=dict(autoraise=False),
109+
options=[],
110+
arguments=[URL])
111+
112+
def test_open_new(self):
113+
self._test('open_new',
114+
options=['--new-window'],
115+
arguments=[URL])
116+
117+
def test_open_new_tab(self):
118+
self._test('open_new_tab',
119+
options=[],
120+
arguments=[URL])
121+
122+
98123
class MozillaCommandTest(CommandTestMixin, unittest.TestCase):
99124

100125
browser_class = webbrowser.Mozilla

Lib/webbrowser.py

+16
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,16 @@ def open(self, url, new=0, autoraise=True):
400400
return ok
401401

402402

403+
class Edge(UnixBrowser):
404+
"Launcher class for Microsoft Edge browser."
405+
406+
remote_args = ['%action', '%s']
407+
remote_action = ""
408+
remote_action_newwin = "--new-window"
409+
remote_action_newtab = ""
410+
background = True
411+
412+
403413
#
404414
# Platform support for Unix
405415
#
@@ -456,6 +466,10 @@ def register_X_browsers():
456466
register("opera", None, Opera("opera"))
457467

458468

469+
if shutil.which("microsoft-edge"):
470+
register("microsoft-edge", None, Edge("microsoft-edge"))
471+
472+
459473
def register_standard_browsers():
460474
global _tryorder
461475
_tryorder = []
@@ -487,6 +501,8 @@ def register_standard_browsers():
487501
"opera", edge64, edge32):
488502
if shutil.which(browser):
489503
register(browser, None, BackgroundBrowser(browser))
504+
if shutil.which("MicrosoftEdge.exe"):
505+
register("microsoft-edge", None, Edge("MicrosoftEdge.exe"))
490506
else:
491507
# Prefer X browsers if present
492508
if os.environ.get("DISPLAY") or os.environ.get("WAYLAND_DISPLAY"):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Enables :mod:`webbrowser` to detect and launch Microsoft Edge browser.

0 commit comments

Comments
 (0)