Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
Enhance snapshot lookup by preserving the first occurrence of duplicate node indices in layout index map. This change optimizes the processing of layout data while maintaining original behavior.
Magnus Müller64bb6bdc11f6
diff --git a/browser_use/dom/enhanced_snapshot.py b/browser_use/dom/enhanced_snapshot.pyindex 5adabac3c..09ebca734 100644--- a/browser_use/dom/enhanced_snapshot.py+++ b/browser_use/dom/enhanced_snapshot.py@@ -82,10 +82,12 @@ def build_snapshot_lookup(backend_node_to_snapshot_index[backend_node_id] = i# PERFORMANCE: Pre-build layout index map to eliminate O(n²) double lookups+ # Preserve original behavior: use FIRST occurrence for duplicateslayout_index_map = {}if layout and 'nodeIndex' in layout:for layout_idx, node_index in enumerate(layout['nodeIndex']):- layout_index_map[node_index] = layout_idx+ if node_index not in layout_index_map: # Only store first occurrence+ layout_index_map[node_index] = layout_idx# Build snapshot lookup for each backend node idfor backend_node_id, snapshot_index in backend_node_to_snapshot_index.items():