import sys, time
from pathlib import Path
from playwright.sync_api import sync_playwright

def test_chrome():
    chrome_worker = r"C:\Users\Admin\AntigravityProfiles\chrome_worker"
    with sync_playwright() as p:
        print("[1] Launching real Google Chrome with Profile 5 copy...")
        context = p.chromium.launch_persistent_context(
            user_data_dir=chrome_worker,
            channel="chrome",
            headless=True,
            args=[
                "--no-first-run",
                "--no-default-browser-check",
                "--disable-blink-features=AutomationControlled"
            ]
        )
        page = context.pages[0] if context.pages else context.new_page()
        
        print("[2] Navigating to https://muse.ai...")
        page.goto("https://muse.ai", wait_until="domcontentloaded", timeout=30000)
        time.sleep(4)
        
        screenshot_path = Path("04_Assets/real_chrome_muse_state.png").resolve()
        page.screenshot(path=str(screenshot_path))
        print("Saved screenshot to:", screenshot_path)
        
        print("URL:", page.url)
        body = page.locator("body").inner_text()
        print("Has 'Đoạn chat':", "Đoạn chat" in body)
        print("Has 'Đang kết nối':", "Đang kết nối" in body)
        print("Has textbox:", page.locator('textarea, [placeholder*="Nhắn tin"]').count())
        
        context.close()

if __name__ == '__main__':
    test_chrome()
