import asyncio, sys, os, json, time
sys.path.insert(0, '/opt/data/scripts')
import cbm_cdp

async def main():
    # Launch the CBM profile first
    print("Launching CBM profile...")
    cbm_cdp.launch_profile()
    print("Profile launched/running")
    
    # Connect via CDP
    print("Connecting to CBM browser...")
    browser = await cbm_cdp.connect(prefer_instagram=False)
    print("Connected!")
    
    # Navigate to Ticketmaster login
    print("Navigating to Ticketmaster SG...")
    await browser.goto("https://ticketmaster.sg/activity/detail/26sg_bts", wait=8)
    
    # Check page state
    state = await cbm_cdp.page_state(browser)
    print(f"Page state: url={state['url']}, title={state['title']}")
    print(f"Warning: {state.get('warning')}")
    print(f"Text preview: {state['text'][:500]}")
    
    # Screenshot
    await browser.screenshot("/tmp/cbm_tm_01_bts_page.png")
    print("Screenshot saved")
    
    await browser.close()

asyncio.run(main())