Spaces:
Running
Running
File size: 1,436 Bytes
8b9c053 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | import asyncio, sys, json
from playwright.async_api import async_playwright
BASE = sys.argv[1] if len(sys.argv) > 1 else "https://ethscriptions-mx.static.hf.space/"
async def main():
async with async_playwright() as p:
b = await p.chromium.launch(args=["--autoplay-policy=no-user-gesture-required"])
for vp in [{"width": 1400, "height": 900}, {"width": 390, "height": 844}]:
pg = await b.new_page(viewport=vp)
errs = []
pg.on("pageerror", lambda e: errs.append("PAGEERROR " + str(e)))
pg.on("console", lambda m: errs.append(m.type + ": " + m.text) if m.type in ("error",) else None)
pg.on("requestfailed", lambda r: errs.append("REQFAIL " + r.url[:100]))
await pg.goto(BASE)
await pg.wait_for_timeout(12000)
r = await pg.evaluate("""() => {
const f = []; document.fonts.forEach(x => f.push(x.family + ':' + x.status));
const c = document.querySelector('canvas');
return { fonts: f, canvas: c ? [c.width, c.height] : null,
sw: document.documentElement.scrollWidth, iw: innerWidth,
text: document.body.innerText.slice(0, 300) };
}""")
print(vp, json.dumps(r, ensure_ascii=False, indent=1))
for e in errs[:20]: print(" ", e)
await pg.close()
await b.close()
asyncio.run(main())
|