File size: 767 Bytes
f2ac853 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | from playwright.sync_api import sync_playwright
import pathlib, sys
f = sys.argv[1] if len(sys.argv) > 1 else "demo/cdhe-monitor.html"
out = sys.argv[2] if len(sys.argv) > 2 else "figures/demo.png"
w, h = (int(sys.argv[3]), int(sys.argv[4])) if len(sys.argv) > 4 else (1600, 920)
url = "file://" + str(pathlib.Path(f).resolve())
with sync_playwright() as p:
b = p.chromium.launch()
pg = b.new_page(viewport={"width": w, "height": h}, device_scale_factor=2)
errs = []
pg.on("console", lambda m: errs.append(f"{m.type}: {m.text}") if m.type == "error" else None)
pg.on("pageerror", lambda e: errs.append("pageerror: " + str(e)))
pg.goto(url)
pg.wait_for_timeout(1200)
pg.screenshot(path=out)
print("errors:", errs[:5])
b.close()
|