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
tiny refactor
Gregor Žunič66a52ab559af
diff --git a/browser_use/dom/serializer.py b/browser_use/dom/serializer/serializer.pysimilarity index 95%rename from browser_use/dom/serializer.pyrename to browser_use/dom/serializer/serializer.pyindex 8bfb7fb8b..14c40bbbd 100644--- a/browser_use/dom/serializer.py+++ b/browser_use/dom/serializer/serializer.py@@ -36,14 +36,6 @@ class DOMTreeSerializer:self._previous_cached_selector_map = previous_cached_state.selector_map if previous_cached_state else Nonedef serialize_accessible_elements(self) -> SerializedDOMState:- """Convert the enhanced DOM tree to string format, showing accessible elements and text content.--- Returns:- - Serialized string representation- - Selector map mapping interactive indices to DOM nodes- """-# Reset stateself._interactive_counter = 1self._selector_map = {}@@ -276,7 +268,7 @@ class DOMTreeSerializer:del attributes_to_include[key]# Remove attributes that duplicate accessibility data- role = DOMTreeSerializer._get_accessibility_role(node)+ role = node.ax_node.role if node.ax_node else Noneif role and node.node_name == role:attributes_to_include.pop('role', None)@@ -289,10 +281,3 @@ class DOMTreeSerializer:return ' '.join(f'{key}={cap_text_length(value, 15)}' for key, value in attributes_to_include.items())return ''-- @staticmethod- def _get_accessibility_role(node: EnhancedDOMTreeNode) -> str | None:- """Get the accessibility role from the AX node."""- if node.ax_node:- return node.ax_node.role- return Nonediff --git a/browser_use/dom/service.py b/browser_use/dom/service.pyindex ccab4b9da..5f679cb1c 100644--- a/browser_use/dom/service.py+++ b/browser_use/dom/service.py@@ -14,7 +14,7 @@ from browser_use.dom.enhanced_snapshot import (REQUIRED_COMPUTED_STYLES,build_snapshot_lookup,)-from browser_use.dom.serializer import DOMTreeSerializer+from browser_use.dom.serializer.serializer import DOMTreeSerializerfrom browser_use.dom.views import (EnhancedAXNode,EnhancedAXProperty,diff --git a/browser_use/dom/views.py b/browser_use/dom/views.pyindex 818db888c..43b46c758 100644--- a/browser_use/dom/views.py+++ b/browser_use/dom/views.py@@ -358,7 +358,7 @@ class SerializedDOMState:include_attributes: list[str] | None = None,) -> str:"""Kinda ugly, but leaving this as an internal method because include_attributes are a parameter on the agent, so we need to leave it as a 2 step process"""- from browser_use.dom.serializer import DOMTreeSerializer+ from browser_use.dom.serializer.serializer import DOMTreeSerializerif not self._root:return 'Empty DOM tree'