import os, sys, json, time

os.environ["BU_NAME"] = "work"
sys.path.insert(0, "/opt/data/browser-harness")
from helpers import goto, wait_for_load, sleep, screenshot, cdp, click, scroll, list_tabs, page_info, new_tab, switch_tab
from admin import daemon_alive, start_remote_daemon

NAME = "work"
assert daemon_alive(NAME), "Browser not alive!"

# Navigate to BTS event page
print("Navigating to BTS event page...")
goto("https://ticketmaster.sg/activity/detail/26sg_bts")
wait_for_load()
sleep(5)
screenshot("/tmp/tm_03_bts_event.png")

# Get page content
result = cdp("Runtime.evaluate", expression="document.body.innerText.substring(0, 4000)", returnByValue=True)
print(f"Event page text: {result}")

# Get the URL 
result2 = cdp("Runtime.evaluate", expression="window.location.href", returnByValue=True)
print(f"Current URL: {result2}")