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
log-js-result
Magnus Müllerec8f901337d9
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.pyindex 0cbe430b6..18a6570bb 100644--- a/browser_use/agent/service.py+++ b/browser_use/agent/service.py@@ -1711,7 +1711,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):).replace('{', '').replace('}', '').replace("'", '').strip().strip(',')# Ensure action_params is always a string before checking lengthaction_params = str(action_params)- action_params = f'{action_params[:122]}...' if len(action_params) > 128 else action_params+ action_params = f'{action_params[:522]}...' if len(action_params) > 528 else action_paramstime_start = time.time()self.logger.info(f' 🦾 {blue}[ACTION {i + 1}/{total_actions}]{reset} {action_params}')diff --git a/browser_use/tools/service.py b/browser_use/tools/service.pyindex 6f1fd86ef..0a660408f 100644--- a/browser_use/tools/service.py+++ b/browser_use/tools/service.py@@ -980,14 +980,18 @@ You can also use it to explore the website.error_msg = f'JavaScript execution error: {exception.get("text", "Unknown error")}'if 'lineNumber' in exception:error_msg += f' at line {exception["lineNumber"]}'- return ActionResult(error=f'Code: {code}\n\nError: {error_msg}')+ msg = f'Code: {code}\n\nError: {error_msg}'+ logger.info(msg)+ return ActionResult(error=msg)# Get the result dataresult_data = result.get('result', {})# Check for wasThrown flag (backup error detection)if result_data.get('wasThrown'):- return ActionResult(error=f'Code: {code}\n\nError: JavaScript execution failed (wasThrown=true)')+ msg = f'Code: {code}\n\nError: JavaScript execution failed (wasThrown=true)'+ logger.info(msg)+ return ActionResult(error=msg)# Get the actual valuevalue = result_data.get('value')@@ -1010,13 +1014,15 @@ You can also use it to explore the website.# Apply length limit with better truncationif len(result_text) > 20000:result_text = result_text[:19950] + '\n... [Truncated after 20000 characters]'-+ msg = f'Code: {code}\n\nResult: {result_text}'+ logger.info(msg)return ActionResult(extracted_content=f'Code: {code}\n\nResult: {result_text}')except Exception as e:# CDP communication or other system errors- error_msg = f'Failed to execute JavaScript: {type(e).__name__}: {e}'- return ActionResult(error=f'Code: {code}\n\nError: {error_msg}')+ error_msg = f'Code: {code}\n\nError: {error_msg} Failed to execute JavaScript: {type(e).__name__}: {e}'+ logger.info(error_msg)+ return ActionResult(error=error_msg)# Custom done action for structured outputasync def extract_clean_markdown(