#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import asyncio
from playwright.async_api import async_playwright

async def main():
    async with async_playwright() as p:
        b = await p.chromium.launch()
        # 桌面 600px (邮件常规宽度)
        pg = await b.new_page(viewport={"width": 640, "height": 960})
        await pg.goto("file:///root/web_reports/report_20260813_email.html")
        await pg.wait_for_load_state("networkidle")
        await pg.screenshot(path="/root/web_reports/mail_desktop_top.png")
        # 滚动中部
        await pg.evaluate("window.scrollTo(0, document.body.scrollHeight*0.35)")
        await pg.wait_for_timeout(250)
        await pg.screenshot(path="/root/web_reports/mail_desktop_mid.png")
        # 手机视口看溢出
        pg2 = await b.new_page(viewport={"width": 390, "height": 844})
        await pg2.goto("file:///root/web_reports/report_20260813_email.html")
        await pg2.wait_for_load_state("networkidle")
        ov = await pg2.evaluate("() => ({w: document.documentElement.scrollWidth, iw: window.innerWidth})")
        print("mobile overflow:", ov)
        await pg2.screenshot(path="/root/web_reports/mail_mobile_top.png")
        await b.close()
asyncio.run(main())
print("DONE")