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
Improve error handling in JSON parsing by including the exception message in the ValueError. Added debug logging for successful model output parsing in utils.py to enhance traceability and debugging.
Magnus Müller543ee984b368
diff --git a/browser_use/agent/message_manager/utils.py b/browser_use/agent/message_manager/utils.pyindex aecc6ab7f..c048274ee 100644--- a/browser_use/agent/message_manager/utils.py+++ b/browser_use/agent/message_manager/utils.py@@ -91,10 +91,11 @@ def extract_json_from_model_output(content: str | BaseMessage) -> dict:result_dict = result_dict[0]assert isinstance(result_dict, dict), f'Expected JSON dictionary in response, got JSON {type(result_dict)} instead'+ logger.debug(f'Successfully parsed model output: {result_dict}')return result_dictexcept json.JSONDecodeError as e:logger.warning(f'Failed to parse model output: {content} {str(e)}')- raise ValueError('Could not parse response.')+ raise ValueError(f'Could not parse response. {str(e)}')def convert_input_messages(input_messages: list[BaseMessage], model_name: str | None) -> list[BaseMessage]:diff --git a/browser_use/agent/service.py b/browser_use/agent/service.pyindex 262fad75a..dc20235a0 100644--- a/browser_use/agent/service.py+++ b/browser_use/agent/service.py@@ -1179,7 +1179,7 @@ class Agent(Generic[Context]):parsed = self.AgentOutput(**parsed_json)except Exception as e:logger.warning(f'Failed to parse model output: {response["raw"]} {str(e)}')- raise ValueError('Could not parse response.')+ raise ValueError(f'Could not parse response. {str(e)}')# cut the number of actions to max_actions_per_step if neededif len(parsed.action) > self.settings.max_actions_per_step: