browser-edge-cases
SOP for debugging browser automation failures on complex websites. Use when browser tools fail on specific sites like LinkedIn, Twitter/X, SPAs, or sites with Shadow DOM.
Choose how to use this skill
You do not need every option. Choose the path your AI client supports. The stable page stays the same; versioned files are immutable.
1. Native installer
This listing has no registered native installer command. Use the complete package or source fallback below, depending on what your client supports.
Do not guess an installer command or replace an existing version without reviewing the diff.
2. Complete package recommended
Download the ZIP when available. It includes SKILL.md plus the references, security notes and version metadata.
No complete ProSkills package is published for this listing yet.3. Prompt-only
Copy the prompt above when the agent can read the stable page or when you want to adopt the workflow without installing a skill.
Need only the instruction file?
Download SKILL.md only if your client requires a single file. The complete ZIP is safer for a full installation because it preserves the references and release context.
No path installs or executes anything by itself. Your agent still needs access to the project files. Before updating, compare the installed version and review the diff.
// RATINGS
Not yet listed on ClawHub or SkillsMP
// README
What you just watched
A growth team preparing a Show HN wants to know how five developer tools' own launches did on Hacker News. Here's what Hive did with that one message:
- You hand it to a queen. Queens are long-lived agents with a role (here, Head of Growth) and their own memory and tools.
- She asks the one question that changes the answer: every launch post, or only each product's original launch? You pick every launch, and she carries on.
- She proposes a colony, and you approve it. Five products means five parallel jobs, so the chat becomes a colony: the queen plus as many worker agents as the work needs.
- She does one herself. She takes PostHog first, works out what counts as a genuine launch post rather than a passing mention, checks the numbers against the Hacker News API, and saves the method as a reusable skill.
- She fans out. A playbook starts one worker per product. Each follows her skill and writes its result to the colony's tracker, a shared SQLite table.
- She checks every row before she answers, and fixes one. Cal.com's worker counted a post from its old name, Calendso, but that post wasn't a Show HN, Launch HN or YC launch. She clears the row, and the chart shows Cal.com as not found rather than zero.
None of this was wired up in advance. There's no workflow graph to draw: the queen shapes the colony as the work unfolds, and a tracker on disk, not a context window, keeps count of what's done and what's left.
Quick start
You'll need Python 3.11+, Node.js 20+ and git. The quickstart installs uv and ripgrep if they're missing, and offers to install Node.
And a model. The quickstart sets up any of these:
- an API key from Anthropic, OpenAI, Google Gemini, Groq, Cerebras or OpenRouter
- a coding subscription you already pay for: Claude Code, OpenAI Codex, Kimi Code, MiniMax, Z.AI or Antigravity
- Hive LLM
- a local model through Ollama, with no key at all
git clone https://github.com/aden-hive/hive.git
cd hive
./quickstart.sh # macOS / Linux
.\quickstart.ps1 # Windows (PowerShell 5.1+)
The quickstart creates a single Python environment for the workspace, stores your API key encrypted under ~/.hive, asks which model to use, builds the dashboard and opens it at http://127.0.0.1:8787. Next time, run hive open from the repository.
[!NOTE] This repository is a
uvworkspace:pip install -e .at its root installs a placeholder that won't run, so use the quickstart. Without the repository,pip install "aden-hive[tools]"installs Hive from PyPI; then runhive open. To add an optional package (a chat-app channel, for example), see Optional packages. To build your own project on Hive's agent loop and models, depend onaden-hive: see Building on Hive.
Then type a task on the home screen and choose the queen to give it to, or open the Prompt Library and send a ready-made prompt straight to the queen it was written for.
How it works
flowchart LR
You(["You"]) -->|"describe the outcome"| Queen["Queen<br/>(persistent agent)"]
Queen -->|"proposes a colony,<br/>you approve"| Pilot["Pilot<br/>(one unit, done by the queen)"]
Pilot -->|"saves the method"| Skill["Skill + playbook"]
Skill -->|"run_worker / run_playbook"| W["Worker clones<br/>in parallel"]
W -->|"tracker_upsert"| T[("Tracker<br/>shared SQLite")]
T -->|"SQL: what's done,<br/>what's left"| Queen
Queen -->|"checked answer"| You
style Queen fill:#ffb100,stroke:#cc5d00,color:#333
style T fill:#fff3d6,stroke:#cc5d00,color:#333
style W fill:#ff9800,stroke:#cc5d00,color:#fff
Hive has one execution primitive: the agent loop. The queen is one, and every worker is a clone of it with its own task, a narrower set of tools and a strict budget. Orchestration is a tool call, not a compiled graph:
run_workerfans tasks out and returns at once, so the queen keeps talking to you while workers run. Four run at a time by default; the rest wait their turn. Each worker's report arrives in the queen's conversation as a new turn.- The tracker is the colony's shared state. The queen defines the table and which columns workers may write, workers upsert one row per unit of work, and the queen checks progress with SQL. It's a file on disk:
~/.hive/colonies/<name>/tracker/tracker.db. run_playbookruns a proven method over every row, with retries and backoff, rate-limited lanes, and a dead-letter list for rows that keep failing. "What's left" is always a fresh query of the tracker, so re-running a playbook picks up where it stopped.
The architecture overview goes deeper: the loop, the tool surface, memory, human oversight, and how state survives a crash.
// HOW IT'S BUILT
// FILES
13 files shipped with this skill. Inline text is the catalog copy. The upstream link is the source repository.
.claude/skills/browser-edge-cases/SKILL.md6.9 KB65ddaea90a0bupstream ↗
--- name: browser-edge-cases description: SOP for debugging browser automation failures on complex websites. Use when browser tools fail on specific sites like LinkedIn, Twitter/X, SPAs, or sites with Shadow DOM. license: MIT --- # Browser Tool Edge Cases Standard Operating Procedure for debugging and fixing browser automation failures on complex websites. ## When to Use This Skill - `browser_interact(action="scroll")` succeeds but page doesn't move - `browser_interact(action="left_click")` succeeds but no action triggered - `browser_interact(action="type")` text disappears or doesn't work - `browser_snapshot` hangs or returns stale content - `browser_navigate` loads wrong content ## SOP: Debugging Browser Tool Failures ### Phase 1: Reproduce & Isolate ``` 1. Create minimal test case demonstrating failure 2. Test against simple site (example.com) to verify tool works 3. Test against problematic site to confirm issue ``` **Quick isolation test:** ```python # Test 1: Does the tool work at all? await browser_navigate(tab_id, "https://example.com") result = await browser_interact(action="scroll", tab_id=tab_id, scroll_direction="down", scroll_amount=100) # Should work on simple sites # Test 2: Does it fail on the problematic site? await browser_navigate(tab_id, "https://linkedin.com/feed") result = await browser_interact(action="scroll", tab_id=tab_id, scroll_direction="down", scroll_amount=100) # If this fails but example.com works → site-specific edge case ``` ### Phase 2: Analyze Root Cause **Step 2a: Check console for errors** ```python console = await browser_console(tab_id) # Look for: CSP violations, React errors, JavaScript exceptions ``` **Step 2b: Inspect DOM structure** ```python html = await browser_html(tab_id) snapshot = await browser_snapshot(tab_id) # Look for: # - Nested scrollable divs (overflow: scroll/auto) # - Shadow DOM roots # - iframes # - Custom widgets ``` **Step 2c: Identify the pattern** | Symptom | Likely Cause | Check | |---------|--------------|-------| | Scroll doesn't move | Nested scroll container | Look for `overflow: scroll` divs | | Click no effect | Element covered | Check `getBoundingClientRect` vs viewport | | Type clears | Autocomplete/React | Check for event listeners on input; try a `type` action with no selector | | Snapshot hangs | Huge DOM | Check node count in snapshot | | Snapshot stale | SPA hydration | Wait after navigation | ### Phase 3: Implement Multi-Layer Fix **Pattern: Always have fallbacks** ```python async def robust_operation(tab_id): # Method 1: Primary approach try: result = await primary_method(tab_id) if verify_success(result): return result except Exception: pass # Method 2: CDP fallback try: result = await cdp_fallback(tab_id) if verify_success(result): return result except Exception: pass # Method 3: JavaScript fallback return await javascript_fallback(tab_id) ``` **Pattern: Always add timeouts** ```python # Bad - can hang forever result = await browser_snapshot(tab_id) # Good - fails fast with useful error try: result = await browser_snapshot(tab_id, timeout_s=10.0) except asyncio.TimeoutError: # Handle timeout gracefully result = await fallback_snapshot(tab_id) ``` ### Phase 4: Verify Fix ``` 1. Run against problematic site → should work 2. Run against simple site → should still work (regression check) 3. Document in registry.md ``` ## Pattern Library ### P1: Nested Scrollable Containers **Sites:** LinkedIn, Twitter/X, any SPA with scrollable feeds **Detection:** ```javascript // Find largest scrollable container const candidates = []; document.querySelectorAll('*').forEach(el => { const style = getComputedStyle(el); if (style.overflow.includes('scroll') || style.overflow.includes('auto')) { const rect = el.getBoundingClientRect(); if (rect.width > 100 && rect.height > 100) { candidates.push({el, area: rect.width * rect.height}); } } }); candidates.sort((a, b) => b.area - a.area); return candidates[0]?.el; ``` **Fix:** Dispatch scroll events at container's center, not viewport center. ### P2: Element Covered by Overlay **Sites:** Modals, tooltips, SPAs with loading overlays **Detection:** ```javascript const rect = element.getBoundingClientRect(); const centerX = rect.left + rect.width / 2; const centerY = rect.top + rect.height / 2; const topElement = document.elementFromPoint(centerX, centerY); return topElement === element || element.contains(topElement); ``` **Fix:** Wait for overlay to disappear, or use JavaScript click. ### P3: React Synthetic Events **Sites:** React SPAs, modern web apps **Detection:** If CDP click doesn't trigger handler but manual click works. **Fix:** Use JavaScript click as primary: ```javascript element.click(); ``` ### P4: Huge DOM / Accessibility Tree **Sites:** LinkedIn, Facebook, Twitter (feeds with 1000s of nodes) **Detection:** ```javascript document.querySelectorAll('*').length > 5000 ``` **Fix:** 1. Add timeout to snapshot operation 2. Truncate tree at 2000 nodes 3. Fall back to DOM-based snapshot if accessibility tree too large ### P5: SPA Hydration Delay **Sites:** React, Vue, Angular SPAs after navigation **Detection:** ```javascript // Check if React app has hydrated document.querySelector('[data-reactroot]') || document.querySelector('[data-reactid]') ``` **Fix:** Wait for specific selector after navigation: ```python await browser_navigate(tab_id, url, wait_until="load") await browser_interact(action="wait", tab_id=tab_id, wait_for_selector='[data-testid="content"]', timeout_ms=5000) ``` ### P6: Shadow DOM **Sites:** Components using Shadow DOM, Lit elements **Detection:** ```javascript document.querySelectorAll('*').some(el => el.shadowRoot) ``` **Fix:** Pierce shadow root: ```javascript function queryShadow(selector) { const parts = selector.split('>>>'); let node = document; for (const part of parts) { if (node.shadowRoot) { node = node.shadowRoot.querySelector(part.trim()); } else { node = node.querySelector(part.trim()); } } return node; } ``` ## Quick Reference | Issue | Primary Fix | Fallback | |-------|-------------|----------| | Scroll not working | Find scrollable container | Mouse wheel at container center | | Click no effect | JavaScript click() | CDP mouse events | | Type clears | `use_insert_text=False` (per-keystroke) | Use a `type` action (Input.insertText) | | Snapshot hangs | Add timeout_s | DOM snapshot fallback | | Stale content | Wait for selector | Increase wait_until timeout | | Shadow DOM | Pierce selector | JavaScript traversal | ## References - [registry.md](registry.md) - Full list of known edge cases - [scripts/test_case.py](scripts/test_case.py) - Template for testing new cases - [BROWSER_USE_PATTERNS.md](../../tools/BROWSER_USE_PATTERNS.md) - Implementation patterns from browser-use.claude/skills/browser-edge-cases/scripts/test_02_twitter_scroll.py3.5 KB4d583c704cfeupstream ↗
#!/usr/bin/env python """ Test #2: Twitter/X Lazy Loading Scroll Symptom: Infinite scroll doesn't load new content Root Cause: Lazy loading requires content to be visible before loading more Fix: Add wait_for_selector between scroll calls """ import asyncio import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).parent.parent.parent.parent / "tools" / "src")) from gcu.browser.bridge import BeelineBridge BRIDGE_PORT = 9229 CONTEXT_NAME = "twitter-scroll-test" async def test_twitter_lazy_scroll(): """Test that repeated scrolls with waits load new content.""" print("=" * 70) print("TEST #2: Twitter/X Lazy Loading Scroll") print("=" * 70) bridge = BeelineBridge() try: await bridge.start() for i in range(10): await asyncio.sleep(1) if bridge.is_connected: print("✓ Extension connected!") break print(f"Waiting for extension... ({i + 1}/10)") else: print("✗ Extension not connected") return context = await bridge.create_context(CONTEXT_NAME) tab_id = context.get("tabId") group_id = context.get("groupId") print(f"✓ Created tab: {tab_id}") # Navigate to Twitter/X print("\n--- Navigating to X.com ---") await bridge.navigate(tab_id, "https://x.com", wait_until="networkidle", timeout_ms=30000) print("✓ Page loaded") # Wait for tweets to appear print("\n--- Waiting for tweets ---") await bridge.wait_for_selector(tab_id, '[data-testid="tweet"]', timeout_ms=10000) # Count initial tweets initial_count = await bridge.evaluate( tab_id, "(function() { return document.querySelectorAll('[data-testid=\"tweet\"]').length; })()", ) print(f"Initial tweet count: {initial_count.get('result', 0)}") # Take screenshot of initial state screenshot = await bridge.screenshot(tab_id) print(f"Screenshot: {len(screenshot.get('data', ''))} bytes") # Scroll multiple times with waits print("\n--- Scrolling with waits ---") for i in range(3): result = await bridge.scroll(tab_id, "down", 500) print(f" Scroll {i + 1}: {result.get('method', 'unknown')} method") # Wait for new content to load await asyncio.sleep(2) # Count tweets after scroll count_result = await bridge.evaluate( tab_id, "(function() { return document.querySelectorAll('[data-testid=\"tweet\"]').length; })()", ) count = count_result.get("result", 0) print(f" Tweet count after scroll: {count}") # Final count final_count = await bridge.evaluate( tab_id, "(function() { return document.querySelectorAll('[data-testid=\"tweet\"]').length; })()", ) final = final_count.get("result", 0) initial = initial_count.get("result", 0) print("\n--- Results ---") print(f"Initial tweets: {initial}") print(f"Final tweets: {final}") if final > initial: print(f"✓ PASS: Loaded {final - initial} new tweets") else: print("✗ FAIL: No new tweets loaded (may need login)") await bridge.destroy_context(group_id) print("\n✓ Context destroyed") finally: await bridge.stop() if __name__ == "__main__": asyncio.run(test_twitter_lazy_scroll()).claude/skills/browser-edge-cases/scripts/test_03_modal_scroll.py3.0 KBa347229042f0upstream ↗
#!/usr/bin/env python """ Test #3: Modal/Dialog Scroll Container Symptom: Scroll scrolls background page, not modal content Root Cause: Modal has its own scroll container with overflow: scroll Fix: Find visible modal container (highest z-index scrollable), scroll that """ import asyncio import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).parent.parent.parent.parent / "tools" / "src")) from gcu.browser.bridge import BeelineBridge BRIDGE_PORT = 9229 CONTEXT_NAME = "modal-scroll-test" # Test site with modal - using a demo site MODAL_DEMO_URL = "https://www.w3schools.com/howto/howto_css_modals.asp" async def test_modal_scroll(): """Test that scroll targets modal content, not background.""" print("=" * 70) print("TEST #3: Modal/Dialog Scroll Container") print("=" * 70) bridge = BeelineBridge() try: await bridge.start() for i in range(10): await asyncio.sleep(1) if bridge.is_connected: print("✓ Extension connected!") break else: print("✗ Extension not connected") return context = await bridge.create_context(CONTEXT_NAME) tab_id = context.get("tabId") group_id = context.get("groupId") print(f"✓ Created tab: {tab_id}") # Navigate to modal demo print("\n--- Navigating to modal demo ---") await bridge.navigate(tab_id, MODAL_DEMO_URL, wait_until="load") print("✓ Page loaded") # Take screenshot before screenshot_before = await bridge.screenshot(tab_id) print(f"Screenshot before: {len(screenshot_before.get('data', ''))} bytes") # Click button to open modal print("\n--- Opening modal ---") # Find and click the "Open Modal" button result = await bridge.click(tab_id, ".ws-btn", timeout_ms=5000) print(f"Click result: {result}") await asyncio.sleep(1) # Take screenshot with modal open screenshot_modal = await bridge.screenshot(tab_id) print(f"Screenshot modal open: {len(screenshot_modal.get('data', ''))} bytes") # Try to scroll within modal print("\n--- Scrolling modal content ---") result = await bridge.scroll(tab_id, "down", 100) print(f"Scroll result: {result}") await asyncio.sleep(0.5) # Take screenshot after scroll screenshot_after = await bridge.screenshot(tab_id) print(f"Screenshot after scroll: {len(screenshot_after.get('data', ''))} bytes") # Check if modal content scrolled (not background) # This is a visual check - we can verify by comparing screenshots print("\n--- Results ---") print(f"Modal scroll test completed. Method used: {result.get('method', 'unknown')}") print("Visual verification needed: Check if modal content scrolled vs background") await bridge.destroy_context(group_id) print("\n✓ Context destroyed") finally: await bridge.stop() if __name__ == "__main__": asyncio.run(test_modal_scroll()).claude/skills/browser-edge-cases/scripts/test_04_element_covered.py4.0 KB3281b2594c50upstream ↗
#!/usr/bin/env python """ Test #4: Element Covered by Overlay Symptom: Click succeeds but no action triggered Root Cause: Element is covered by transparent overlay, tooltip, or iframe Detection: document.elementFromPoint(x, y) !== target Fix: Wait for overlay to disappear, or use JavaScript element.click() """ import asyncio import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).parent.parent.parent.parent / "tools" / "src")) from gcu.browser.bridge import BeelineBridge CONTEXT_NAME = "overlay-click-test" async def test_overlay_click(): """Test clicking elements that are covered by overlays.""" print("=" * 70) print("TEST #4: Element Covered by Overlay") print("=" * 70) bridge = BeelineBridge() try: await bridge.start() for i in range(10): await asyncio.sleep(1) if bridge.is_connected: print("✓ Extension connected!") break else: print("✗ Extension not connected") return context = await bridge.create_context(CONTEXT_NAME) tab_id = context.get("tabId") group_id = context.get("groupId") print(f"✓ Created tab: {tab_id}") # Create a test page with overlay print("\n--- Creating test page with overlay ---") test_html = """ <!DOCTYPE html> <html> <head><title>Overlay Test</title></head> <body> <button id="target-btn" onclick="alert('Clicked!')">Click Me</button> <div id="overlay" style="position:fixed;top:0;left:0; width:100%;height:100%; background:rgba(0,0,0,0.3);z-index:1000;"></div> <script> window.clickCount = 0; document.getElementById('target-btn').addEventListener('click', () => { window.clickCount++; }); </script> </body> </html> """ # Navigate to data URL import base64 data_url = f"data:text/html;base64,{base64.b64encode(test_html.encode()).decode()}" await bridge.navigate(tab_id, data_url, wait_until="load") # Screenshot before screenshot = await bridge.screenshot(tab_id) print(f"Screenshot: {len(screenshot.get('data', ''))} bytes") # Try to click the covered button print("\n--- Attempting to click covered button ---") # First, check if element is covered coverage_check = await bridge.evaluate( tab_id, """ (function() { const btn = document.getElementById('target-btn'); const rect = btn.getBoundingClientRect(); const centerX = rect.left + rect.width / 2; const centerY = rect.top + rect.height / 2; const topElement = document.elementFromPoint(centerX, centerY); return { isCovered: topElement !== btn && !btn.contains(topElement), topElement: topElement?.tagName, targetElement: btn.tagName }; })(); """, ) print(f"Coverage check: {coverage_check.get('result', {})}") # Try CDP click (may fail due to overlay) click_result = await bridge.click(tab_id, "#target-btn", timeout_ms=5000) print(f"Click result: {click_result}") # Check if click registered count_result = await bridge.evaluate(tab_id, "(function() { return window.clickCount; })()") count = count_result.get("result", 0) print(f"Click count after CDP click: {count}") if count > 0: print("✓ PASS: JavaScript click penetrated overlay") else: print("✗ FAIL: Click did not reach button (overlay blocked it)") await bridge.destroy_context(group_id) print("\n✓ Context destroyed") finally: await bridge.stop() if __name__ == "__main__": asyncio.run(test_overlay_click()).claude/skills/browser-edge-cases/scripts/test_06_shadow_dom.py5.0 KB585976f3d4c1upstream ↗
#!/usr/bin/env python """ Test #6: Shadow DOM Elements Symptom: querySelector can't find element Root Cause: Element is inside a shadow root, not main DOM tree Detection: element.shadowRoot !== null on parent elements Fix: Use piercing selector (host >>> target) or traverse shadow roots """ import asyncio import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).parent.parent.parent.parent / "tools" / "src")) from gcu.browser.bridge import BeelineBridge CONTEXT_NAME = "shadow-dom-test" async def test_shadow_dom(): """Test clicking elements inside Shadow DOM.""" print("=" * 70) print("TEST #6: Shadow DOM Elements") print("=" * 70) bridge = BeelineBridge() try: await bridge.start() for i in range(10): await asyncio.sleep(1) if bridge.is_connected: print("✓ Extension connected!") break else: print("✗ Extension not connected") return context = await bridge.create_context(CONTEXT_NAME) tab_id = context.get("tabId") group_id = context.get("groupId") print(f"✓ Created tab: {tab_id}") # Create test page with Shadow DOM print("\n--- Creating test page with Shadow DOM ---") test_html = """ <!DOCTYPE html> <html> <head><title>Shadow DOM Test</title></head> <body> <div id="shadow-host"></div> <script> const host = document.getElementById('shadow-host'); const shadow = host.attachShadow({ mode: 'open' }); shadow.innerHTML = ` <style> button { padding: 10px 20px; font-size: 16px; } </style> <button id="shadow-btn">Shadow Button</button> `; shadow.getElementById('shadow-btn').addEventListener('click', () => { window.shadowClickCount = (window.shadowClickCount || 0) + 1; console.log('Shadow button clicked:', window.shadowClickCount); }); </script> </body> </html> """ # Write to file and use file:// URL (data: URLs don't work well with extension) test_file = Path("/tmp/shadow_dom_test.html") test_file.write_text(test_html.strip()) file_url = f"file://{test_file}" await bridge.navigate(tab_id, file_url, wait_until="load") print("✓ Page loaded") # Screenshot screenshot = await bridge.screenshot(tab_id) print(f"Screenshot: {len(screenshot.get('data', ''))} bytes") # Detect Shadow DOM print("\n--- Detecting Shadow DOM ---") detection = await bridge.evaluate( tab_id, """ (function() { const hosts = []; document.querySelectorAll('*').forEach(el => { if (el.shadowRoot) { hosts.push({ tag: el.tagName, id: el.id, hasButton: el.shadowRoot.querySelector('button') !== null }); } }); return { count: hosts.length, hosts }; })(); """, ) print(f"Shadow DOM detection: {detection.get('result', {})}") # Try to click shadow button using regular selector (should fail) print("\n--- Attempting click with regular selector ---") try: result = await bridge.click(tab_id, "#shadow-btn", timeout_ms=3000) print(f"Result: {result}") except Exception as e: print(f"Expected failure: {e}") # Try to click using JavaScript that pierces shadow DOM print("\n--- Clicking via JavaScript shadow piercing ---") click_result = await bridge.evaluate( tab_id, """ (function() { const host = document.getElementById('shadow-host'); const btn = host.shadowRoot.getElementById('shadow-btn'); if (btn) { btn.click(); return { success: true, clicked: 'shadow-btn' }; } return { success: false, error: 'Button not found' }; })(); """, ) print(f"JS click result: {click_result.get('result', {})}") # Verify click was registered count_result = await bridge.evaluate(tab_id, "(function() { return window.shadowClickCount || 0; })()") count = count_result.get("result") or 0 print(f"Shadow click count: {count}") if count and count > 0: print("✓ PASS: Shadow DOM element clicked successfully") else: print("✗ FAIL: Could not click Shadow DOM element") await bridge.destroy_context(group_id) print("\n✓ Context destroyed") finally: await bridge.stop() if __name__ == "__main__": asyncio.run(test_shadow_dom()).claude/skills/browser-edge-cases/scripts/test_07_contenteditable.py6.4 KB84ffe77540cfupstream ↗
#!/usr/bin/env python """ Test #7: ContentEditable / Rich Text Editors Symptom: browser_interact(action="type") doesn't insert text Root Cause: Element is contenteditable, not an <input> or <textarea> Detection: element.contentEditable === 'true' Fix: Focus via JavaScript, use execCommand('insertText') or Input.dispatchKeyEvent """ import asyncio import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).parent.parent.parent.parent / "tools" / "src")) from gcu.browser.bridge import BeelineBridge CONTEXT_NAME = "contenteditable-test" async def test_contenteditable(): """Test typing into contenteditable elements.""" print("=" * 70) print("TEST #7: ContentEditable / Rich Text Editors") print("=" * 70) bridge = BeelineBridge() try: await bridge.start() for i in range(10): await asyncio.sleep(1) if bridge.is_connected: print("✓ Extension connected!") break else: print("✗ Extension not connected") return context = await bridge.create_context(CONTEXT_NAME) tab_id = context.get("tabId") group_id = context.get("groupId") print(f"✓ Created tab: {tab_id}") # Create test page with contenteditable test_html = """ <!DOCTYPE html> <html> <head><title>ContentEditable Test</title></head> <body> <h2>ContentEditable Test</h2> <h3>1. Simple contenteditable div</h3> <div id="editor1" contenteditable="true" style="border:1px solid #ccc;padding:10px; min-height:50px;">Start text</div> <h3>2. Rich text editor (like Notion)</h3> <div id="editor2" contenteditable="true" style="border:1px solid #ccc;padding:10px; min-height:50px;"> <p>Type here...</p> </div> <h3>3. Regular input (for comparison)</h3> <input id="input1" type="text" placeholder="Regular input" /> <script> // Track content changes window.editor1Content = ''; window.editor2Content = ''; document.getElementById('editor1').addEventListener('input', (e) => { window.editor1Content = e.target.innerText; }); document.getElementById('editor2').addEventListener('input', (e) => { window.editor2Content = e.target.innerText; }); </script> </body> </html> """ # Write to file and use file:// URL (data: URLs don't work well with extension) test_file = Path("/tmp/contenteditable_test.html") test_file.write_text(test_html.strip()) file_url = f"file://{test_file}" await bridge.navigate(tab_id, file_url, wait_until="load") print("✓ Page loaded") # Screenshot with timeout protection try: screenshot = await asyncio.wait_for(bridge.screenshot(tab_id), timeout=10.0) print(f"Screenshot: {len(screenshot.get('data', ''))} bytes") except asyncio.TimeoutError: print("Screenshot timed out (skipping)") # Detect contenteditable print("\n--- Detecting contenteditable elements ---") detection = await bridge.evaluate( tab_id, """ (function() { const editables = document.querySelectorAll('[contenteditable="true"]'); return { count: editables.length, ids: Array.from(editables).map(el => el.id) }; })(); """, ) print(f"Contenteditable detection: {detection.get('result', {})}") # Test 1: Type into regular input (baseline) print("\n--- Test 1: Regular input ---") await bridge.click(tab_id, "#input1") await bridge.type_text(tab_id, "#input1", "Hello input") input_result = await bridge.evaluate(tab_id, "(function() { return document.getElementById('input1').value; })()") print(f"Input value: {input_result.get('result', '')}") # Test 2: Type into contenteditable div print("\n--- Test 2: Contenteditable div ---") await bridge.click(tab_id, "#editor1") await bridge.type_text(tab_id, "#editor1", "Hello contenteditable", clear_first=True) editor_result = await bridge.evaluate( tab_id, "(function() { return document.getElementById('editor1').innerText; })()", ) print(f"Editor1 innerText: {editor_result.get('result', '')}") # Test 3: Use JavaScript insertText for rich editor print("\n--- Test 3: JavaScript insertText for rich editor ---") insert_result = await bridge.evaluate( tab_id, """ (function() { const editor = document.getElementById('editor2'); editor.focus(); document.execCommand('selectAll', false, null); document.execCommand('insertText', false, 'Hello from execCommand'); return editor.innerText; })(); """, ) print(f"Editor2 after execCommand: {insert_result.get('result', '')}") # Screenshot after with timeout protection try: screenshot_after = await asyncio.wait_for(bridge.screenshot(tab_id), timeout=10.0) print(f"Screenshot after: {len(screenshot_after.get('data', ''))} bytes") except asyncio.TimeoutError: print("Screenshot after timed out (skipping)") # Results print("\n--- Results ---") input_val = input_result.get("result", "") editor1_val = editor_result.get("result", "") editor2_val = insert_result.get("result", "") input_pass = "Hello input" in input_val editor1_pass = "Hello contenteditable" in editor1_val editor2_pass = "execCommand" in editor2_val print(f"Input: {'✓ PASS' if input_pass else '✗ FAIL'} - {input_val}") print(f"Editor1: {'✓ PASS' if editor1_pass else '✗ FAIL'} - {editor1_val}") print(f"Editor2: {'✓ PASS' if editor2_pass else '✗ FAIL'} - {editor2_val}") await bridge.destroy_context(group_id) print("\n✓ Context destroyed") finally: await bridge.stop() if __name__ == "__main__": asyncio.run(test_contenteditable()).claude/skills/browser-edge-cases/scripts/test_08_autocomplete.py9.1 KB066f6443c6e7upstream ↗
#!/usr/bin/env python """ Test #8: Autocomplete Field Clearing Symptom: Typed text gets cleared immediately Root Cause: Field expects realistic keystroke timing for autocomplete Detection: Field has autocomplete listeners or dropdown appears Fix: Add delay_ms between keystrokes """ import asyncio import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).parent.parent.parent.parent / "tools" / "src")) from gcu.browser.bridge import BeelineBridge CONTEXT_NAME = "autocomplete-test" async def test_autocomplete(): """Test typing into fields with autocomplete behavior.""" print("=" * 70) print("TEST #8: Autocomplete Field Clearing") print("=" * 70) bridge = BeelineBridge() try: await bridge.start() for i in range(10): await asyncio.sleep(1) if bridge.is_connected: print("✓ Extension connected!") break else: print("✗ Extension not connected") return context = await bridge.create_context(CONTEXT_NAME) tab_id = context.get("tabId") group_id = context.get("groupId") print(f"✓ Created tab: {tab_id}") # Create test page with autocomplete behavior test_html = """ <!DOCTYPE html> <html> <head><title>Autocomplete Test</title> <style> .autocomplete-items { position: absolute; border: 1px solid #d4d4d4; border-top: none; z-index: 99; top: 100%; left: 0; right: 0; max-height: 200px; overflow-y: auto; background: white; } .autocomplete-items div { padding: 10px; cursor: pointer; } .autocomplete-items div:hover { background-color: #e9e9e9; } .autocomplete-active { background-color: DodgerBlue !important; color: white; } .autocomplete { position: relative; display: inline-block; } input { width: 300px; padding: 10px; font-size: 16px; } </style></head> <body> <h2>Autocomplete Test</h2> <div class="autocomplete"> <input id="search" type="text" placeholder="Search countries..." autocomplete="off"> </div> <div id="log" style="margin-top:20px;font-family:monospace;"></div> <script> const countries = [ "Afghanistan","Albania","Algeria", "Andorra","Angola","Argentina", "Armenia","Australia","Austria", "Azerbaijan","Bahamas","Bahrain", "Bangladesh","Belarus","Belgium", "Belize","Benin","Bhutan", "Bolivia","Brazil","Canada", "China","Colombia","Denmark", "Egypt","France","Germany", "India","Indonesia","Italy", "Japan","Mexico","Netherlands", "Nigeria","Norway","Pakistan", "Peru","Philippines","Poland", "Portugal","Russia","Spain", "Sweden","Switzerland","Thailand", "Turkey","Ukraine", "United Kingdom","United States", "Vietnam" ]; const input = document.getElementById('search'); const log = document.getElementById('log'); let currentFocus = -1; let typingTimeout = null; // Track events for testing window.inputEvents = []; window.inputValue = ''; function logEvent(type, value) { window.inputEvents.push({ type, value, time: Date.now() }); const entry = document.createElement('div'); entry.textContent = type + ': ' + value; log.insertBefore(entry, log.firstChild); } // Simulate autocomplete that clears fast typing input.addEventListener('input', function(e) { const val = this.value; // Clear previous dropdown closeAllLists(); if (!val) return; // If typing too fast (autocomplete-style), clear and restart clearTimeout(typingTimeout); typingTimeout = setTimeout(() => { logEvent('input', val); window.inputValue = val; // Create dropdown const div = document.createElement('div'); div.setAttribute('id', this.id + 'autocomplete-list'); div.setAttribute('class', 'autocomplete-items'); this.parentNode.appendChild(div); countries.filter( c => c.substr(0, val.length).toUpperCase() === val.toUpperCase() ).slice(0, 5).forEach(country => { const item = document.createElement('div'); item.innerHTML = '<strong>' + country.substr(0, val.length) + '</strong>' + country.substr(val.length); item.addEventListener('click', function() { input.value = country; closeAllLists(); logEvent('select', country); window.inputValue = country; }); div.appendChild(item); }); }, 100); // 100ms debounce }); function closeAllLists() { document.querySelectorAll('.autocomplete-items').forEach(el => el.remove()); } document.addEventListener('click', function() { closeAllLists(); }); </script> </body> </html> """ # Write to file and use file:// URL (data: URLs don't work well with extension) test_file = Path("/tmp/autocomplete_test.html") test_file.write_text(test_html.strip()) file_url = f"file://{test_file}" await bridge.navigate(tab_id, file_url, wait_until="load") print("✓ Page loaded") # Screenshot screenshot = await bridge.screenshot(tab_id) print(f"Screenshot: {len(screenshot.get('data', ''))} bytes") # Test 1: Fast typing (no delay) - may fail print("\n--- Test 1: Fast typing (delay_ms=0) ---") await bridge.click(tab_id, "#search") await bridge.type_text(tab_id, "#search", "Ger", clear_first=True, delay_ms=0) await asyncio.sleep(0.5) fast_result = await bridge.evaluate(tab_id, "(function() { return document.getElementById('search').value; })()") fast_value = fast_result.get("result", "") print(f"Value after fast typing: '{fast_value}'") # Check events events_result = await bridge.evaluate(tab_id, "(function() { return window.inputEvents; })()") print(f"Events logged: {events_result.get('result', [])}") # Test 2: Slow typing (with delay) - should work print("\n--- Test 2: Slow typing (delay_ms=100) ---") await bridge.click(tab_id, "#search") await bridge.type_text(tab_id, "#search", "United", clear_first=True, delay_ms=100) await asyncio.sleep(0.5) slow_result = await bridge.evaluate(tab_id, "(function() { return document.getElementById('search').value; })()") slow_value = slow_result.get("result", "") print(f"Value after slow typing: '{slow_value}'") # Check if dropdown appeared dropdown_result = await bridge.evaluate( tab_id, "(function() { return document.querySelectorAll('.autocomplete-items div').length; })()", ) dropdown_count = dropdown_result.get("result", 0) print(f"Dropdown items: {dropdown_count}") # Screenshot with dropdown screenshot_dropdown = await bridge.screenshot(tab_id) print(f"Screenshot with dropdown: {len(screenshot_dropdown.get('data', ''))} bytes") # Results print("\n--- Results ---") if "United" in slow_value: print("✓ PASS: Slow typing with delay_ms worked") else: print("✗ FAIL: Slow typing still didn't work") if dropdown_count > 0: print("✓ PASS: Autocomplete dropdown appeared") else: print("⚠ WARNING: No autocomplete dropdown") await bridge.destroy_context(group_id) print("\n✓ Context destroyed") finally: await bridge.stop() if __name__ == "__main__": asyncio.run(test_autocomplete()).claude/skills/browser-edge-cases/scripts/test_10_huge_dom.py5.4 KBe9955d655037upstream ↗
#!/usr/bin/env python """ Test #10: LinkedIn Huge DOM Tree Symptom: browser_snapshot() hangs forever Root Cause: 10k+ DOM nodes, accessibility tree has 50k+ nodes Detection: document.querySelectorAll('*').length > 5000 Fix: Add timeout (10s default), truncate tree at 2000 nodes """ import asyncio import sys import time import base64 from pathlib import Path sys.path.insert(0, str(Path(__file__).parent.parent.parent.parent / "tools" / "src")) from gcu.browser.bridge import BeelineBridge CONTEXT_NAME = "huge-dom-test" async def test_huge_dom(): """Test snapshot performance on huge DOM trees.""" print("=" * 70) print("TEST #10: Huge DOM Tree (LinkedIn-style)") print("=" * 70) bridge = BeelineBridge() try: await bridge.start() for i in range(10): await asyncio.sleep(1) if bridge.is_connected: print("✓ Extension connected!") break else: print("✗ Extension not connected") return context = await bridge.create_context(CONTEXT_NAME) tab_id = context.get("tabId") group_id = context.get("groupId") print(f"✓ Created tab: {tab_id}") # Test 1: Small DOM (baseline) print("\n--- Test 1: Small DOM (baseline) ---") small_html = """ <!DOCTYPE html> <html><body> <h1>Small Page</h1> <p>A few elements</p> <button>Click me</button> </body></html> """ data_url = f"data:text/html;base64,{base64.b64encode(small_html.encode()).decode()}" await bridge.navigate(tab_id, data_url, wait_until="load") start = time.perf_counter() snapshot = await bridge.snapshot(tab_id, timeout_s=5.0) elapsed = time.perf_counter() - start tree_len = len(snapshot.get("tree", "")) print(f"Small DOM snapshot: {elapsed:.3f}s, {tree_len} chars") # Test 2: Generate huge DOM print("\n--- Test 2: Huge DOM (5000+ elements) ---") huge_html = """ <!DOCTYPE html> <html><body> <h1>Huge DOM Test</h1> <div id="container"></div> <script> const container = document.getElementById('container'); for (let i = 0; i < 5000; i++) { const div = document.createElement('div'); div.className = 'item-' + i; div.innerHTML = '<span>Item ' + i + '</span><button>Action</button>'; container.appendChild(div); } </script> </body></html> """ data_url = f"data:text/html;base64,{base64.b64encode(huge_html.encode()).decode()}" await bridge.navigate(tab_id, data_url, wait_until="load") # Count elements count_result = await bridge.evaluate(tab_id, "(function() { return document.querySelectorAll('*').length; })()") elem_count = count_result.get("result", 0) print(f"DOM elements: {elem_count}") # Skip screenshot on huge DOM - it can timeout # Instead verify page loaded by checking DOM print("✓ Page verified (skipping screenshot on huge DOM)") # Test snapshot with timeout print("\n--- Testing snapshot with 10s timeout ---") start = time.perf_counter() try: snapshot = await bridge.snapshot(tab_id, timeout_s=10.0) elapsed = time.perf_counter() - start tree_len = len(snapshot.get("tree", "")) truncated = "(truncated)" in snapshot.get("tree", "") print(f"✓ Huge DOM snapshot: {elapsed:.3f}s, {tree_len} chars, truncated={truncated}") if elapsed < 5.0: print("✓ PASS: Snapshot completed quickly") else: print(f"⚠ WARNING: Snapshot took {elapsed:.1f}s") if truncated: print("✓ PASS: Tree was truncated to prevent hang") else: print("⚠ WARNING: Tree not truncated (may need adjustment)") except asyncio.TimeoutError: print("✗ FAIL: Snapshot timed out (this shouldn't happen)") # Test 3: Real LinkedIn print("\n--- Test 3: Real LinkedIn Feed ---") await bridge.navigate(tab_id, "https://www.linkedin.com/feed", wait_until="load", timeout_ms=30000) await asyncio.sleep(2) count_result = await bridge.evaluate(tab_id, "(function() { return document.querySelectorAll('*').length; })()") elem_count = count_result.get("result", 0) print(f"LinkedIn DOM elements: {elem_count}") start = time.perf_counter() try: snapshot = await bridge.snapshot(tab_id, timeout_s=15.0) elapsed = time.perf_counter() - start tree_len = len(snapshot.get("tree", "")) truncated = "(truncated)" in snapshot.get("tree", "") print(f"LinkedIn snapshot: {elapsed:.3f}s, {tree_len} chars, truncated={truncated}") if elapsed < 5.0: print("✓ PASS: LinkedIn snapshot fast enough") elif elapsed < 15.0: print("⚠ WARNING: LinkedIn snapshot slow but within timeout") else: print("✗ FAIL: LinkedIn snapshot too slow") except asyncio.TimeoutError: print("✗ FAIL: LinkedIn snapshot timed out") await bridge.destroy_context(group_id) print("\n✓ Context destroyed") finally: await bridge.stop() if __name__ == "__main__": asyncio.run(test_huge_dom()).claude/skills/browser-edge-cases/scripts/test_13_spa_navigation.py6.5 KB743f19f6589eupstream ↗
#!/usr/bin/env python """ Test #13: SPA Navigation Events Symptom: wait_until="load" fires before content ready Root Cause: SPA uses client-side routing, no full page load Detection: URL changes but load event already fired Fix: Use wait_until="networkidle" or wait_for_selector """ import asyncio import sys import time from pathlib import Path sys.path.insert(0, str(Path(__file__).parent.parent.parent.parent / "tools" / "src")) from gcu.browser.bridge import BeelineBridge CONTEXT_NAME = "spa-nav-test" async def test_spa_navigation(): """Test navigation timing on SPA pages.""" print("=" * 70) print("TEST #13: SPA Navigation Events") print("=" * 70) bridge = BeelineBridge() try: await bridge.start() for i in range(10): await asyncio.sleep(1) if bridge.is_connected: print("✓ Extension connected!") break else: print("✗ Extension not connected") return context = await bridge.create_context(CONTEXT_NAME) tab_id = context.get("tabId") group_id = context.get("groupId") print(f"✓ Created tab: {tab_id}") # Create a test SPA spa_html = """ <!DOCTYPE html> <html> <head> <title>SPA Test</title> <style> nav a { margin-right: 10px; } .page { padding: 20px; border: 1px solid #ccc; margin-top: 10px; } </style> </head> <body> <nav> <a href="#home" onclick="navigate('home')">Home</a> <a href="#about" onclick="navigate('about')">About</a> <a href="#contact" onclick="navigate('contact')">Contact</a> </nav> <div id="app" class="page"> <h1>Loading...</h1> </div> <script> // Simulate SPA routing let currentPage = ''; async function navigate(page) { event.preventDefault(); currentPage = page; // Show loading state document.getElementById('app').innerHTML = '<h1>Loading...</h1>'; // Simulate async content loading (like real SPAs) await new Promise(r => setTimeout(r, 500)); // Render content const content = { home: '<h1>Home Page</h1><p>Welcome!</p>' + '<button id="home-btn">Home Action</button>', about: '<h1>About Page</h1><p>Simulated SPA.</p>' + '<button id="about-btn">About Action</button>', contact: '<h1>Contact Page</h1>' + '<p>Contact us at [email protected]</p>' + '<button id="contact-btn">Contact Action</button>' }; document.getElementById('app').innerHTML = content[page] || '<h1>404</h1>'; window.location.hash = page; } // Initial load with delay (simulates SPA hydration) setTimeout(() => { navigate('home'); }, 1000); // Track for testing window.pageLoads = []; window.addEventListener('hashchange', () => { window.pageLoads.push(window.location.hash); }); </script> </body> </html> """ # Write to file and use file:// URL (data: URLs don't work well with extension) test_file = Path("/tmp/spa_test.html") test_file.write_text(spa_html.strip()) file_url = f"file://{test_file}" # Test 1: wait_until="load" - may fire before content ready print("\n--- Test 1: wait_until='load' ---") start = time.perf_counter() await bridge.navigate(tab_id, file_url, wait_until="load") elapsed = time.perf_counter() - start print(f"Navigation completed in {elapsed:.3f}s") # Check content immediately content = await bridge.evaluate( tab_id, "(function() { return document.getElementById('app').innerText; })()", ) print(f"Content immediately after load: '{content.get('result', '')}'") # Screenshot screenshot = await bridge.screenshot(tab_id) print(f"Screenshot: {len(screenshot.get('data', ''))} bytes") # Wait for content print("\n--- Waiting for content to hydrate ---") await bridge.wait_for_selector(tab_id, "#home-btn", timeout_ms=5000) print("✓ Content loaded") # Check content after wait content_after = await bridge.evaluate( tab_id, "(function() { return document.getElementById('app').innerText; })()", ) print(f"Content after wait: '{content_after.get('result', '')}'") # Test 2: SPA navigation (no full page load) print("\n--- Test 2: SPA client-side navigation ---") # Click "About" link await bridge.click(tab_id, 'a[href="#about"]') await asyncio.sleep(1) # Check if content changed about_content = await bridge.evaluate( tab_id, "(function() { return document.getElementById('app').innerText; })()", ) print(f"Content after SPA nav: '{about_content.get('result', '')}'") if "About Page" in about_content.get("result", ""): print("✓ PASS: SPA navigation worked") else: print("✗ FAIL: SPA navigation didn't update content") # Test 3: wait_until="networkidle" print("\n--- Test 3: wait_until='networkidle' ---") await bridge.navigate(tab_id, file_url, wait_until="networkidle", timeout_ms=10000) # Check content immediately content_networkidle = await bridge.evaluate( tab_id, "(function() { return document.getElementById('app').innerText; })()", ) print(f"Content after networkidle: '{content_networkidle.get('result', '')}'") if "Home Page" in content_networkidle.get("result", ""): print("✓ PASS: networkidle waited for content") else: print("⚠ WARNING: networkidle didn't wait long enough") await bridge.destroy_context(group_id) print("\n✓ Context destroyed") finally: await bridge.stop() if __name__ == "__main__": asyncio.run(test_spa_navigation()).claude/skills/browser-edge-cases/scripts/test_15_screenshot.py8.6 KB69f6fb80e31aupstream ↗
#!/usr/bin/env python """ Test #15: Screenshot Functionality Tests browser_screenshot across multiple scenarios: - Basic viewport screenshot - Full-page screenshot - Selector-based screenshot - Screenshot on complex DOM - Timeout handling Category: screenshot """ import asyncio import base64 import sys import time from pathlib import Path sys.path.insert(0, str(Path(__file__).parent.parent.parent.parent / "tools" / "src")) from gcu.browser.bridge import BeelineBridge CONTEXT_NAME = "screenshot-test" SIMPLE_HTML = """<!DOCTYPE html> <html> <head><style> body { margin: 0; background: #fff; font-family: sans-serif; } h1 { color: #333; padding: 20px; } .box { width: 200px; height: 100px; background: #4a90e2; margin: 20px; } .long-content { height: 2000px; background: linear-gradient(blue, red); } </style></head> <body> <h1 id="title">Screenshot Test Page</h1> <div class="box" id="target-box">Target Box</div> <div class="long-content"></div> </body> </html>""" def check_png(data: str) -> bool: """Verify that base64 data decodes to a valid PNG.""" try: raw = base64.b64decode(data) return raw[:8] == b"\x89PNG\r\n\x1a\n" except Exception: return False async def test_basic_screenshot(bridge: BeelineBridge, tab_id: int, data_url: str): print("\n--- Test 1: Basic Viewport Screenshot ---") await bridge.navigate(tab_id, data_url, wait_until="load") await asyncio.sleep(0.5) start = time.perf_counter() result = await bridge.screenshot(tab_id) elapsed = time.perf_counter() - start ok = result.get("ok") data = result.get("data", "") mime = result.get("mimeType", "") print(f" ok={ok}, mimeType={mime}, elapsed={elapsed:.3f}s") print(f" data length: {len(data)} chars") if ok and data: valid_png = check_png(data) print(f" valid PNG: {valid_png}") if valid_png: raw = base64.b64decode(data) print(f" PNG size: {len(raw)} bytes") print(" ✓ PASS: Basic screenshot works") return True else: print(" ✗ FAIL: Data is not a valid PNG") else: print(f" ✗ FAIL: {result.get('error', 'no data')}") return False async def test_full_page_screenshot(bridge: BeelineBridge, tab_id: int, data_url: str): print("\n--- Test 2: Full Page Screenshot ---") await bridge.navigate(tab_id, data_url, wait_until="load") await asyncio.sleep(0.5) viewport_result = await bridge.screenshot(tab_id, full_page=False) full_result = await bridge.screenshot(tab_id, full_page=True) v_data = viewport_result.get("data", "") f_data = full_result.get("data", "") if not v_data or not f_data: print(f" ✗ FAIL: viewport ok={viewport_result.get('ok')}, full ok={full_result.get('ok')}") return False v_size = len(base64.b64decode(v_data)) f_size = len(base64.b64decode(f_data)) print(f" Viewport PNG: {v_size} bytes") print(f" Full page PNG: {f_size} bytes") if f_size > v_size: print(" ✓ PASS: Full page larger than viewport") return True else: print(" ✗ FAIL: Full page not larger than viewport (may not capture long pages)") return False async def test_selector_screenshot(bridge: BeelineBridge, tab_id: int, data_url: str): print("\n--- Test 3: Selector Screenshot ---") await bridge.navigate(tab_id, data_url, wait_until="load") await asyncio.sleep(0.5) # selector param exists in signature but may not be implemented result = await bridge.screenshot(tab_id, selector="#target-box") ok = result.get("ok") data = result.get("data", "") if ok and data: # If implemented, the box screenshot should be smaller than a full viewport screenshot full_result = await bridge.screenshot(tab_id) full_data = full_result.get("data", "") if full_data: sel_size = len(base64.b64decode(data)) full_size = len(base64.b64decode(full_data)) print(f" Selector PNG: {sel_size} bytes") print(f" Full page PNG: {full_size} bytes") if sel_size < full_size: print(" ✓ PASS: Selector screenshot smaller than full page") return True else: print(" ⚠ WARNING: Selector screenshot not smaller (may be full page)") return False else: print(f" ⚠ NOT IMPLEMENTED: selector param ignored (returns full page) - error={result.get('error')}") print(" NOTE: selector parameter exists in signature but is not used in implementation") return False async def test_screenshot_url_metadata(bridge: BeelineBridge, tab_id: int): print("\n--- Test 4: Screenshot URL Metadata ---") await bridge.navigate(tab_id, "https://example.com", wait_until="load") await asyncio.sleep(1) result = await bridge.screenshot(tab_id) url = result.get("url", "") tab = result.get("tabId") print(f" url={url!r}, tabId={tab}") if "example.com" in url: print(" ✓ PASS: URL metadata captured correctly") return True else: print(f" ✗ FAIL: Expected example.com in URL, got {url!r}") return False async def test_screenshot_timeout(bridge: BeelineBridge, tab_id: int, data_url: str): print("\n--- Test 5: Timeout Handling ---") await bridge.navigate(tab_id, data_url, wait_until="load") # Very short timeout - likely still completes since simple page start = time.perf_counter() result = await bridge.screenshot(tab_id, timeout_s=0.001) elapsed = time.perf_counter() - start if not result.get("ok"): err = result.get("error", "") if "timed out" in err or "cancelled" in err: print(f" ✓ PASS: Timeout handled gracefully: {err!r}") return True else: print(f" ⚠ Fast enough to beat timeout: {err!r} in {elapsed:.3f}s") return True # Not a failure, just fast else: print(f" ⚠ Screenshot completed before timeout ({elapsed:.3f}s) - too fast to test timeout") return True # Still ok, just very fast async def test_screenshot_complex_site(bridge: BeelineBridge, tab_id: int): print("\n--- Test 6: Complex Site (example.com) ---") await bridge.navigate(tab_id, "https://example.com", wait_until="load") await asyncio.sleep(1) start = time.perf_counter() result = await bridge.screenshot(tab_id) elapsed = time.perf_counter() - start ok = result.get("ok") data = result.get("data", "") print(f" ok={ok}, elapsed={elapsed:.3f}s, data_len={len(data)}") if ok and check_png(data): print(" ✓ PASS: Screenshot on real site works") return True else: print(f" ✗ FAIL: {result.get('error', 'bad data')}") return False async def main(): print("=" * 70) print("TEST #15: Screenshot Functionality") print("=" * 70) bridge = BeelineBridge() try: await bridge.start() for i in range(10): await asyncio.sleep(1) if bridge.is_connected: print("✓ Extension connected!") break print(f"Waiting for extension... ({i + 1}/10)") else: print("✗ Extension not connected. Ensure Chrome with Beeline extension is running.") return context = await bridge.create_context(CONTEXT_NAME) tab_id = context.get("tabId") group_id = context.get("groupId") print(f"✓ Created tab: {tab_id}") data_url = f"data:text/html;base64,{base64.b64encode(SIMPLE_HTML.encode()).decode()}" results = { "basic": await test_basic_screenshot(bridge, tab_id, data_url), "full_page": await test_full_page_screenshot(bridge, tab_id, data_url), "selector": await test_selector_screenshot(bridge, tab_id, data_url), "metadata": await test_screenshot_url_metadata(bridge, tab_id), "timeout": await test_screenshot_timeout(bridge, tab_id, data_url), "complex_site": await test_screenshot_complex_site(bridge, tab_id), } print("\n" + "=" * 70) print("SUMMARY") print("=" * 70) for name, passed in results.items(): status = "✓ PASS" if passed else "✗ FAIL" print(f" {status}: {name}") passed_count = sum(1 for v in results.values() if v) total = len(results) print(f"\n {passed_count}/{total} tests passed") await bridge.destroy_context(group_id) print("\n✓ Context destroyed") finally: await bridge.stop() print("✓ Bridge stopped") if __name__ == "__main__": asyncio.run(main()).claude/skills/browser-edge-cases/scripts/test_case.py12 KB43a3dfa29d07upstream ↗
#!/usr/bin/env python """ Browser Edge Case Test Template This script provides a template for testing and debugging browser tool failures on specific websites. Use this to reproduce, isolate, and verify fixes. Usage: 1. Copy this file: cp test_case.py test_#[number]_[site].py 2. Fill in the CONFIG section with your test details 3. Run: uv run python test_#[number]_[site].py Example: uv run python test_01_linkedin_scroll.py """ import asyncio import sys import time from pathlib import Path # Add tools to path sys.path.insert(0, str(Path(__file__).parent.parent.parent.parent / "tools" / "src")) from gcu.browser.bridge import BeelineBridge # ═══════════════════════════════════════════════════════════════════════════════ # CONFIG: Fill in these values for your test case # ═══════════════════════════════════════════════════════════════════════════════ TEST_CASE = { "number": 1, "name": "LinkedIn Nested Scroll Container", "site": "https://www.linkedin.com/feed", "simple_site": "https://example.com", "category": "scroll", # scroll, click, input, snapshot, navigation "symptom": "scroll() returns success but page doesn't move", } BRIDGE_PORT = 9229 CONTEXT_NAME = "edge-case-test" # ═══════════════════════════════════════════════════════════════════════════════ # TEST FUNCTIONS # ═══════════════════════════════════════════════════════════════════════════════ async def test_simple_site(bridge: BeelineBridge, tab_id: int) -> dict: """Test that the tool works on a simple site (baseline).""" print("\n--- Baseline Test (Simple Site) ---") await bridge.navigate(tab_id, TEST_CASE["simple_site"], wait_until="load") await asyncio.sleep(1) # Adjust this based on category if TEST_CASE["category"] == "scroll": result = await bridge.scroll(tab_id, "down", 100) print(f" Scroll result: {result}") return result elif TEST_CASE["category"] == "click": # Add click test pass elif TEST_CASE["category"] == "snapshot": result = await bridge.snapshot(tab_id, timeout_s=5.0) print(f" Snapshot length: {len(result.get('tree', ''))}") return result return {"ok": True} async def test_problematic_site(bridge: BeelineBridge, tab_id: int) -> dict: """Test the tool on the problematic site.""" print("\n--- Problem Site Test ---") await bridge.navigate(tab_id, TEST_CASE["site"], wait_until="load", timeout_ms=30000) await asyncio.sleep(2) # Adjust this based on category if TEST_CASE["category"] == "scroll": # Get scroll positions before before = await bridge.evaluate( tab_id, """ (function() { const results = { window: { y: window.scrollY } }; document.querySelectorAll('*').forEach((el, i) => { const style = getComputedStyle(el); if ((style.overflowY === 'scroll' || style.overflowY === 'auto') && el.scrollHeight > el.clientHeight) { results['el_' + i] = { tag: el.tagName, scrollTop: el.scrollTop, class: el.className.substring(0, 30) }; } }); return results; })(); """, ) print(f" Before scroll: {before.get('result', {})}") # Try to scroll result = await bridge.scroll(tab_id, "down", 500) print(f" Scroll result: {result}") await asyncio.sleep(1) # Get scroll positions after after = await bridge.evaluate( tab_id, """ (function() { const results = { window: { y: window.scrollY } }; document.querySelectorAll('*').forEach((el, i) => { const style = getComputedStyle(el); if ((style.overflowY === 'scroll' || style.overflowY === 'auto') && el.scrollHeight > el.clientHeight) { results['el_' + i] = { tag: el.tagName, scrollTop: el.scrollTop, class: el.className.substring(0, 30) }; } }); return results; })(); """, ) print(f" After scroll: {after.get('result', {})}") # Check if anything changed before_data = before.get("result", {}) or {} after_data = after.get("result", {}) or {} changed = False for key in after_data: if key in before_data: b_val = before_data[key].get("scrollTop", 0) if isinstance(before_data[key], dict) else 0 a_val = after_data[key].get("scrollTop", 0) if isinstance(after_data[key], dict) else 0 if a_val != b_val: print(f" ✓ CHANGE DETECTED: {key} scrolled from {b_val} to {a_val}") changed = True if not changed: print(" ✗ NO CHANGE: Scroll did not affect any container") return {"ok": changed, "scroll_result": result} elif TEST_CASE["category"] == "snapshot": start = time.perf_counter() try: result = await bridge.snapshot(tab_id, timeout_s=15.0) elapsed = time.perf_counter() - start tree_len = len(result.get("tree", "")) print(f" Snapshot completed in {elapsed:.2f}s, {tree_len} chars") return {"ok": True, "elapsed": elapsed, "tree_length": tree_len} except asyncio.TimeoutError: print(" ✗ SNAPSHOT TIMED OUT") return {"ok": False, "error": "timeout"} return {"ok": True} async def detect_root_cause(bridge: BeelineBridge, tab_id: int) -> dict: """Run detection scripts to identify the root cause.""" print("\n--- Root Cause Detection ---") detections = {} # Detection 1: Nested scrollable containers scroll_check = await bridge.evaluate( tab_id, """ (function() { const candidates = []; document.querySelectorAll('*').forEach(el => { const style = getComputedStyle(el); if (style.overflow.includes('scroll') || style.overflow.includes('auto')) { const rect = el.getBoundingClientRect(); if (rect.width > 100 && rect.height > 100) { candidates.push({ tag: el.tagName, area: rect.width * rect.height, class: el.className.substring(0, 30) }); } } }); candidates.sort((a, b) => b.area - a.area); return { count: candidates.length, largest: candidates[0] }; })(); """, ) detections["nested_scroll"] = scroll_check.get("result", {}) print(f" Nested scroll containers: {detections['nested_scroll']}") # Detection 2: Shadow DOM shadow_check = await bridge.evaluate( tab_id, """ (function() { const withShadow = []; document.querySelectorAll('*').forEach(el => { if (el.shadowRoot) { withShadow.push(el.tagName); } }); return { count: withShadow.length, elements: withShadow.slice(0, 5) }; })(); """, ) detections["shadow_dom"] = shadow_check.get("result", {}) print(f" Shadow DOM: {detections['shadow_dom']}") # Detection 3: iframes iframe_check = await bridge.evaluate( tab_id, """ (function() { const iframes = document.querySelectorAll('iframe'); return { count: iframes.length }; })(); """, ) detections["iframes"] = iframe_check.get("result", {}) print(f" iframes: {detections['iframes']}") # Detection 4: DOM size dom_check = await bridge.evaluate( tab_id, """ (function() { return { elements: document.querySelectorAll('*').length, body_children: document.body.children.length }; })(); """, ) detections["dom_size"] = dom_check.get("result", {}) print(f" DOM size: {detections['dom_size']}") # Detection 5: Framework detection framework_check = await bridge.evaluate( tab_id, """ (function() { return { react: !!document.querySelector('[data-reactroot], [data-reactid]'), vue: !!document.querySelector('[data-v-]'), angular: !!document.querySelector('[ng-app], [ng-version]') }; })(); """, ) detections["frameworks"] = framework_check.get("result", {}) print(f" Frameworks: {detections['frameworks']}") return detections # ═══════════════════════════════════════════════════════════════════════════════ # MAIN # ═══════════════════════════════════════════════════════════════════════════════ async def main(): print("=" * 70) print(f"EDGE CASE TEST #{TEST_CASE['number']}: {TEST_CASE['name']}") print("=" * 70) print(f"Site: {TEST_CASE['site']}") print(f"Category: {TEST_CASE['category']}") print(f"Symptom: {TEST_CASE['symptom']}") bridge = BeelineBridge() try: print("\n--- Starting Bridge ---") await bridge.start() # Wait for extension connection for i in range(10): await asyncio.sleep(1) if bridge.is_connected: print("✓ Extension connected!") break print(f"Waiting for extension... ({i + 1}/10)") else: print("✗ Extension not connected. Ensure Chrome with Beeline extension is running.") return # Create browser context context = await bridge.create_context(CONTEXT_NAME) tab_id = context.get("tabId") group_id = context.get("groupId") print(f"✓ Created tab: {tab_id}") # Run tests baseline_result = await test_simple_site(bridge, tab_id) problem_result = await test_problematic_site(bridge, tab_id) detections = await detect_root_cause(bridge, tab_id) # Summary print("\n" + "=" * 70) print("SUMMARY") print("=" * 70) print(f"Baseline test: {'✓ PASS' if baseline_result.get('ok') else '✗ FAIL'}") print(f"Problem test: {'✓ PASS' if problem_result.get('ok') else '✗ FAIL'}") print(f"Root cause indicators: {list(k for k, v in detections.items() if v)}") # Cleanup print("\n--- Cleanup ---") await bridge.destroy_context(group_id) print("✓ Context destroyed") finally: await bridge.stop() print("✓ Bridge stopped") if __name__ == "__main__": asyncio.run(main()).claude/skills/browser-edge-cases/registry.md10 KBfd64a5e6b17eupstream ↗
# Browser Edge Case Registry Curated list of known browser automation edge cases with symptoms, causes, and fixes. --- ## Scroll Issues ### #1: LinkedIn Nested Scroll Container | Attribute | Value | |-----------|-------| | **Site** | LinkedIn (linkedin.com/feed) | | **Symptom** | `browser_interact(action="scroll")` returns `{ok: true}` but page doesn't move | | **Root Cause** | Content is in a nested scrollable div (`overflow: scroll`), not the main window | | **Detection** | `document.querySelectorAll('*')` with `overflow: scroll/auto` has large candidates | | **Fix** | JavaScript finds largest scrollable container, uses `container.scrollBy()` | | **Code** | `bridge.py:808-891` - smart scroll with container detection | | **Verified** | 2026-04-03 ✓ | ### #2: Twitter/X Lazy Loading | Attribute | Value | |-----------|-------| | **Site** | Twitter/X (x.com) | | **Symptom** | Infinite scroll doesn't load new content | | **Root Cause** | Lazy loading requires content to be visible before loading more | | **Detection** | Scroll position at bottom but no new `[data-testid="tweet"]` elements | | **Fix** | Add `wait_for_selector` between scroll calls with 1s delay | | **Code** | Test file: `tests/test_x_page_load_repro.py` | | **Verified** | - | ### #3: Modal/Dialog Scroll Container | Attribute | Value | |-----------|-------| | **Site** | Any site with modal dialogs | | **Symptom** | Scroll scrolls background page, not modal content | | **Root Cause** | Modal has its own scroll container with `overflow: scroll` | | **Detection** | Visible element with `position: fixed` and scrollable content | | **Fix** | Find visible modal container (highest z-index scrollable), scroll that | | **Code** | - | | **Verified** | - | --- ## Click Issues ### #4: Element Covered by Overlay | Attribute | Value | |-----------|-------| | **Site** | SPAs, sites with loading overlays | | **Symptom** | Click succeeds but no action triggered | | **Root Cause** | Element is covered by transparent overlay, tooltip, or iframe | | **Detection** | `document.elementFromPoint(x, y) !== target` | | **Fix** | Wait for overlay to disappear, or use JavaScript `element.click()` | | **Code** | `bridge.py:394-591` - JavaScript click as primary | | **Verified** | - | ### #5: React Synthetic Events | Attribute | Value | |-----------|-------| | **Site** | React applications | | **Symptom** | CDP click doesn't trigger React handler | | **Root Cause** | React uses synthetic events that don't respond to CDP events | | **Detection** | Site uses React (check for `__reactFiber$` or `data-reactroot`) | | **Fix** | Use JavaScript `element.click()` as primary method | | **Code** | `bridge.py:394-591` - JavaScript-first click | | **Verified** | - | ### #6: Shadow DOM Elements | Attribute | Value | |-----------|-------| | **Site** | Components using Shadow DOM, Lit elements | | **Symptom** | `querySelector` can't find element | | **Root Cause** | Element is inside a shadow root, not main DOM tree | | **Detection** | `element.shadowRoot !== null` on parent elements | | **Fix** | Use piercing selector (`host >>> target`) or traverse shadow roots | | **Code** | See SKILL.md P6 pattern | | **Verified** | 2026-04-03 ✓ | --- ## Input Issues ### #7: ContentEditable / Rich Text Editors | Attribute | Value | |-----------|-------| | **Site** | Rich text editors (Notion, Slack web, etc.) | | **Symptom** | `browser_interact(action="type")` doesn't insert text | | **Root Cause** | Element is `contenteditable`, not an `<input>` or `<textarea>` | | **Detection** | `element.contentEditable === 'true'` | | **Fix** | Focus via JavaScript, use `execCommand('insertText')` or `Input.dispatchKeyEvent` | | **Code** | `bridge.py:616-694` - contentEditable handling | ### #9: Custom Date Pickers | Attribute | Value | |-----------|-------| | **Site** | Forms with custom date widgets | | **Symptom** | Can't type date into date field | | **Root Cause** | Custom widget intercepts and blocks keyboard input | | **Detection** | Typing doesn't change field value | | **Fix** | Click calendar widget icon, select date from dropdown | | **Code** | - | | **Verified** | - | --- ## Snapshot Issues ### #10: LinkedIn Huge DOM Tree | Attribute | Value | |-----------|-------| | **Site** | LinkedIn, Facebook, Twitter feeds | | **Symptom** | `browser_snapshot()` hangs forever | | **Root Cause** | 10k+ DOM nodes, accessibility tree has 50k+ nodes | | **Detection** | `document.querySelectorAll('*').length > 5000` | | **Fix** | Add `timeout_s` param with `asyncio.timeout()`, proper error handling | | **Code** | `bridge.py:1041-1028` - snapshot with timeout protection | | **Verified** | 2026-04-03 ✓ (0.08s on LinkedIn) | ### #11: SPA Hydration Delay | Attribute | Value | |-----------|-------| | **Site** | React/Vue/Angular SPAs | | **Symptom** | Snapshot shows old content after navigation | | **Root Cause** | Client-side hydration hasn't completed when snapshot runs | | **Detection** | `document.readyState === 'complete'` but content missing | | **Fix** | Wait for specific selector after navigation | | **Code** | Test file: `tests/test_x_page_load_repro.py` | | **Verified** | - | ### #12: iframe Content Missing | Attribute | Value | |-----------|-------| | **Site** | Sites with embedded content | | **Symptom** | Snapshot missing iframe content | | **Root Cause** | Accessibility tree doesn't include iframe content | | **Detection** | `document.querySelectorAll('iframe')` has results | | **Fix** | Use `DOM.getFrameOwner` + separate snapshot for each iframe | | **Code** | - | | **Verified** | - | --- ## Navigation Issues ### #13: SPA Navigation Events | Attribute | Value | |-----------|-------| | **Site** | React Router, Vue Router SPAs | | **Symptom** | `wait_until="load"` fires before content ready | | **Root Cause** | SPA uses client-side routing, no full page load | | **Detection** | URL changes but `load` event already fired | | **Fix** | Use `wait_until="networkidle"` or `wait_for_selector` | | **Code** | `bridge.py:navigate()` - wait_until options | | **Verified** | - | ### #14: Cross-Origin Redirects | Attribute | Value | |-----------|-------| | **Site** | OAuth flows, SSO logins | | **Symptom** | Navigation fails during redirect | | **Root Cause** | Cross-origin security prevents CDP tracking | | **Detection** | URL changes to different domain | | **Fix** | Use `wait_for_url` with pattern matching instead of exact URL | --- ## Screenshot Issues ### #15: Selector Screenshot Not Implemented | Attribute | Value | |-----------|-------| | **Site** | Any site | | **Symptom** | `browser_screenshot(selector="h1")` takes full viewport instead of element | | **Root Cause** | `selector` param existed in signature but was silently ignored in both `bridge.py` and `inspection.py` | | **Detection** | Screenshot with selector same byte size as screenshot without selector | | **Fix** | Use CDP `Runtime.evaluate` to call `getBoundingClientRect()` on the element, pass result as `clip` to `Page.captureScreenshot` | | **Code** | `bridge.py:1315-1344` - selector clip logic; `inspection.py:94-96` - pass selector to bridge | | **Verified** | 2026-04-03 ✓ (JS rect query returns correct viewport coords; requires server restart) | ### #16: Stale Browser Context (Group ID Mismatch) | Attribute | Value | |-----------|-------| | **Site** | Any | | **Symptom** | `browser_open()` returns `"No group with id: XXXXXXX"` even though `browser_status` shows `running: true` | | **Root Cause** | In-memory `_contexts` dict has a stale `groupId` from a Chrome tab group that was closed outside the tool (e.g. user closed the tab group) | | **Detection** | `browser_status` returns `running: true` but `browser_open` fails with "No group with id" | | **Fix** | Call `browser_stop()` to clear stale context from `_contexts`, then `browser_open(url)` to lazy-create a fresh one | | **Code** | `tools/lifecycle.py:144-160` - `already_running` check uses cached dict without validating against Chrome | | **Verified** | 2026-04-03 ✓ | ### #17: X Chat Send Silently No-ops in Long-lived Session | Attribute | Value | |-----------|-------| | **Site** | x.com/i/chat (X Chat DMs) | | **Symptom** | `send_dm.py` returns `send_unverified` on every send: enabled `dm-composer-send-button` is found and clicked, but the composer never clears, no `message-text-*` bubble renders, and nothing is delivered server-side. Started after the browser session sat idle ~2h (rate-limit pause) | | **Root Cause** | The X Chat SPA's send path goes stale in a long-lived browser session — the click lands but the send silently no-ops (nothing queued; verified by bubble counts after recovery). Not a selector problem: the same selectors work in a fresh session | | **Detection** | Repeated `send_unverified` with `composerEmpty: false, msgCount: 0` across DIFFERENT recipients in the same session | | **Fix** | `browser_stop()` + `browser_open()` (full browser restart), then retry — sends verify as `sent` immediately. Failed clicks do NOT deliver later, so retrying after restart does not double-send | | **Code** | `core/framework/skills/_default_skills/x-com-automation/scripts/send_dm.py` verify step (faithful `send_unverified` reporting made this diagnosable) | | **Verified** | 2026-07-17 ✓ (queen session 20260716_130042; reproduced + confirmed via browser_remote) | Note: an aria-label `"Cancel voice note"` button in the composer alongside disabled attachment/GIF buttons is X's normal has-draft-text state (mislabeled clear button), NOT an active voice recording — red herring. `dm-composer-voice-button` no longer exists in the current composer; `dm-composer-send-button` mounts once React registers text. --- ## How to Add New Edge Cases 1. **Reproduce** the issue with minimal test case 2. **Document** using the template below 3. **Implement** fix with multi-layer fallback 4. **Verify** against both problematic and simple sites 5. **Submit** by appending to this file ### Template ```markdown ### #N: [Short Title] | Attribute | Value | |-----------|-------| | **Site** | [URL or site type] | | **Symptom** | [What the user observes] | | **Root Cause** | [Technical explanation] | | **Detection** | [JavaScript to detect this case] | | **Fix** | [Solution approach] | | **Code** | [File:line reference if implemented] | | **Verified** | [Date or "pending"] | ``` --- ## Statistics | Category | Count | |----------|-------| | Scroll Issues | 3 | | Click Issues | 4 | | Input Issues | 3 | | Snapshot Issues | 3 | | Navigation Issues | 2 | | Screenshot Issues | 2 | | **Total** | **17** | Last updated: 2026-07-17README.mdupstream ↗
Contents are not inlined in the catalog. Open the upstream file.
Plain-text copy, no login: /skill-bundles/aden-hive-hive-claude-skills-browser-edge-cases.md