diff --git a/examples/agent-eyes-demo.py b/examples/agent-eyes-demo.py index fd26bf2..6ffccf5 100644 --- a/examples/agent-eyes-demo.py +++ b/examples/agent-eyes-demo.py @@ -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."""