thenuke02/cs2-analyzer
0
1"""Take screenshots of the OpenSight UI for visual auditing.2 3Usage:4 python scripts/screenshot.py # Screenshot landing page5 python scripts/screenshot.py --url /analyze/ID # Screenshot specific page6 python scripts/screenshot.py --click "#tab-btn" # Click element then screenshot7 python scripts/screenshot.py --full # Full page screenshot8"""9 10import argparse11import sys12import time13 14from playwright.sync_api import sync_playwright15 16 17def take_screenshot(18 url="http://localhost:7860",19 output="screenshot.png",20 click=None,21 full_page=False,22 wait_ms=1000,23 width=1440,24 height=900,25):26 with sync_playwright() as p:27 browser = p.chromium.launch(headless=True)28 page = browser.new_page(viewport={"width": width, "height": height})29 page.goto(url, wait_until="networkidle", timeout=30000)30 time.sleep(wait_ms / 1000)31 32 if click:33 try:34 page.click(click, timeout=5000)35 time.sleep(0.5)36 except Exception as e:37 print(f"Click failed on '{click}': {e}", file=sys.stderr)38 39 page.screenshot(path=output, full_page=full_page)40 print(f"Screenshot saved: {output}")41 browser.close()42 43 44if __name__ == "__main__":45 parser = argparse.ArgumentParser(description="Screenshot OpenSight UI")46 parser.add_argument("--url", default="http://localhost:7860", help="URL to screenshot")47 parser.add_argument("--output", "-o", default="screenshot.png", help="Output file")48 parser.add_argument("--click", help="CSS selector to click before screenshot")49 parser.add_argument("--full", action="store_true", help="Full page screenshot")50 parser.add_argument("--wait", type=int, default=1000, help="Wait ms after load")51 parser.add_argument("--width", type=int, default=1440, help="Viewport width")52 parser.add_argument("--height", type=int, default=900, help="Viewport height")53 args = parser.parse_args()54 55 take_screenshot(56 url=args.url,57 output=args.output,58 click=args.click,59 full_page=args.full,60 wait_ms=args.wait,61 width=args.width,62 height=args.height,63 )64 