#!/usr/bin/env python3
"""List curogram-related cookie names/domains (values redacted) from CDP."""
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=10)
ws.send(json.dumps({"id": 1, "method": "Network.getAllCookies"}))
while True:
    m = json.loads(ws.recv())
    if m.get("id") == 1:
        res = m["result"]; break
ws.close()
for c in res.get("cookies", []):
    d = c.get("domain", "")
    if "curogram" in d:
        print(f"{c['name']}\t{d}\tlen={len(c.get('value',''))}")
