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
removed client reacts cache, refactor scripts
Gregor Žuničcf03b7a9d462
diff --git a/browser_use/dom/dom_tree/index.js b/browser_use/dom/dom_tree/index.jsindex 8a7af4941..d98959535 100644--- a/browser_use/dom/dom_tree/index.js+++ b/browser_use/dom/dom_tree/index.js@@ -12,11 +12,9 @@// Add caching mechanisms at the top levelconst 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();}};@@ -56,16 +54,7 @@function getCachedClientRects(element) {if (!element) return null;- 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;+ return element.getClientRects();}/**diff --git a/tests/old/extraction_test.py b/browser_use/dom/playground/extraction.pysimilarity index 93%rename from tests/old/extraction_test.pyrename to browser_use/dom/playground/extraction.pyindex e2f61cf51..42a14a479 100644--- a/tests/old/extraction_test.py+++ b/browser_use/dom/playground/extraction.py@@ -1,7 +1,9 @@import asyncioimport os+import timeimport anyio+import tiktokenfrom browser_use.agent.prompts import AgentMessagePromptfrom browser_use.browser import BrowserProfile, BrowserSession@@ -71,7 +73,11 @@ async def test_focus_vs_all_elements():# Get/refresh the state (includes removing old highlights)print('\nGetting page state...')++ start_time = time.time()all_elements_state = await browser_session.get_state_summary(True)+ end_time = time.time()+ print(f'get_state_summary took {end_time - start_time:.2f} seconds')selector_map = all_elements_state.selector_maptotal_elements = len(selector_map.keys())@@ -86,7 +92,7 @@ async def test_focus_vs_all_elements():)# print(prompt.get_user_message(use_vision=False).content)# Write the user message to a file for analysis- user_message = prompt.get_user_message(use_vision=False).content+ user_message = prompt.get_user_message(use_vision=False).textos.makedirs('./tmp', exist_ok=True)async with await anyio.open_file('./tmp/user_message.txt', 'w', encoding='utf-8') as f:if isinstance(user_message, str):@@ -94,6 +100,10 @@ async def test_focus_vs_all_elements():else:await f.write(str(user_message))+ encoding = tiktoken.encoding_for_model('gpt-4o')+ token_count = len(encoding.encode(user_message))+ print(f'Token count: {token_count}')+print('User message written to ./tmp/user_message.txt')# also save all_elements_state.element_tree.clickable_elements_to_string() to a filediff --git a/tests/old/process_dom_test.py b/browser_use/dom/playground/process_dom.pysimilarity index 100%rename from tests/old/process_dom_test.pyrename to browser_use/dom/playground/process_dom.pydiff --git a/browser_use/dom/tests/test_accessibility_playground.py b/browser_use/dom/playground/test_accessibility.pysimilarity index 100%rename from browser_use/dom/tests/test_accessibility_playground.pyrename to browser_use/dom/playground/test_accessibility.py