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')
    context = browser.contexts[0]
    page = context.pages[0] if context.pages else context.new_page()
    page.goto('https://www.facebook.com/profile.php?id=61594841053758', wait_until='domcontentloaded')
    page.wait_for_timeout(4000)
    page.screenshot(path='FacebookAutoPoster/latest_profile_snapshot.png')
    
    # Check friends count
    friends_links = page.locator('a[href*="friends"]').all_inner_texts()
    print('Friends elements:', [f for f in friends_links if f.strip()])
    
    # Check notifications badge
    notif = page.locator('a[aria-label*="Notifications"], a[aria-label*="Thông báo"]').all_inner_texts()
    print('Notifications elements:', [n for n in notif if n.strip()])
    
    # Check feed posts text
    posts = page.locator('div[role="feed"]').inner_text() if page.locator('div[role="feed"]').count() > 0 else ""
    print('Recent post preview (first 200 chars):', repr(posts[:200]))
