Skip to content

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

log-js-result

Magnus Müllerec8f901337d9
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index 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 length
action_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_params
time_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.py
index 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 data
result_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 value
value = result_data.get('value')
@@ -1010,13 +1014,15 @@ You can also use it to explore the website.
# Apply length limit with better truncation
if 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 output
async def extract_clean_markdown(