Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

added back client rects cache

Gregor Žunič6bad3b310c51
diff --git a/browser_use/dom/dom_tree/index.js b/browser_use/dom/dom_tree/index.js
index 56d212034..69d820588 100644
--- a/browser_use/dom/dom_tree/index.js
+++ b/browser_use/dom/dom_tree/index.js
@@ -12,9 +12,11 @@
// Add caching mechanisms at the top level
const DOM_CACHE = {
boundingRects: new WeakMap(),
+ clientRects: new WeakMap(),
computedStyles: new WeakMap(),
clearCache: () => {
DOM_CACHE.boundingRects = new WeakMap();
+ DOM_CACHE.clientRects = new WeakMap();
DOM_CACHE.computedStyles = new WeakMap();
}
};
@@ -54,7 +56,16 @@
function getCachedClientRects(element) {
if (!element) return null;
- return element.getClientRects();
+ if (DOM_CACHE.clientRects.has(element)) {
+ return DOM_CACHE.clientRects.get(element);
+ }
+
+ const rects = element.getClientRects();
+
+ if (rects) {
+ DOM_CACHE.clientRects.set(element, rects);
+ }
+ return rects;
}
/**
diff --git a/browser_use/dom/views.py b/browser_use/dom/views.py
index 3c04220bc..7b83bfcff 100644
--- a/browser_use/dom/views.py
+++ b/browser_use/dom/views.py
@@ -56,15 +56,15 @@ class DOMTextNode(DOMBaseNode):
DEFAULT_INCLUDE_ATTRIBUTES = [
'title',
'type',
- # 'name',
+ 'checked',
+ 'name',
'role',
'value',
- 'aria-label',
'placeholder',
+ 'data-date-format',
'alt',
+ 'aria-label',
'aria-expanded',
- 'data-date-format',
- 'checked',
'data-state',
'aria-checked',
]
@@ -188,7 +188,7 @@ class DOMElementNode(DOMBaseNode):
attributes_html_str = None
if include_attributes:
attributes_to_include = {
- key: str(value)
+ key: str(value).strip()
for key, value in node.attributes.items()
if key in include_attributes and str(value).strip() != ''
}
@@ -239,7 +239,7 @@ class DOMElementNode(DOMBaseNode):
if attributes_to_include.items():
# Format as key1='value1' key2='value2'
attributes_html_str = ' '.join(
- f'{key}={cap_text_length(value, 15)}' for key, value in attributes_to_include.items()
+ f'{key}={cap_text_length(value, 20)}' for key, value in attributes_to_include.items()
)
# Build the line
diff --git a/examples/simple.py b/examples/simple.py
index cbde69fd8..505e13de1 100644
--- a/examples/simple.py
+++ b/examples/simple.py
@@ -19,7 +19,7 @@ llm = ChatOpenAI(
)
-task = 'Open 3 tabs with random wikipedia pages'
+task = 'Go to google.com/travel/flights and search for flights to Tokyo next week'
agent = Agent(task=task, llm=llm)