# -*- coding: utf-8 -*-
import sys, json, time, urllib.request
sys.stdout.reconfigure(encoding='utf-8')

HOST = "localhost"
PORT = 9222

def get_targets():
    url = f'http://{HOST}:{PORT}/json'
    with urllib.request.urlopen(url) as r:
        return json.loads(r.read().decode())

page = None
for t in get_targets():
    if 'appmsg' in t.get('url', '') and 'action=edit' in t.get('url', ''):
        page = t
        break

import websocket
ws = websocket.create_connection(page['webSocketDebuggerUrl'])
ws.settimeout(30)

# 检查元素是否有特殊的事件监听器
ws.send(json.dumps({
    'id': 1,
    'method': 'Runtime.evaluate',
    'params': {
        'expression': '''
        (function() {
            var el = document.getElementById("title");
            if (!el) return "not found";
            
            // 检查是否有Vue/React等框架的数据绑定
            var hasVue = !!el.__vue__ || !!el._vue;
            var hasReact = !!el._reactInternalFiber || !!el._reactInternalInstance;
            var hasAngular = !!el.ngModel;
            
            // 检查class
            var classes = el.className;
            
            return "classes: " + classes + ", vue: " + hasVue + ", react: " + hasReact + ", angular: " + hasAngular;
        })()
        '''
    }
}))
time.sleep(0.5)
response = ws.recv()
print('框架检查:', response[:300])

ws.close()
