37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
|
|
"""Connect to the SARS login Chromium via CDP and screenshot the page.
|
||
|
|
|
||
|
|
Usage: .venv\Scripts\python screenshot_dashboard.py <cdp_port> <output_path>
|
||
|
|
|
||
|
|
Reads the URL, waits for it to settle, then takes a full-page PNG.
|
||
|
|
"""
|
||
|
|
import sys
|
||
|
|
from pathlib import Path
|
||
|
|
from playwright.sync_api import sync_playwright
|
||
|
|
|
||
|
|
|
||
|
|
def main() -> int:
|
||
|
|
if len(sys.argv) != 3:
|
||
|
|
print(f"Usage: {sys.argv[0]} <cdp_port> <output_path>", file=sys.stderr)
|
||
|
|
return 2
|
||
|
|
port = int(sys.argv[1])
|
||
|
|
out = Path(sys.argv[2]).resolve()
|
||
|
|
|
||
|
|
with sync_playwright() as p:
|
||
|
|
browser = p.chromium.connect_over_cdp(f"http://127.0.0.1:{port}")
|
||
|
|
ctx = browser.contexts[0]
|
||
|
|
page = ctx.pages[0]
|
||
|
|
print(f"Connected. URL: {page.url}")
|
||
|
|
# Wait a beat for any in-flight navigation to settle.
|
||
|
|
try:
|
||
|
|
page.wait_for_load_state("domcontentloaded", timeout=5_000)
|
||
|
|
except Exception:
|
||
|
|
pass
|
||
|
|
out.parent.mkdir(parents=True, exist_ok=True)
|
||
|
|
page.screenshot(path=str(out), full_page=True)
|
||
|
|
print(f"Saved: {out}")
|
||
|
|
return 0
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
sys.exit(main())
|