Spaces:
Running
Running
Download scripts/shot.py from Ethscriptions/mx: direct link, hf CLI and curl.
- Browser
- Download file 1.23 kB
-
https://huggingface.co/spaces/Ethscriptions/mx/resolve/main/scripts/shot.py
- Command line
-
hf download hf://spaces/Ethscriptions/mx/scripts/shot.py
-
curl -L -o shot.py https://huggingface.co/spaces/Ethscriptions/mx/resolve/main/scripts/shot.py
1.23 kB
| """Screenshot helper: python3 scripts/shot.py out.png '<query string>' [w h]""" | |
| import sys, asyncio | |
| from playwright.async_api import async_playwright | |
| async def main(): | |
| out, qs = sys.argv[1], sys.argv[2] | |
| w = int(sys.argv[3]) if len(sys.argv) > 3 else 540 | |
| h = int(sys.argv[4]) if len(sys.argv) > 4 else 960 | |
| async with async_playwright() as p: | |
| b = await p.chromium.launch(args=["--use-gl=angle", "--use-angle=swiftshader", "--enable-unsafe-swiftshader", "--autoplay-policy=no-user-gesture-required"]) | |
| pg = await b.new_page(viewport={"width": w, "height": h}) | |
| logs = [] | |
| pg.on("console", lambda m: logs.append(m.type + ": " + m.text)) | |
| pg.on("pageerror", lambda e: logs.append("PAGEERROR: " + str(e))) | |
| await pg.goto("http://localhost:5173/preview/production/ed5ba841-ed53-4eec-a8c5-93237d26b7ab/?" + qs) | |
| try: | |
| await pg.wait_for_function("window.__done === true", timeout=90000) | |
| except Exception as e: | |
| logs.append("TIMEOUT " + str(e)[:100]) | |
| await pg.screenshot(path=out) | |
| for l in logs: | |
| if "error" in l.lower() or "TIMEOUT" in l or "INFO" in l: print(l[:900]) | |
| await b.close() | |
| asyncio.run(main()) | |