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
More time calculations
magmueller52cf8402b55c
diff --git a/src/agent/prompts.py b/src/agent/prompts.pyindex a6a7bc139..cefb2b110 100644--- a/src/agent/prompts.py+++ b/src/agent/prompts.py@@ -1,6 +1,7 @@from langchain_core.messages import HumanMessage, SystemMessagefrom src.controller.views import ControllerPageState+from src.utils import time_execution_syncclass AgentSystemPrompt:@@ -62,6 +63,7 @@ class AgentMessagePrompt:def __init__(self, state: ControllerPageState):self.state = state+ @time_execution_sync('get_user_message')def get_user_message(self) -> HumanMessage:state_description = f"""Current url: {self.state.url}diff --git a/src/browser/service.py b/src/browser/service.pyindex 7d25642a4..b9a529fc6 100644--- a/src/browser/service.py+++ b/src/browser/service.py@@ -320,6 +320,7 @@ class BrowserService:except Exception as e:raise Exception(f'Failed to click element with xpath: {xpath}. Error: {str(e)}')+ @time_execution_sync('click')def click_element_by_index(self, index: int, state: BrowserState):"""Clicks an element using its index from the selector map.diff --git a/src/controller/service.py b/src/controller/service.pyindex 4f6caac14..63fa267bc 100644--- a/src/controller/service.py+++ b/src/controller/service.py@@ -1,6 +1,7 @@from src.browser.service import BrowserServicefrom src.browser.views import BrowserStatefrom src.controller.views import ControllerActionResult, ControllerActions, ControllerPageState+from src.utils import time_execution_syncclass ControllerService:@@ -41,6 +42,7 @@ class ControllerService:screenshot=screenshot_b64,)+ @time_execution_sync('act')def act(self, action: ControllerActions) -> ControllerActionResult:try:current_state = self.get_cached_browser_state(force_update=True)diff --git a/src/dom/service.py b/src/dom/service.pyindex 81b6a7bf5..07a129ea4 100644--- a/src/dom/service.py+++ b/src/dom/service.py@@ -9,7 +9,8 @@ class DomService:self.driver = driverdef get_clickable_elements(self) -> ProcessedDomContent:- # Get current state of DOM by executing JavaScript+ # Clear xpath cache on each new DOM processing+ self.xpath_cache = {}html_content = self.driver.page_sourcereturn self._process_content(html_content)@@ -253,6 +254,9 @@ class DomService:if len(same_type_siblings) > 1:try:index = same_type_siblings.index(current) + 1+ # print(+ # f'Debug XPath: Found {len(same_type_siblings)} siblings of type {current.name}, current index: {index}'+ # )parts.insert(0, f'{current.name}[{index}]')except ValueError:parts.insert(0, current.name)diff --git a/src/dom/tests/extraction_test.py b/src/dom/tests/extraction_test.pyindex dab2ebac5..68d47471d 100644--- a/src/dom/tests/extraction_test.py+++ b/src/dom/tests/extraction_test.py@@ -5,8 +5,8 @@ from selenium.webdriver.common.by import Byfrom selenium.webdriver.support import expected_conditions as ECfrom selenium.webdriver.support.ui import WebDriverWaitfrom tokencost import count_string_tokens-from src.browser.service import BrowserService+from src.browser.service import BrowserServicefrom src.dom.service import DomServicefrom src.utils import time_execution_sync