CLI: Fixed bug in firefox opening addon page because of new profile
All checks were successful
checks-impure / test (pull_request) Successful in 59s
checks / test (pull_request) Successful in 2m1s

This commit is contained in:
Luis Hebendanz 2023-10-08 14:39:31 +02:00
parent af1b8f68e7
commit 9c74c4d661

View File

@ -1,10 +1,7 @@
import argparse import argparse
import logging import logging
import os
import shutil import shutil
import signal
import subprocess import subprocess
import tempfile
import time import time
import urllib.request import urllib.request
from contextlib import ExitStack, contextmanager from contextlib import ExitStack, contextmanager
@ -21,34 +18,23 @@ log = logging.getLogger(__name__)
def open_browser(base_url: str, sub_url: str) -> None: def open_browser(base_url: str, sub_url: str) -> None:
with tempfile.TemporaryDirectory() as tmpdir: for i in range(5):
for i in range(5):
try:
urllib.request.urlopen(base_url + "/health")
break
except OSError:
time.sleep(i)
url = f"{base_url}/{sub_url.removeprefix('/')}"
proc = _open_browser(url, tmpdir)
try: try:
proc.wait() urllib.request.urlopen(base_url + "/health")
print("Browser closed") break
os.kill(os.getpid(), signal.SIGINT) except OSError:
finally: time.sleep(i)
proc.kill() url = f"{base_url}/{sub_url.removeprefix('/')}"
proc.wait() _open_browser(url)
def _open_browser(url: str, tmpdir: str) -> subprocess.Popen: def _open_browser(url: str) -> subprocess.Popen:
for browser in ("firefox", "iceweasel", "iceape", "seamonkey"): for browser in ("firefox", "iceweasel", "iceape", "seamonkey"):
if shutil.which(browser): if shutil.which(browser):
cmd = [ cmd = [
browser, browser,
"-kiosk", "-kiosk",
"-private-window", "-new-window",
"--new-instance",
"--profile",
tmpdir,
url, url,
] ]
print(" ".join(cmd)) print(" ".join(cmd))