Skip to content
This repository was archived by the owner on Jun 22, 2025. It is now read-only.

Commit a6b2963

Browse files
committed
Make Eel work with Microsoft Edge on Linux
1 parent 7e88610 commit a6b2963

File tree

3 files changed

+38
-26
lines changed

3 files changed

+38
-26
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ Consult the [documentation for PyInstaller](http://PyInstaller.readthedocs.io/en
344344

345345
## Microsoft Edge
346346

347-
For Windows 10 users, Microsoft Edge (`eel.start(.., mode='edge')`) is installed by default and a useful fallback if a preferred browser is not installed. See the examples:
347+
Generally, Microsoft Edge can be installed on both Windows and Linux. However, for users of Windows 10 and 11, Microsoft Edge (`eel.start(.., mode='edge')`) is installed by default, making it a useful fallback if an otherwise preferred browser is not installed. See these examples:
348348

349349
- A Hello World example using Microsoft Edge: [examples/01 - hello_world-Edge/](https://github.com/ChrisKnott/Eel/tree/master/examples/01%20-%20hello_world-Edge)
350350
- Example implementing browser-fallbacks: [examples/07 - CreateReactApp/eel_CRA.py](https://github.com/ChrisKnott/Eel/tree/master/examples/07%20-%20CreateReactApp/eel_CRA.py)

eel/edge.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,35 @@
1-
import platform
21
import subprocess as sps
32
import sys
4-
from typing import List
3+
from typing import List, Optional
54

65
from eel.types import OptionsDictT
76

87
name: str = 'Edge'
98

109

11-
def run(_path: str, options: OptionsDictT, start_urls: List[str]) -> None:
12-
cmd = 'start microsoft-edge:{}'.format(start_urls[0])
13-
sps.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr, stdin=sps.PIPE, shell=True)
10+
def run(path: str, options: OptionsDictT, start_urls: List[str]) -> None:
11+
if path.startswith('start microsoft-edge:'):
12+
cmd = 'start microsoft-edge:{}'.format(start_urls[0])
13+
sps.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr, stdin=sps.PIPE, shell=True)
14+
else:
15+
args: List[str] = options['cmdline_args'] + start_urls
16+
sps.Popen([path, '--new-window'] + args,
17+
stdout=sps.PIPE, stderr=sys.stderr, stdin=sps.PIPE)
1418

1519

16-
def find_path() -> bool:
17-
if platform.system() == 'Windows':
18-
return True
20+
def find_path() -> Optional[str]:
21+
if sys.platform in ['win32', 'win64']:
22+
return _find_edge_win()
23+
elif sys.platform.startswith('linux'):
24+
return _find_edge_linux()
25+
else:
26+
return None
1927

20-
return False
28+
29+
def _find_edge_linux() -> Optional[str]:
30+
import whichcraft as wch
31+
return wch.which('microsoft-edge') # type: ignore # whichcraft doesn't currently have type hints
32+
33+
34+
def _find_edge_win() -> str:
35+
return 'start microsoft-edge:'
Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import platform
32
import sys
43

54
# Use latest version of Eel from parent directory
@@ -21,18 +20,16 @@ def say_hello_py(x):
2120
say_hello_py('Python World!')
2221
eel.say_hello_js('Python World!') # Call a Javascript function
2322

24-
# Launch example in Microsoft Edge only on Windows 10 and above
25-
if sys.platform in ['win32', 'win64'] and int(platform.release()) >= 10:
26-
eel.start('hello.html', mode='edge')
27-
else:
28-
raise EnvironmentError('Error: System is not Windows 10 or above')
29-
30-
# # Launching Edge can also be gracefully handled as a fall back
31-
# try:
32-
# eel.start('hello.html', mode='chrome-app', size=(300, 200))
33-
# except EnvironmentError:
34-
# # If Chrome isn't found, fallback to Microsoft Edge on Win10 or greater
35-
# if sys.platform in ['win32', 'win64'] and int(platform.release()) >= 10:
36-
# eel.start('hello.html', mode='edge')
37-
# else:
38-
# raise
23+
# Set parameters irrespective of browser choice
24+
start_page = 'hello.html'
25+
window_size = (300, 200)
26+
# Launch example in Microsoft Edge if found
27+
try:
28+
eel.start(start_page, mode='edge', size=window_size)
29+
except EnvironmentError as exc1:
30+
# If Edge isn't found, attempt fallback to Chrome or raise error
31+
try:
32+
print("Try chrome...")
33+
eel.start(start_page, mode='chrome', size=window_size)
34+
except EnvironmentError as exc2:
35+
raise EnvironmentError(f'{exc1} AND {exc2}')

0 commit comments

Comments
 (0)