mirror of
https://github.com/browser-use/browser-use
synced 2026-05-06 17:52:15 +02:00
Merge branch 'main' into saurav/fix-docs-for-cloud-browser
This commit is contained in:
@@ -84,8 +84,8 @@ Check out the [library docs](https://docs.browser-use.com) and [cloud docs](http
|
||||
https://github.com/user-attachments/assets/171fb4d6-0355-46f2-863e-edb04a828d04
|
||||
|
||||
<br/><br/>
|
||||
See more [examples in the docs](https://docs.browser-use.com/examples).
|
||||
|
||||
See [more examples](https://docs.browser-use.com/examples) and give us a star!
|
||||
|
||||
|
||||
<br/><br/>
|
||||
|
||||
@@ -68,6 +68,7 @@ from browser_use.tools.service import Tools
|
||||
from browser_use.utils import (
|
||||
URL_PATTERN,
|
||||
_log_pretty_path,
|
||||
check_latest_browser_use_version,
|
||||
get_browser_use_version,
|
||||
get_git_info,
|
||||
time_execution_async,
|
||||
@@ -1175,13 +1176,20 @@ class Agent(Generic[Context, AgentStructuredOutput]):
|
||||
# Just re-raise - Pydantic's validation errors are already descriptive
|
||||
raise
|
||||
|
||||
def _log_agent_run(self) -> None:
|
||||
async def _log_agent_run(self) -> None:
|
||||
"""Log the agent run"""
|
||||
# Blue color for task
|
||||
self.logger.info(f'\033[34m🚀 Task: {self.task}\033[0m')
|
||||
|
||||
self.logger.debug(f'🤖 Browser-Use Library Version {self.version} ({self.source})')
|
||||
|
||||
# Check for latest version and log upgrade message if needed
|
||||
latest_version = await check_latest_browser_use_version()
|
||||
if latest_version and latest_version != self.version:
|
||||
self.logger.info(
|
||||
f'📦 Newer version available: {latest_version} (current: {self.version}). Upgrade with: uv add browser-use@{latest_version}'
|
||||
)
|
||||
|
||||
def _log_first_step_startup(self) -> None:
|
||||
"""Log startup message only on the first step"""
|
||||
if len(self.history.history) == 0:
|
||||
@@ -1406,7 +1414,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):
|
||||
signal_handler.register()
|
||||
|
||||
try:
|
||||
self._log_agent_run()
|
||||
await self._log_agent_run()
|
||||
|
||||
self.logger.debug(
|
||||
f'🔧 Agent setup: Agent Session ID {self.session_id[-4:]}, Task ID {self.task_id[-4:]}, Browser Session ID {self.browser_session.id[-4:] if self.browser_session else "None"} {"(connecting via CDP)" if (self.browser_session and self.browser_session.cdp_url) else "(launching local browser)"}'
|
||||
|
||||
@@ -1179,8 +1179,8 @@ class DefaultActionWatchdog(BaseWatchdog):
|
||||
# Execute JavaScript to trigger comprehensive event sequence
|
||||
framework_events_script = """
|
||||
(function() {
|
||||
// Find the target element
|
||||
const element = arguments[0];
|
||||
// Find the target element (available as 'this' when using objectId)
|
||||
const element = this;
|
||||
if (!element) return false;
|
||||
|
||||
// Ensure element is focused
|
||||
@@ -1255,7 +1255,7 @@ class DefaultActionWatchdog(BaseWatchdog):
|
||||
}
|
||||
|
||||
return success;
|
||||
})(arguments[0]);
|
||||
})();
|
||||
"""
|
||||
|
||||
# Execute the framework events script
|
||||
@@ -1263,7 +1263,6 @@ class DefaultActionWatchdog(BaseWatchdog):
|
||||
params={
|
||||
'objectId': object_id,
|
||||
'functionDeclaration': framework_events_script,
|
||||
'arguments': [{'objectId': object_id}],
|
||||
'returnByValue': True,
|
||||
},
|
||||
session_id=cdp_session.session_id,
|
||||
|
||||
@@ -13,6 +13,7 @@ from sys import stderr
|
||||
from typing import Any, ParamSpec, TypeVar
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import httpx
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
@@ -578,6 +579,24 @@ def get_browser_use_version() -> str:
|
||||
return 'unknown'
|
||||
|
||||
|
||||
async def check_latest_browser_use_version() -> str | None:
|
||||
"""Check the latest version of browser-use from PyPI asynchronously.
|
||||
|
||||
Returns:
|
||||
The latest version string if successful, None if failed
|
||||
"""
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=3.0) as client:
|
||||
response = await client.get('https://pypi.org/pypi/browser-use/json')
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
return data['info']['version']
|
||||
except Exception:
|
||||
# Silently fail - we don't want to break agent startup due to network issues
|
||||
pass
|
||||
return None
|
||||
|
||||
|
||||
@cache
|
||||
def get_git_info() -> dict[str, str] | None:
|
||||
"""Get git information if installed from git repository"""
|
||||
|
||||
Reference in New Issue
Block a user