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
laminar-ignore input output
Magnus Müller6407c10918f7
diff --git a/browser_use/agent/message_manager/service.py b/browser_use/agent/message_manager/service.pyindex 5eba9ef0a..9275b754f 100644--- a/browser_use/agent/message_manager/service.py+++ b/browser_use/agent/message_manager/service.py@@ -163,7 +163,7 @@ class MessageManager:task_update_item = HistoryItem(system_message=f'User updated <user_request> to: {new_task}')self.state.agent_history_items.append(task_update_item)- @observe_debug(name='update_agent_history_description')+ @observe_debug(ignore_input=True, ignore_output=True, name='update_agent_history_description')def _update_agent_history_description(self,model_output: AgentOutput | None = None,@@ -245,7 +245,7 @@ class MessageManager:return ''- @observe_debug(name='add_state_message', ignore_input=True)+ @observe_debug(ignore_input=True, ignore_output=True, name='add_state_message')@time_execution_sync('--add_state_message')def add_state_message(self,diff --git a/browser_use/agent/prompts.py b/browser_use/agent/prompts.pyindex fccda50b8..22c98339f 100644--- a/browser_use/agent/prompts.py+++ b/browser_use/agent/prompts.py@@ -97,7 +97,7 @@ class AgentMessagePrompt:self.screenshots = screenshots or []assert self.browser_state- @observe_debug(name='_deduplicate_screenshots')+ @observe_debug(ignore_input=True, ignore_output=True, name='_deduplicate_screenshots')def _deduplicate_screenshots(self, screenshots: list[str]) -> list[str]:"""Remove consecutive duplicate screenshots, keeping only the most recent of each.@@ -127,7 +127,7 @@ class AgentMessagePrompt:return unique_screenshots- @observe_debug(name='_get_browser_state_description')+ @observe_debug(ignore_input=True, ignore_output=True, name='_get_browser_state_description')def _get_browser_state_description(self) -> str:elements_text = self.browser_state.element_tree.clickable_elements_to_string(include_attributes=self.include_attributes)@@ -230,7 +230,7 @@ Interactive elements from top layer of the current page inside the viewport{trunagent_state += '<available_file_paths>\n' + '\n'.join(self.available_file_paths) + '\n</available_file_paths>\n'return agent_state- @observe_debug(name='get_user_message')+ @observe_debug(ignore_input=True, ignore_output=True, name='get_user_message')def get_user_message(self, use_vision: bool = True) -> UserMessage:# Don't pass screenshot to model if page is a new tab page, step is 0, and there's only one tabif (diff --git a/browser_use/agent/service.py b/browser_use/agent/service.pyindex 84ccc2865..dcc8fcfdd 100644--- a/browser_use/agent/service.py+++ b/browser_use/agent/service.py@@ -632,7 +632,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):# self.logger.debug('Agent paused after getting state')raise InterruptedError- @observe_debug(name='get_browser_state_with_recovery', ignore_output=True)+ @observe_debug(ignore_input=True, ignore_output=True, name='get_browser_state_with_recovery')async def _get_browser_state_with_recovery(self, cache_clickable_elements_hashes: bool = True) -> BrowserStateSummary:"""Get browser state with multiple fallback strategies for error recovery"""@@ -1344,7 +1344,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):await self.close()- @observe_debug()+ @observe_debug(ignore_input=True, ignore_output=True)@time_execution_async('--multi_act')async def multi_act(self,diff --git a/browser_use/browser/profile.py b/browser_use/browser/profile.pyindex 2158f8741..7d223ef81 100644--- a/browser_use/browser/profile.py+++ b/browser_use/browser/profile.py@@ -737,7 +737,7 @@ class BrowserProfile(BrowserConnectArgs, BrowserLaunchPersistentContextArgs, Bro# logger.info(f'🔍 Preinstalling extension {extension_id}...')# # TODO: copy this from ArchiveBox implementation- @observe_debug(name='detect_display_configuration')+ @observe_debug(ignore_input=True, ignore_output=True, name='detect_display_configuration')def detect_display_configuration(self) -> None:"""Detect the system display size and initialize the display-related config defaults:diff --git a/browser_use/browser/session.py b/browser_use/browser/session.pyindex 35ed96aed..41e689046 100644--- a/browser_use/browser/session.py+++ b/browser_use/browser/session.py@@ -275,7 +275,7 @@ class BrowserSession(BaseModel):# """# return getattr(self.browser_profile, key)- @observe_debug(name='browser.session.start')+ @observe_debug(ignore_input=True, ignore_output=True, name='browser.session.start')async def start(self) -> Self:"""Starts the browser session by either connecting to an existing browser or launching a new one.@@ -684,7 +684,7 @@ class BrowserSession(BaseModel):self.logger.info(f'🎥 Saving browser context trace to {final_trace_path}...')await self.browser_context.tracing.stop(path=str(final_trace_path))- @observe_debug(name='connect_or_launch_browser')+ @observe_debug(ignore_input=True, ignore_output=True, name='connect_or_launch_browser')async def _connect_or_launch_browser(self) -> None:"""Try all connection methods in order of precedence."""# Try connecting via passed objects first@@ -710,7 +710,7 @@ class BrowserSession(BaseModel):# Launch new browser as last resortawait self.setup_new_browser_context()- @observe_debug(ignore_output=True)+ @observe_debug(ignore_input=True, ignore_output=True)@retry(wait=1, # wait 1s between each attempt to take a screenshotretries=1, # try up to 1 time to take the screenshot (2 total attempts)@@ -780,7 +780,7 @@ class BrowserSession(BaseModel):assert screenshot_b64, 'Playwright page.screenshot() returned empty base64'return screenshot_b64- @observe_debug(name='setup_playwright')+ @observe_debug(ignore_input=True, ignore_output=True, name='setup_playwright')@retry(wait=1,retries=3,@@ -1397,7 +1397,7 @@ class BrowserSession(BaseModel):# self.browser_profile.user_data_dir = fork_path# self.browser_profile.prepare_user_data_dir()- @observe_debug(name='setup_current_page_change_listeners')+ @observe_debug(ignore_input=True, ignore_output=True, name='setup_current_page_change_listeners')async def _setup_current_page_change_listeners(self) -> None:# Uses a combination of:# - visibilitychange events@@ -1522,7 +1522,9 @@ class BrowserSession(BaseModel):f'⚠️ Failed to add visibility listener to existing tab, is it crashed or ignoring CDP commands?: [{page_idx}]{page.url}: {type(e).__name__}: {e}')- @observe_debug(name='setup_viewports', metadata={'browser_profile': '{{browser_profile}}'})+ @observe_debug(+ ignore_input=True, ignore_output=True, name='setup_viewports', metadata={'browser_profile': '{{browser_profile}}'}+ )async def _setup_viewports(self) -> None:"""Resize any existing page viewports to match the configured size, set up storage_state, permissions, geolocation, etc."""@@ -1646,7 +1648,7 @@ class BrowserSession(BaseModel):if self.browser_profile.keep_alive is None:self.browser_profile.keep_alive = keep_alive- @observe_debug(name='is_connected')+ @observe_debug(ignore_input=True, ignore_output=True, name='is_connected')async def is_connected(self, restart: bool = True) -> bool:"""Check if the browser session has valid, connected browser and context objects.@@ -1806,7 +1808,7 @@ class BrowserSession(BaseModel):f'Using temporary profile instead: {_log_pretty_path(self.browser_profile.user_data_dir)}')- @observe_debug(name='prepare_user_data_dir')+ @observe_debug(ignore_input=True, ignore_output=True, name='prepare_user_data_dir')def prepare_user_data_dir(self, check_conflicts: bool = True) -> None:"""Create and prepare the user data dir, handling conflicts if needed.@@ -1908,7 +1910,7 @@ class BrowserSession(BaseModel):self.logger.error(f'❌ Failed to create parent directory for {path_name} {path_value}: {e}')# --- Tab management ---- @observe_debug(name='get_current_page', ignore_input=True)+ @observe_debug(ignore_input=True, ignore_output=True, name='get_current_page')async def get_current_page(self) -> Page:"""Get the current page + ensure it's not None / closed"""@@ -1978,7 +1980,7 @@ class BrowserSession(BaseModel):page = await self.get_current_page()await page.wait_for_selector(selector, state='visible', timeout=timeout)- @observe_debug(name='remove_highlights', ignore_output=True, ignore_input=True)+ @observe_debug(ignore_input=True, ignore_output=True, name='remove_highlights')@require_initialization@time_execution_async('--remove_highlights')@retry(timeout=2, retries=0)@@ -2644,7 +2646,7 @@ class BrowserSession(BaseModel):if elapsed > 1:self.logger.debug(f'💤 Page network traffic calmed down after {now - start_time:.2f} seconds')- @observe_debug(name='wait_for_page_and_frames_load')+ @observe_debug(ignore_input=True, ignore_output=True, name='wait_for_page_and_frames_load')async def _wait_for_page_and_frames_load(self, timeout_overwrite: float | None = None):"""Ensures page is fully loaded before continuing.@@ -2739,7 +2741,7 @@ class BrowserSession(BaseModel):self.logger.error(f'⛔️ Failed to go back after detecting non-allowed URL: {type(e).__name__}: {e}')raise URLNotAllowedError(f'Navigation to non-allowed URL: {page.url}')- @observe_debug()+ @observe_debug(ignore_input=True, ignore_output=True)async def navigate_to(self, url: str):"""Navigate the agent's current tab to a URL"""@@ -2758,7 +2760,10 @@ class BrowserSession(BaseModel):# NOTE we dont have to wait since we will wait later when we get the new page statepass- @observe_debug()+ @observe_debug(+ ignore_input=True,+ ignore_output=True,+ )async def refresh_page(self):"""Refresh the agent's current page"""@@ -2899,7 +2904,7 @@ class BrowserSession(BaseModel):structure = await page.evaluate(debug_script)return structure- @observe_debug(ignore_output=True)+ @observe_debug(ignore_input=True, ignore_output=True)@time_execution_async('--get_state_summary')@require_initializationasync def get_state_summary(self, cache_clickable_elements_hashes: bool) -> BrowserStateSummary:@@ -2943,7 +2948,7 @@ class BrowserSession(BaseModel):return self._cached_browser_state_summary- @observe_debug(name='get_minimal_state_summary', ignore_output=True)+ @observe_debug(ignore_input=True, ignore_output=True, name='get_minimal_state_summary')@require_initialization@time_execution_async('--get_minimal_state_summary')async def get_minimal_state_summary(self) -> BrowserStateSummary:@@ -2991,7 +2996,7 @@ class BrowserSession(BaseModel):browser_errors=[f'Page state retrieval failed, minimal recovery applied for {url}'],)- @observe_debug(name='get_updated_state', ignore_output=True)+ @observe_debug(ignore_input=True, ignore_output=True, name='get_updated_state')async def _get_updated_state(self, focus_element: int = -1) -> BrowserStateSummary:"""Update and return state."""@@ -3132,7 +3137,7 @@ class BrowserSession(BaseModel):raise# region - Browser Actions- @observe_debug(name='take_screenshot')+ @observe_debug(ignore_input=True, ignore_output=True, name='take_screenshot')@require_initialization@time_execution_async('--take_screenshot')async def take_screenshot(self, full_page: bool = False) -> str:@@ -3670,7 +3675,7 @@ class BrowserSession(BaseModel):return page- @observe_debug(name='create_new_tab')+ @observe_debug(ignore_input=True, ignore_output=True, name='create_new_tab')@time_execution_async('--create_new_tab')async def create_new_tab(self, url: str | None = None) -> Page:"""Create a new tab and optionally navigate to a URL"""@@ -3767,21 +3772,21 @@ class BrowserSession(BaseModel):return new_page# region - Helper methods for easier access to the DOM- @observe_debug(name='get_selector_map')+ @observe_debug(ignore_input=True, ignore_output=True, name='get_selector_map')@require_initializationasync def get_selector_map(self) -> SelectorMap:if self._cached_browser_state_summary is None:return {}return self._cached_browser_state_summary.selector_map- @observe_debug(name='get_element_by_index')+ @observe_debug(ignore_input=True, ignore_output=True, name='get_element_by_index')@require_initializationasync def get_element_by_index(self, index: int) -> ElementHandle | None:selector_map = await self.get_selector_map()element_handle = await self.get_locate_element(selector_map[index])return element_handle- @observe_debug(name='is_file_input_by_index')+ @observe_debug(ignore_input=True, ignore_output=True, name='is_file_input_by_index')async def is_file_input_by_index(self, index: int) -> bool:try:selector_map = await self.get_selector_map()@@ -4121,7 +4126,7 @@ class BrowserSession(BaseModel):str(self.id)[-4:],)- @observe_debug(name='get_state_summary_with_fallback', ignore_output=True)+ @observe_debug(ignore_input=True, ignore_output=True, name='get_state_summary_with_fallback')@require_initialization@time_execution_async('--get_state_summary_with_fallback')async def get_state_summary_with_fallback(self, cache_clickable_elements_hashes: bool = True) -> BrowserStateSummary:diff --git a/browser_use/controller/registry/service.py b/browser_use/controller/registry/service.pyindex d59384c67..678ce13da 100644--- a/browser_use/controller/registry/service.py+++ b/browser_use/controller/registry/service.py@@ -309,7 +309,7 @@ class Registry(Generic[Context]):return decorator- @observe_debug(name='execute_action')+ @observe_debug(ignore_input=True, ignore_output=True, name='execute_action')@time_execution_async('--execute_action')async def execute_action(self,diff --git a/browser_use/controller/service.py b/browser_use/controller/service.pyindex 69be01a65..eb73ad6cf 100644--- a/browser_use/controller/service.py+++ b/browser_use/controller/service.py@@ -1150,7 +1150,7 @@ Explain the content of the page and that the requested information is not availareturn self.registry.action(description, **kwargs)# Act --------------------------------------------------------------------- @observe_debug(name='act')+ @observe_debug(ignore_input=True, ignore_output=True, name='act')@time_execution_sync('--act')async def act(self,diff --git a/browser_use/observability.py b/browser_use/observability.pyindex 77265c9b8..334af9fa8 100644--- a/browser_use/observability.py+++ b/browser_use/observability.py@@ -150,7 +150,7 @@ def observe_debug(Decorated function that may be traced only in debug modeExample:- @observe_debug(name="debug_function", metadata={"debug": True})+ @observe_debug(ignore_input=True, ignore_output=True,name="debug_function", metadata={"debug": True})def debug_function(param1, param2):return param1 + param2"""diff --git a/eval/comprehensive_judge.py b/eval/comprehensive_judge.pyindex f4122cb01..0cc516b32 100644--- a/eval/comprehensive_judge.py+++ b/eval/comprehensive_judge.py@@ -117,7 +117,10 @@ def truncate_text(text: str, max_length: int, from_beginning: bool = False) -> sreturn text[: max_length - 23] + '...[cut for eval]...'-@observe_debug()+@observe_debug(+ ignore_input=True,+ ignore_output=True,+)def prepare_agent_steps(complete_history: list[dict]) -> list[str]:"""Extract and format agent steps, limiting each to 2000 characters.@@ -184,7 +187,10 @@ def prepare_agent_steps(complete_history: list[dict]) -> list[str]:return last_part[::-1]-@observe_debug()+@observe_debug(+ ignore_input=True,+ ignore_output=True,+)def are_images_identical(img_path1: str, img_path2: str) -> bool:"""Check if two images are identical by comparing their content."""try:@@ -205,7 +211,10 @@ def are_images_identical(img_path1: str, img_path2: str) -> bool:return False-@observe_debug()+@observe_debug(+ ignore_input=True,+ ignore_output=True,+)def filter_images(screenshot_paths: list[str], max_images: int) -> list[str]:"""Filter screenshot paths to:@@ -237,7 +246,10 @@ def filter_images(screenshot_paths: list[str], max_images: int) -> list[str]:return deduplicated_paths[-max_images:] if len(deduplicated_paths) > max_images else deduplicated_paths-@observe_debug()+@observe_debug(+ ignore_input=True,+ ignore_output=True,+)async def comprehensive_judge(task: str,complete_history: list[dict],@@ -448,7 +460,10 @@ Evaluate this agent execution given the criteria and respond with the exact JSONreturn create_fallback_result(task, str(e))-@observe_debug()+@observe_debug(+ ignore_input=True,+ ignore_output=True,+)def parse_judge_response(result_dict: dict, task: str) -> JudgeResult:"""Parse the LLM response into a structured JudgeResult."""try:@@ -476,7 +491,10 @@ def parse_judge_response(result_dict: dict, task: str) -> JudgeResult:return create_fallback_result(task, 'Failed to parse structured response')-@observe_debug()+@observe_debug(+ ignore_input=True,+ ignore_output=True,+)def create_fallback_result(task: str, error_msg: str) -> JudgeResult:"""Create a fallback result when evaluation fails."""return JudgeResult(@@ -488,7 +506,10 @@ def create_fallback_result(task: str, error_msg: str) -> JudgeResult:)-@observe_debug()+@observe_debug(+ ignore_input=True,+ ignore_output=True,+)async def judge_with_retry(task: str,complete_history: list[dict],@@ -645,7 +666,10 @@ def _write_result_file(result_file: Path, result_data: dict[str, Any]) -> None:# Integration helper function-@observe_debug()+@observe_debug(+ ignore_input=True,+ ignore_output=True,+)async def evaluate_task_with_comprehensive_judge(task_folder: Path, model: BaseChatModel, max_images: int = 10, judge_repeat_count: int = 1) -> dict[str, Any]:diff --git a/eval/resource_monitoring.py b/eval/resource_monitoring.pyindex 15d260b24..6050e9d78 100644--- a/eval/resource_monitoring.py+++ b/eval/resource_monitoring.py@@ -20,7 +20,10 @@ _resource_monitor_stop_event = None_graceful_shutdown_initiated = False-@observe_debug()+@observe_debug(+ ignore_input=True,+ ignore_output=True,+)def get_system_resources() -> dict[str, Any]:"""Get current system resource usage"""try:@@ -81,7 +84,10 @@ def get_system_resources() -> dict[str, Any]:}-@observe_debug()+@observe_debug(+ ignore_input=True,+ ignore_output=True,+)def log_system_resources(context: str = ''):"""Log current system resource usage"""resources = get_system_resources()diff --git a/eval/service.py b/eval/service.pyindex 9eebd4aa8..f7dca5b0b 100644--- a/eval/service.py+++ b/eval/service.py@@ -347,7 +347,10 @@ async def reformat_agent_history(# ================================================-@observe_debug()+@observe_debug(+ ignore_input=True,+ ignore_output=True,+)async def judge_task_result(model, task_folder: Path, score_threshold: float = 3, use_mind2web: bool = False, judge_repeat_count: int = 1) -> dict:@@ -645,7 +648,10 @@ async def evaluate_task_result()-@observe_debug()+@observe_debug(+ ignore_input=True,+ ignore_output=True,+)async def cleanup_browser_safe(browser_session: BrowserSession):"""Safe browser cleanup with timeout"""try:@@ -1150,7 +1156,10 @@ async def run_task_with_semaphore(return final_result-@observe_debug()+@observe_debug(+ ignore_input=True,+ ignore_output=True,+)async def run_multiple_tasks(tasks: list[Task],llm: BaseChatModel,@@ -1214,7 +1223,10 @@ async def run_multiple_tasks(heartbeat_task = Noneheartbeat_stop_event = asyncio.Event()- @observe_debug()+ @observe_debug(+ ignore_input=True,+ ignore_output=True,+ )async def heartbeat_logger():"""Log periodic heartbeat to show the process is alive"""heartbeat_count = 0@@ -1347,7 +1359,10 @@ async def run_multiple_tasks(# ================================================-@observe_debug()+@observe_debug(+ ignore_input=True,+ ignore_output=True,+)async def run_evaluation_pipeline(tasks: list[Task],llm: BaseChatModel,