Explorer
/proc/self/task/1751552/root/tmp/baseline_render.py
← Zurück ↓ Download
from playwright.sync_api import sync_playwright
URL="http://127.0.0.1:8771/index.html"
with sync_playwright() as p:
    b=p.chromium.launch()
    for w,h,label in [(390,844,"390x844"),(430,932,"430x932"),(768,1024,"768x1024")]:
        pg=b.new_page(viewport={"width":w,"height":h})
        pg.goto(URL,wait_until="networkidle"); pg.wait_for_timeout(400)
        pg.screenshot(path=f"/tmp/baseline_{label}_full.png", full_page=True)
        # top viewport
        pg.screenshot(path=f"/tmp/baseline_{label}_top.png")
        # hero region measure
        m=pg.evaluate("""()=>{const h=document.querySelector('.hero');const c=document.querySelector('.hero-copy');const hr=h.getBoundingClientRect();const cr=c?c.getBoundingClientRect():null;return {winW:innerWidth,docW:document.documentElement.scrollWidth,heroTop:hr.top,heroH:Math.round(hr.height),copyDisplay:c?getComputedStyle(c).display:null,copyRect:cr?{x:Math.round(cr.x),y:Math.round(cr.y),w:Math.round(cr.width),h:Math.round(cr.height)}:null,heroBg:getComputedStyle(h).backgroundImage.slice(0,40),heroBgPos:getComputedStyle(h).backgroundPosition};}""")
        print(f"[{label}]", m)
        pg.close()
    b.close()