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
fixed shadow root xpaths
Gregor Žunič7f8bbff08324
diff --git a/browser_use/dom/playground/extraction.py b/browser_use/dom/playground/extraction.pyindex 67d949bb3..24048d887 100644--- a/browser_use/dom/playground/extraction.py+++ b/browser_use/dom/playground/extraction.py@@ -24,9 +24,10 @@ async def test_focus_vs_all_elements():browser_profile=BrowserProfile(# executable_path='/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',window_size=ViewportSize(width=1100, height=1000),- disable_security=True,+ disable_security=False,wait_for_network_idle_page_load_time=1,headless=False,+ args=['--incognito'],),)diff --git a/browser_use/dom/service.py b/browser_use/dom/service.pyindex 092c5bbc2..8729cc2b4 100644--- a/browser_use/dom/service.py+++ b/browser_use/dom/service.py@@ -249,7 +249,10 @@ class DomService:if 'shadowRoots' in node and node['shadowRoots']:dom_tree_node.shadow_roots = []for shadow_root in node['shadowRoots']:- dom_tree_node.shadow_roots.append(_construct_enhanced_node(shadow_root))+ shadow_root_node = _construct_enhanced_node(shadow_root)+ # forcefully set the parent node to the shadow root node (helps traverse the tree)+ shadow_root_node.parent_node = dom_tree_node+ dom_tree_node.shadow_roots.append(shadow_root_node)if 'children' in node and node['children']:dom_tree_node.children_nodes = []diff --git a/browser_use/dom/views.py b/browser_use/dom/views.pyindex 74d32706c..e471b0021 100644--- a/browser_use/dom/views.py+++ b/browser_use/dom/views.py@@ -215,12 +215,16 @@ class EnhancedDOMTreeNode:segments = []current_element = self- while current_element and current_element.node_type == NodeType.ELEMENT_NODE:- # Stop if we hit a shadow root or iframe- if current_element.parent_node and (- current_element.parent_node.shadow_root_type is not None- or current_element.parent_node.node_name.lower() == 'iframe'- ):+ while current_element and (+ current_element.node_type == NodeType.ELEMENT_NODE or current_element.node_type == NodeType.DOCUMENT_FRAGMENT_NODE+ ):+ # just pass through shadow roots+ if current_element.node_type == NodeType.DOCUMENT_FRAGMENT_NODE:+ current_element = current_element.parent_node+ continue++ # stop ONLY if we hit iframe+ if current_element.parent_node and current_element.parent_node.node_name.lower() == 'iframe':breakposition = self._get_element_position(current_element)