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!"

# Wait for page to fully load
sleep(5)
screenshot("/tmp/cbm_tm_02_state.png")

# Check current state
url = cdp("Runtime.evaluate", expression="window.location.href", returnByValue=True)
print(f"Current URL: {url}")

page_text = cdp("Runtime.evaluate", expression="document.body.innerText.substring(0, 3000)", returnByValue=True)
print(f"Page text: {page_text}")

# Check all tabs
tabs = list_tabs()
print(f"Tabs: {tabs}")