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()
    
    # Evaluate JavaScript to find all clickable elements in the left sidebar under "About"
    items = page.evaluate("""() => {
        const results = [];
        const links = document.querySelectorAll('a, div[role="button"], div[role="tab"]');
        for (let l of links) {
            const text = l.innerText ? l.innerText.trim() : '';
            if (['Intro', 'Personal details', 'Work', 'Education', 'Hobbies', 'Interests', 'Travel', 'Links', 'Contact info', 'Names', 'Details about you', 'Bio', 'About you', 'Pinned details'].includes(text)) {
                results.push({
                    text: text,
                    tag: l.tagName,
                    href: l.getAttribute('href'),
                    role: l.getAttribute('role'),
                    classes: l.className
                });
            }
        }
        return results;
    }""")
    print("Found items in left sidebar:")
    for item in items:
        print(item)
