examples: sandboxed chromium by default, with a --no-sandbox fallback

This commit is contained in:
Hermenix committed 2026-09-30 19:35:03 +00:00
1 parent 36541d22f4
commit f667654f01
1 file changed
+30 -10
+30 -10
View File
@@ -122,18 +122,18 @@ def clear_screen(runtime_dir: str) -> None:
time.sleep(1.0)
def start_browser(env: dict, *, url: str, port: int, home: pathlib.Path,
fullscreen: bool = False) -> subprocess.Popen:
home.mkdir(parents=True, exist_ok=True)
def _browser_argv(env: dict, *, url: str, port: int, home: pathlib.Path,
fullscreen: bool, unsandboxed: bool) -> list[str]:
profile = home / "profile"
env = {**env, "HOME": str(home)}
argv = [
return [
"chromium",
"--ozone-platform=wayland",
# The compositor is a system service with no user manager and the kernel
# here has no working user-namespace sandbox set up; this is the same
# invocation the module's own manual testing used.
"--no-sandbox",
# The sandbox works on this machine, so it is on by default. When it
# does not, the fallback needs `--test-type` as well: without it Chromium
# paints "you are using an unsupported command-line flag: --no-sandbox"
# across the top of the page, and that banner would be in every frame of
# the recording.
*(["--no-sandbox", "--test-type"] if unsandboxed else []),
"--disable-dev-shm-usage",
# Windowed by default: the session's wallpaper, gaps and window borders
# are the point of filming a *desktop*, and a kiosk window hides all of
@@ -149,11 +149,31 @@ def start_browser(env: dict, *, url: str, port: int, home: pathlib.Path,
"--remote-debugging-address=127.0.0.1",
url,
]
def start_browser(env: dict, *, url: str, port: int, home: pathlib.Path,
fullscreen: bool = False) -> subprocess.Popen:
home.mkdir(parents=True, exist_ok=True)
env = {**env, "HOME": str(home)}
argv = _browser_argv(env, url=url, port=port, home=home,
fullscreen=fullscreen, unsandboxed=False)
log(f"browser: starting chromium (debug port {port}, "
f"{'kiosk' if fullscreen else 'windowed'}) at {url}")
return subprocess.Popen(argv, env=env, stdout=subprocess.DEVNULL,
proc = subprocess.Popen(argv, env=env, stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)
# A sandboxed Chromium can die on launch (no user namespaces, no setuid
# helper). Give it a moment, and fall back rather than filming an empty
# desktop and calling it a demo.
time.sleep(2.5)
if proc.poll() is not None:
log("browser: sandboxed launch exited; retrying with --no-sandbox")
argv = _browser_argv(env, url=url, port=port, home=home,
fullscreen=fullscreen, unsandboxed=True)
proc = subprocess.Popen(argv, env=env, stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)
return proc
def cdp_target(port: int, timeout: float = 30.0) -> str:
"""Wait for the DevTools endpoint and return the page target's ws URL."""