#!/usr/bin/env python3 """Render a verification verdict in the page, from a dossier decided outside it. usage: DOSSIER=/tmp/dossier.json run.py """ import asyncio import os import shutil from playwright.async_api import async_playwright HERE = os.path.dirname(os.path.abspath(__file__)) DOSSIER = os.environ.get("DOSSIER", "/tmp/dossier.json") PROFILE = os.path.join(HERE, "chromium-profile") PAGE = os.environ.get("PAGE", "http://127.0.0.1:8080/?chains=blake&network=xbt") async def main(): text = open(DOSSIER).read() print("dossier bytes:", len(text)) async with async_playwright() as p: context = await p.chromium.launch_persistent_context( PROFILE, viewport={"width": 1280, "height": 1600}) page = context.pages[0] if context.pages else await context.new_page() page.on("console", lambda m: print("console:", m.text)) cdp = await context.new_cdp_session(page) await cdp.send("Network.clearBrowserCache") await page.goto(PAGE, wait_until="load", timeout=60000) card = page.locator("#cards .card").first await card.locator("input").nth(0).fill("wss://swaprelay.smesh.lol") await page.get_by_role("button", name="Connect").click() await page.wait_for_function( "document.getElementById('connect-status').textContent.includes('connected')", timeout=120000) print("connected") await page.locator("#dossier").fill(text) await page.get_by_role("button", name="Verify").click() await page.wait_for_function( "document.getElementById('verify-report').textContent.includes('verified by')", timeout=60000) report = await page.locator("#verify-report").inner_text() print(report.splitlines()[:6]) await page.screenshot(path=os.path.join(HERE, "01-verdict.png"), full_page=True) await context.close() asyncio.run(main())