import sys
import time
from playwright.sync_api import sync_playwright

if hasattr(sys.stdout, 'reconfigure'):
    sys.stdout.reconfigure(encoding='utf-8')

with sync_playwright() as p:
    browser = p.chromium.connect_over_cdp("http://127.0.0.1:9224")
    page = browser.contexts[0].pages[0]

    # Đóng dialog nếu có
    page.keyboard.press("Escape")
    page.wait_for_timeout(1000)
    page.keyboard.press("Escape")
    page.wait_for_timeout(1000)

    # Đến trang profile
    page.goto("https://www.facebook.com/profile.php?id=61594841053758", wait_until="domcontentloaded")
    page.wait_for_timeout(4000)

    # Cuộn xuống
    page.mouse.wheel(0, 500)
    page.wait_for_timeout(2000)
    page.screenshot(path="FacebookAutoPoster/profile_posts_full.png")

    # Kiểm tra xem có text "300 WARSHIPS" không
    content = page.content()
    has_300 = "300 WARSHIPS" in content or "300 warships" in content.lower()
    print("Has '300 WARSHIPS' on profile:", has_300)

    # Kiểm tra notification xem có thông báo "Your video is ready" không
    notifs = page.locator('div[role="feed"]').all_inner_texts()
    print("Feed texts count:", len(notifs))
