#!/usr/bin/env python3
"""Screenshot bloquo.cc with stealth and longer waits"""

from playwright.sync_api import sync_playwright
try:
    from playwright_stealth import stealth_sync
    HAS_STEALTH = True
except ImportError:
    HAS_STEALTH = False

import time

OUTPUT_DIR = "/root/.openclaw/workspace/work/tools/visual-intake/bloquo"

TARGETS = [
    ("https://bloquo.cc/", "bloquo-homepage.png"),
    ("https://warped.bloquo.cc/", "bloquo-warped-cigars.png"),
    ("https://talkingwalls.co.il/", "bloquo-talkingwalls.png"),
    ("https://gellisfamilydomain.com/", "bloquo-gellis.png"),
]

def main():
    with sync_playwright() as p:
        browser = p.chromium.launch(
            headless=True,
            args=["--no-sandbox", "--disable-setuid-sandbox", "--disable-blink-features=AutomationControlled"]
        )
        context = browser.new_context(
            viewport={"width": 1440, "height": 900},
            user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36"
        )
        page = context.new_page()
        if HAS_STEALTH:
            stealth_sync(page)
            print("Stealth mode enabled")

        for url, fname in TARGETS:
            try:
                print(f"\nCapturing {url}...")
                page.goto(url, wait_until="networkidle", timeout=30000)
                time.sleep(5)
                
                # Get page dimensions
                dims = page.evaluate("() => ({ w: document.body.scrollWidth, h: document.body.scrollHeight, title: document.title })")
                print(f"  Page: {dims}")
                
                filepath = f"{OUTPUT_DIR}/{fname}"
                page.screenshot(path=filepath, full_page=True)
                
                import os
                size = os.path.getsize(filepath)
                print(f"  Saved: {filepath} ({size/1024:.1f}KB)")
                
            except Exception as e:
                print(f"  Error: {e}")

        browser.close()

if __name__ == "__main__":
    main()
