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

async def main():
    # Launch and connect
    cbm_cdp.launch_profile()
    browser = await cbm_cdp.connect(prefer_instagram=False)
    print("Connected to CBM")
    
    # Navigate to BTS event page with more wait time
    print("Navigating to BTS event page...")
    await browser.goto("https://ticketmaster.sg/activity/detail/26sg_bts", wait=10)
    
    # Check page state
    state = await cbm_cdp.page_state(browser)
    print(f"URL: {state['url']}")
    print(f"Title: {state['title']}")
    print(f"Warning: {state.get('warning')}")
    print(f"Has login: {state.get('hasLogin')}")
    print(f"Text (first 2000): {state['text'][:2000]}")
    
    # Screenshot
    await browser.screenshot("/tmp/cbm_tm_02_bts_event.png")
    print("Screenshot saved")
    
    await browser.close()

asyncio.run(main())