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
The __hash__ method inefficiently recreates the static_attributes set on every call.
Magnus Müllerca469caa317f
diff --git a/browser_use/dom/views.py b/browser_use/dom/views.pyindex 37d25fb0b..80e54bde4 100644--- a/browser_use/dom/views.py+++ b/browser_use/dom/views.py@@ -51,6 +51,53 @@ DEFAULT_INCLUDE_ATTRIBUTES = ['ax_name',]+STATIC_ATTRIBUTES = set(+ [+ 'class',+ 'id',+ 'name',+ 'type',+ 'placeholder',+ 'aria-label',+ 'title',+ # 'aria-expanded',+ 'role',+ 'data-testid',+ 'data-test',+ 'data-cy',+ 'data-selenium',+ 'for',+ 'required',+ 'disabled',+ 'readonly',+ 'checked',+ 'selected',+ 'multiple',+ 'href',+ 'target',+ 'rel',+ 'aria-describedby',+ 'aria-labelledby',+ 'aria-controls',+ 'aria-owns',+ 'aria-live',+ 'aria-atomic',+ 'aria-busy',+ 'aria-disabled',+ 'aria-hidden',+ 'aria-pressed',+ 'aria-checked',+ 'aria-selected',+ 'tabindex',+ 'alt',+ 'src',+ 'lang',+ 'itemscope',+ 'itemtype',+ 'itemprop',+ ]+)+@dataclassclass CurrentPageTargets:@@ -683,54 +730,9 @@ class EnhancedDOMTreeNode:parent_branch_path = self._get_parent_branch_path()parent_branch_path_string = '/'.join(parent_branch_path)- # Get attributes hash- static_attributes = set(- [- 'class',- 'id',- 'name',- 'type',- 'placeholder',- 'aria-label',- 'title',- # 'aria-expanded',- 'role',- 'data-testid',- 'data-test',- 'data-cy',- 'data-selenium',- 'for',- 'required',- 'disabled',- 'readonly',- 'checked',- 'selected',- 'multiple',- 'href',- 'target',- 'rel',- 'aria-describedby',- 'aria-labelledby',- 'aria-controls',- 'aria-owns',- 'aria-live',- 'aria-atomic',- 'aria-busy',- 'aria-disabled',- 'aria-hidden',- 'aria-pressed',- 'aria-checked',- 'aria-selected',- 'tabindex',- 'alt',- 'src',- 'lang',- 'itemscope',- 'itemtype',- 'itemprop',- ]+ attributes_string = ''.join(+ f'{k}={v}' for k, v in sorted((k, v) for k, v in self.attributes.items() if k in STATIC_ATTRIBUTES))- attributes_string = ''.join(f"{k}={v}" for k, v in sorted((k, v) for k, v in self.attributes.items() if k in static_attributes))# Combine both for final hashcombined_string = f'{parent_branch_path_string}|{attributes_string}'