"""One-shot experiment: which minimal pref set keeps headless Firefox alive? Death signature (pw:browser logs): RenderCompositorSWGL failed mapping default framebuffer at ~0.8s, then 'Exiting due to channel error' and exit 0xC0000005 at ~2.6s. Fast operations finish first, which made earlier probes look green. Run: python -m browser_automation_agent.browser.prefs_matrix_probe """ from __future__ import annotations import asyncio import os from typing import Any from playwright.async_api import Playwright MATRIX = { "baseline": {}, "gpu-process-off": {"layers.gpu-process.enabled": False}, "webrender-off-basic": { "gfx.webrender.all": False, "layers.acceleration.disabled": True, }, "software-nogl": { "gfx.webrender.software": True, "gfx.webrender.software.opengl": False, }, } MOZ_ENV = { "MOZ_DISABLE_CONTENT_SANDBOX": "1", "MOZ_DISABLE_GFX_SANDBOX": "1", "MOZ_DISABLE_RDD_SANDBOX": "1", "MOZ_DISABLE_SOCKET_PROCESS_SANDBOX": "1", } async def trial(pw: Playwright, name: str, prefs: dict[str, Any]) -> None: browser = await pw.firefox.launch( headless=True, env={**os.environ, **MOZ_ENV}, firefox_user_prefs=prefs, ) ctx = await browser.new_context(viewport={"width": 1280, "height": 720}) page = await ctx.new_page() try: await page.goto("https://example.com/", wait_until="domcontentloaded", timeout=20000) title = await page.title() # The bomb historically explodes 2-3s in: prove we outlive it. await asyncio.sleep(5) alive = browser.is_connected() text = (await page.inner_text("body"))[:40] print(f"[{name}] alive-after-5s={alive} title={title!r} text={text!r}") except Exception as exc: # noqa: BLE001 — the experiment reports, never raises print(f"[{name}] DIED: {type(exc).__name__}: {str(exc)[:80]}") finally: try: await browser.close() except Exception as exc: # noqa: BLE001 — teardown must never mask the result print(f"[{name}] close failed: {type(exc).__name__}: {str(exc)[:80]}") async def main() -> None: from playwright.async_api import async_playwright from .probe import prepare_runtime_env prepare_runtime_env() pw = await async_playwright().start() try: for name, prefs in MATRIX.items(): await trial(pw, name, prefs) finally: await pw.stop() if __name__ == "__main__": asyncio.run(main())