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
small token optimization with title
Gregor Žunič6de2a103ad7c
diff --git a/browser_use/dom/playground/extraction.py b/browser_use/dom/playground/extraction.pyindex a502779a3..292900b52 100644--- a/browser_use/dom/playground/extraction.py+++ b/browser_use/dom/playground/extraction.py@@ -81,7 +81,6 @@ async def test_focus_vs_all_elements():include_attributes=DEFAULT_INCLUDE_ATTRIBUTES,step_info=None,)- print(prompt.get_user_message(use_vision=False).content)# Write the user message to a file for analysisuser_message = prompt.get_user_message(use_vision=False).textdiff --git a/browser_use/dom/views.py b/browser_use/dom/views.pyindex 8fbd8e35a..bd7c34a1e 100644--- a/browser_use/dom/views.py+++ b/browser_use/dom/views.py@@ -222,24 +222,19 @@ class DOMElementNode(DOMBaseNode):if node.tag_name == attributes_to_include.get('role'):del attributes_to_include['role']- # if aria-label == text of the node, don't include it- if (- attributes_to_include.get('aria-label')- and attributes_to_include.get('aria-label', '').strip() == text.strip()- ):- del attributes_to_include['aria-label']-- # if placeholder == text of the node, don't include it- if (- attributes_to_include.get('placeholder')- and attributes_to_include.get('placeholder', '').strip() == text.strip()- ):- del attributes_to_include['placeholder']+ # Remove attributes that duplicate the node's text content+ attrs_to_remove_if_text_matches = ['aria-label', 'placeholder', 'title']+ for attr in attrs_to_remove_if_text_matches:+ if (+ attributes_to_include.get(attr)+ and attributes_to_include.get(attr, '').strip().lower() == text.strip().lower()+ ):+ del attributes_to_include[attr]if attributes_to_include.items():# Format as key1='value1' key2='value2'attributes_html_str = ' '.join(- f'{key}={cap_text_length(value, 20)}' for key, value in attributes_to_include.items()+ f'{key}={cap_text_length(value, 15)}' for key, value in attributes_to_include.items())# Build the line@@ -264,7 +259,8 @@ class DOMElementNode(DOMBaseNode):elif not attributes_html_str:line += ' '- # line += ' />' # 1 token+ # makes sense to have if the website has lots of text -> so the LLM knows which things are part of the same clickable element and which are not+ line += ' />' # 1 tokenformatted_text.append(line)# Process children regardless