import asyncio import json import websockets import requests async def inspect_amplitude(): pages = requests.get("http://localhost:9222/json/list").json() ws_url = pages[0]["webSocketDebuggerUrl"] async with websockets.connect(ws_url, max_size=50*1024*1024) as ws: js = """ (() => { const res = { hasAmplitude: typeof window.amplitude !== 'undefined', hasDataLayer: typeof window.dataLayer !== 'undefined', hasGtag: typeof window.gtag !== 'undefined', amplitudeKeys: window.amplitude ? Object.keys(window.amplitude) : [], localStorageKeys: Object.keys(localStorage).filter(k => k.toLowerCase().includes('amp') || k.toLowerCase().includes('telecom')), url: window.location.href, title: document.title }; return res; })() """ await ws.send(json.dumps({ "id": 1, "method": "Runtime.evaluate", "params": { "expression": js, "returnByValue": True } })) res = json.loads(await ws.recv()) print("Inspection result:", json.dumps(res.get("result", {}).get("result", {}).get("value", {}), indent=2, ensure_ascii=False)) if __name__ == "__main__": asyncio.run(inspect_amplitude())