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
Basic extraction
Magnus Müllera345dec8f210
diff --git a/browser_use/dom/playground/extraction.py b/browser_use/dom/playground/extraction.pyindex 70a6ef0ca..12e071c75 100644--- a/browser_use/dom/playground/extraction.py+++ b/browser_use/dom/playground/extraction.py@@ -108,7 +108,7 @@ async def test_focus_vs_all_elements():# save pure clickable elements to a fileif all_elements_state.dom_state._root:async with await anyio.open_file('./tmp/element_tree.json', 'w', encoding='utf-8') as f:- await f.write(json.dumps(all_elements_state.dom_state._root.__json__(), indent=0))+ await f.write(json.dumps(all_elements_state.dom_state._root.__json__(), indent=2))# copy the user message to the clipboard# pyperclip.copy(text_to_save)diff --git a/browser_use/dom/serializer/clickable_elements.py b/browser_use/dom/serializer/clickable_elements.pyindex 47e4b6c7b..abf0bbd3e 100644--- a/browser_use/dom/serializer/clickable_elements.py+++ b/browser_use/dom/serializer/clickable_elements.py@@ -1,8 +1,74 @@-from browser_use.dom.views import EnhancedDOMTreeNode+from browser_use.dom.views import EnhancedDOMTreeNode, NodeTypeclass ClickableElementDetector:@staticmethoddef is_interactive(node: EnhancedDOMTreeNode) -> bool:"""Check if this node is clickable/interactive using enhanced scoring."""- return True++ # Skip non-element nodes+ if node.node_type != NodeType.ELEMENT_NODE:+ return False++ # Primary check: snapshot data from Chrome's heuristics+ if node.snapshot_node and node.snapshot_node.is_clickable:+ return True++ # remove html and body nodes+ if node.tag_name in {'html', 'body'}:+ return False++ # Secondary check: intrinsically interactive HTML elements+ interactive_tags = {'button', 'input', 'select', 'textarea', 'a', 'label', 'details', 'summary', 'option', 'optgroup'}+ if node.tag_name in interactive_tags:+ return True++ # Tertiary check: elements with interactive attributes+ if node.attributes:+ # Check for event handlers or interactive attributes+ interactive_attributes = {'onclick', 'onmousedown', 'onmouseup', 'onkeydown', 'onkeyup', 'tabindex'}+ if any(attr in node.attributes for attr in interactive_attributes):+ return True++ # Check for interactive ARIA roles+ if 'role' in node.attributes:+ interactive_roles = {+ 'button',+ 'link',+ 'menuitem',+ 'option',+ 'radio',+ 'checkbox',+ 'tab',+ 'textbox',+ 'combobox',+ 'slider',+ 'spinbutton',+ }+ if node.attributes['role'] in interactive_roles:+ return True++ # Quaternary check: accessibility tree roles+ if node.ax_node and node.ax_node.role:+ interactive_ax_roles = {+ 'button',+ 'link',+ 'menuitem',+ 'option',+ 'radio',+ 'checkbox',+ 'tab',+ 'textbox',+ 'combobox',+ 'slider',+ 'spinbutton',+ 'listbox',+ }+ if node.ax_node.role in interactive_ax_roles:+ return True++ # Final check: cursor style indicates interactivity+ if node.snapshot_node and node.snapshot_node.cursor_style and node.snapshot_node.cursor_style == 'pointer':+ return True++ return False