import sys, os
from playwright.sync_api import sync_playwright

sys.stdout.reconfigure(encoding="utf-8")
os.environ["DEBUG"] = "pw:browser*"

user_data = r"C:\Users\Admin\AppData\Local\Google\Chrome\User Data"

print("[1] Testing Playwright launch...", flush=True)
try:
    with sync_playwright() as p:
        args = [
            "--profile-directory=Profile 5",
            "--no-first-run",
            "--no-default-browser-check",
        ]
        context = p.chromium.launch_persistent_context(
            user_data_dir=user_data,
            channel="chrome",
            headless=True,
            args=args,
            timeout=15000
        )
        print("[2] Success!", flush=True)
        context.close()
except Exception as e:
    import traceback
    traceback.print_exc()
