import asyncio import json import websockets import requests async def inspect_window_bridge(): 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 standardKeys = new Set([ "window","self","document","name","location","customElements","history","locationbar","menubar", "personalbar","scrollbars","statusbar","toolbar","status","closed","frames","length","top","opener", "parent","frameElement","navigator","origin","external","screen","innerWidth","innerHeight", "scrollX","pageXOffset","scrollY","pageYOffset","visualViewport","screenX","screenY","outerWidth", "outerHeight","devicePixelRatio","clientInformation","screenLeft","screenTop","defaultStatus", "defaultstatus","styleMedia","onsearch","isSecureContext","onabort","onblur","oncancel","oncanplay", "oncanplaythrough","onchange","onclick","onclose","oncontextlost","oncontextmenu","oncontextrestored", "oncuechange","ondblclick","ondrag","ondragend","ondragenter","ondragleave","ondragover","ondragstart", "ondrop","ondurationchange","onemptied","onended","onerror","onfocus","onformdata","oninput","oninvalid", "onkeydown","onkeypress","onkeyup","onload","onloadeddata","onloadedmetadata","onloadstart","onmousedown", "onmouseenter","onmouseleave","onmousemove","onmouseout","onmouseover","onmouseup","onmousewheel", "onpause","onplay","onplaying","onprogress","onratechange","onreset","onresize","onscroll","onsecuritypolicyviolation", "onseeked","onseeking","onselect","onslotchange","onstalled","onsubmit","onsuspend","ontimeupdate","ontoggle", "onvolumechange","onwaiting","onwebkitanimationend","onwebkitanimationiteration","onwebkitanimationstart", "onwebkittransitionend","onwheel","onauxclick","ongotpointercapture","onlostpointercapture","onpointerdown", "onpointermove","onpointerrawupdate","onpointerup","onpointercancel","onpointerover","onpointerout", "onpointerenter","onpointerleave","onselectstart","onselectionchange","onanimationend","onanimationiteration", "onanimationstart","ontransitionrun","ontransitionstart","ontransitionend","ontransitioncancel","onafterprint", "onbeforeprint","onbeforeunload","onhashchange","onlanguagechange","onmessage","onmessageerror","onoffline", "ononline","onpagehide","onpageshow","onpopstate","onrejectionhandled","onstorage","onunhandledrejection", "onunload","crossOriginIsolated","scheduler" ]); const customKeys = Object.keys(window).filter(k => !standardKeys.has(k) && !k.startsWith('webkit') && !k.startsWith('on')); // Check for network request interception or analytics interceptor return { customKeys: customKeys, angular: typeof window.ng !== 'undefined', react: typeof window.__REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined', vue: typeof window.Vue !== 'undefined' }; })() """ await ws.send(json.dumps({ "id": 1, "method": "Runtime.evaluate", "params": { "expression": js, "returnByValue": True } })) res = json.loads(await ws.recv()) print(json.dumps(res.get("result", {}).get("result", {}).get("value", {}), indent=2, ensure_ascii=False)) if __name__ == "__main__": asyncio.run(inspect_window_bridge())