Skip to content
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

Make Eel work with Microsoft Edge on Linux #681

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ Consult the [documentation for PyInstaller](http://PyInstaller.readthedocs.io/en

## Microsoft Edge

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:
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:

- 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)
- Example implementing browser-fallbacks: [examples/07 - CreateReactApp/eel_CRA.py](https://github.com/ChrisKnott/Eel/tree/master/examples/07%20-%20CreateReactApp/eel_CRA.py)
33 changes: 24 additions & 9 deletions eel/edge.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
import platform
import subprocess as sps
import sys
from typing import List
from typing import List, Optional

from eel.types import OptionsDictT

name: str = 'Edge'


def run(_path: str, options: OptionsDictT, start_urls: List[str]) -> None:
cmd = 'start microsoft-edge:{}'.format(start_urls[0])
sps.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr, stdin=sps.PIPE, shell=True)
def run(path: str, options: OptionsDictT, start_urls: List[str]) -> None:
if path.startswith('start microsoft-edge:'):
cmd = 'start microsoft-edge:{}'.format(start_urls[0])
sps.Popen(cmd, stdout=sys.stdout, stderr=sys.stderr, stdin=sps.PIPE, shell=True)
else:
args: List[str] = options['cmdline_args'] + start_urls # type: ignore
sps.Popen([path, '--new-window'] + args,
stdout=sps.PIPE, stderr=sys.stderr, stdin=sps.PIPE)


def find_path() -> bool:
if platform.system() == 'Windows':
return True
def find_path() -> Optional[str]:
if sys.platform in ['win32', 'win64']:
return _find_edge_win()
elif sys.platform.startswith('linux'):
return _find_edge_linux()
else:
return None

return False

def _find_edge_linux() -> Optional[str]:
import whichcraft as wch
return wch.which('microsoft-edge') # type: ignore # whichcraft doesn't currently have type hints


def _find_edge_win() -> str:
return 'start microsoft-edge:'
29 changes: 13 additions & 16 deletions examples/01 - hello_world-Edge/hello.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import platform
import sys

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

# Launch example in Microsoft Edge only on Windows 10 and above
if sys.platform in ['win32', 'win64'] and int(platform.release()) >= 10:
eel.start('hello.html', mode='edge')
else:
raise EnvironmentError('Error: System is not Windows 10 or above')

# # Launching Edge can also be gracefully handled as a fall back
# try:
# eel.start('hello.html', mode='chrome-app', size=(300, 200))
# except EnvironmentError:
# # If Chrome isn't found, fallback to Microsoft Edge on Win10 or greater
# if sys.platform in ['win32', 'win64'] and int(platform.release()) >= 10:
# eel.start('hello.html', mode='edge')
# else:
# raise
# Set parameters irrespective of browser choice
start_page = 'hello.html'
window_size = (300, 200)
# Launch example in Microsoft Edge if found
try:
eel.start(start_page, mode='edge', size=window_size)
except EnvironmentError as exc1:
# If Edge isn't found, attempt fallback to Chrome or raise error
try:
print("Try chrome...")
eel.start(start_page, mode='chrome', size=window_size)
except EnvironmentError as exc2:
raise EnvironmentError(f'{exc1} AND {exc2}')
Loading