from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.connect_over_cdp('http://localhost:9222')
    page = browser.contexts[0].pages[0]
    page.goto('https://www.facebook.com/me', wait_until='domcontentloaded', timeout=30000)
    page.wait_for_timeout(3000)
    
    # Tìm text 'Add bio' hoặc các nút liên quan đến Bio trên trang chủ profile
    print('Searching for Bio elements on profile...')
    for el in page.locator("text=/bio/i").all():
        print('Bio text match:', el.evaluate('e => e.outerHTML[:120]'))
        
    print('Checking role=button texts:')
    for b in page.locator("div[role='button'], span[role='button']").all():
        t = b.inner_text().strip().replace('\n', ' ')
        if any(w in t.lower() for w in ['bio', 'edit', 'add', 'intro']):
            print('  ->', t)
            
    page.screenshot(path=r'C:\Projects\Historical\FacebookAutoPoster\profile_for_bio.png')
    browser.close()
