import sys
sys.stdout.reconfigure(encoding='utf-8')
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.connect_over_cdp('http://localhost:9222')
    context = browser.contexts[0]
    page = context.pages[0] if context.pages else context.new_page()
    
    print('Current page title:', page.title())
    print('Current page URL:', page.url)
    
    # Save a full screenshot
    page.screenshot(path=r'C:\Projects\Historical\FacebookAutoPoster\sk_about_view.png', full_page=True)
    print('Saved sk_about_view.png')
    
    # Print the text in the main content area
    main_el = page.locator("div[role='main']")
    if main_el.count() > 0:
        print('=== MAIN CONTENT ===')
        for line in main_el.inner_text().split('\n'):
            if line.strip():
                print(line.strip())
