Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

fix(dom): correct stackingContexts length check to access index list

itxaiohanglover780de2542744
diff --git a/browser_use/dom/enhanced_snapshot.py b/browser_use/dom/enhanced_snapshot.py
index 881f1c794..eb13ff51c 100644
--- a/browser_use/dom/enhanced_snapshot.py
+++ b/browser_use/dom/enhanced_snapshot.py
@@ -161,8 +161,8 @@ def build_snapshot_lookup(
)
# Extract stacking contexts if available
- if layout_idx < len(layout.get('stackingContexts', [])):
- stacking_contexts = layout.get('stackingContexts', [])[layout_idx]
+ if layout_idx < len(layout.get('stackingContexts', {}).get('index', [])):
+ stacking_contexts = layout.get('stackingContexts', {}).get('index', [])[layout_idx]
snapshot_lookup[backend_node_id] = EnhancedSnapshotNode(
is_clickable=is_clickable,