]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44844: Enable detection of Microsoft Edge browser in webbrowser module (GH-29908)
authorSteve Dower <steve.dower@python.org>
Tue, 4 Apr 2023 16:00:03 +0000 (17:00 +0100)
committerGitHub <noreply@github.com>
Tue, 4 Apr 2023 16:00:03 +0000 (17:00 +0100)
Lib/test/test_webbrowser.py
Lib/webbrowser.py
Misc/NEWS.d/next/Library/2021-12-03-23-00-56.bpo-44844.tvg2VY.rst [new file with mode: 0644]

index 147a113c7fd7303095ab014a5f29441354fc76d6..2d695bc883131f1b745ed2fb70f9fc7e94432d48 100644 (file)
@@ -95,6 +95,31 @@ class ChromeCommandTest(CommandTestMixin, unittest.TestCase):
                    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
index d98c5997d2f44f882219bd3070b2fad60d7fbbcf..b86d131f030d805d1392b04bf40c21df0d48e2c7 100755 (executable)
@@ -400,6 +400,16 @@ class Konqueror(BaseBrowser):
         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
 #
@@ -456,6 +466,10 @@ def register_X_browsers():
         register("opera", None, Opera("opera"))
 
 
+    if shutil.which("microsoft-edge"):
+        register("microsoft-edge", None, Edge("microsoft-edge"))
+
+
 def register_standard_browsers():
     global _tryorder
     _tryorder = []
@@ -487,6 +501,8 @@ def register_standard_browsers():
                         "opera", edge64, edge32):
             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"):
diff --git a/Misc/NEWS.d/next/Library/2021-12-03-23-00-56.bpo-44844.tvg2VY.rst b/Misc/NEWS.d/next/Library/2021-12-03-23-00-56.bpo-44844.tvg2VY.rst
new file mode 100644 (file)
index 0000000..f0c9123
--- /dev/null
@@ -0,0 +1 @@
+Enables :mod:`webbrowser` to detect and launch Microsoft Edge browser.