import asyncio import json import os import pathlib os.environ["LD_LIBRARY_PATH"] = ( "/tmp/multica-task-4070005680/debs/root/usr/lib/x86_64-linux-gnu" + (":" + os.environ["LD_LIBRARY_PATH"] if os.environ.get("LD_LIBRARY_PATH") else "") ) from playwright.async_api import async_playwright OUT = pathlib.Path("/tmp/multica-task-4070005680/opencode/chain") OUT.mkdir(exist_ok=True) URL = "http://192.168.200.12:8010/hel715-chain.html?auto=1" async def main(): async with async_playwright() as p: browser = await p.chromium.launch( args=["--autoplay-policy=no-user-gesture-required", "--no-sandbox"] ) ctx = await browser.new_context( viewport={"width": 1280, "height": 800}, record_video_dir=str(OUT), record_video_size={"width": 1280, "height": 800}, ) page = await ctx.new_page() errors = [] page.on("pageerror", lambda e: errors.append(str(e))) await page.goto(URL, wait_until="domcontentloaded") # wait for demo end marker (auto demo ~37s) try: await page.wait_for_function( "() => window.__chainLog && window.__chainLog.some(l => l.includes('AUTO-DEMO-END'))", timeout=60000, ) except Exception as e: errors.append(f"wait_for_function: {e}") await asyncio.sleep(1.5) logs = await page.evaluate("() => window.__chainLog") metrics = { "url": URL, "chain_log": logs, "pageerrors": errors, } (OUT / "chain-browser-log.json").write_text( json.dumps(metrics, ensure_ascii=False, indent=1) ) video = page.video await ctx.close() path = await video.path() await browser.close() print("video:", path) print("errors:", errors) print(json.dumps(logs, ensure_ascii=False, indent=1)) asyncio.run(main())