#!/usr/bin/env python3
"""Deep dump of /settings: all clickable text, headings, and any element whose
text mentions password, to locate the Change Password trigger."""
import json, urllib.request
from websocket import create_connection
tabs=json.loads(urllib.request.urlopen("http://localhost:9223/json",timeout=8).read())
page=next(t for t in tabs if t.get("type")=="page" and "curogram.com" in (t.get("url") or "").lower())
ws=create_connection(page["webSocketDebuggerUrl"],timeout=20); _id=[0]
def call(m,p=None):
    _id[0]+=1; mid=_id[0]; ws.send(json.dumps({"id":mid,"method":m,"params":p or {}}))
    while True:
        x=json.loads(ws.recv())
        if x.get("id")==mid: return x.get("result",{})
call("Runtime.enable")
js=r"""
(()=>{
  const norm=s=>(s||'').replace(/\s+/g,' ').trim();
  const clickable=[];
  document.querySelectorAll('button,a,[role=button],[role=tab],mat-tab,[class*=tab],[class*=menu-item],li,div[role]').forEach(e=>{
    const t=norm(e.innerText||e.textContent);
    if(t && t.length<=45 && (e.onclick||e.getAttribute('role')||e.tagName==='BUTTON'||e.tagName==='A'||/tab|menu|item|btn|button/i.test(e.className))) clickable.push(t);
  });
  const pwEls=[];
  document.querySelectorAll('*').forEach(e=>{
    const t=norm(e.innerText||e.textContent);
    if(/change password/i.test(t) && t.length<60) pwEls.push({tag:e.tagName, cls:(e.className||'').toString().slice(0,60), text:t});
  });
  return JSON.stringify({clickable:[...new Set(clickable)].slice(0,60), pwEls:pwEls.slice(0,8)});
})()
"""
r=call("Runtime.evaluate",{"expression":js,"returnByValue":True})
print(r.get("result",{}).get("value"))
ws.close()
