import json

try:
    with open(r'C:\Users\Variet-Worker\.gemini\antigravity\bridge\deep-inspect-result.json', 'r', encoding='utf-8', errors='ignore') as f:
        data = json.load(f)

    # Print first 50 buttons from nodes
    count = 0
    print('=== First 100 Buttons in DOM Nodes ===')
    for node in data.get('nodes', []):
        label = node.get('label', 'unknown')
        btns = node.get('buttons', [])
        if btns:
            print(f'\n[Node] {label}')
            for b in btns:
                t = b.get('text', '').replace('\n', ' ').strip()
                hidden = b.get("hidden")
                cls = b.get("class")
                if t:
                    print(f'  - "{t[:50]}" (Hidden: {hidden}, Class: {cls[:30]})')
                    count += 1
                if count > 100:
                    break
        if count > 100:
            break

    # Print first 50 buttons from webviews
    count = 0
    print('\n=== First 100 Buttons in Webviews ===')
    for probe in data.get('webviewProbes', []):
        if probe.get('success'):
            pd = probe.get('data', {})
            btns = pd.get('buttons', [])
            label = pd.get('title', 'Unknown Title') + f" (URL: {pd.get('url', 'Unknown URL')})"
            if btns:
                print(f'\n[WebviewProbe {probe.get("index")}] {label}')
                for b in btns:
                    t = b.get('text', '').replace('\n', ' ').strip()
                    hidden = b.get("hidden")
                    cls = b.get("class")
                    if t:
                        print(f'  - "{t[:50]}" (Hidden: {hidden}, Class: {cls[:30]})')
                        count += 1
                    if count > 100:
                        break
        if count > 100:
            break

except Exception as e:
    print(f'Error reading JSON: {e}')
