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
tweak version number check to use pyproject.toml
Nick Sweeting2eb0c11b8658
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.pyindex 9bf016747..17aa9087c 100644--- a/browser_use/agent/service.py+++ b/browser_use/agent/service.py@@ -393,30 +393,43 @@ class Agent(Generic[Context]):return self.settings.message_contextdef _set_browser_use_version_and_source(self, source_override: str | None = None) -> None:- """Get the version and source of the browser-use package (git or pip in a nutshell)"""+ """Get the version from pyproject.toml and determine the source of the browser-use package"""try:- # First check for repository-specific files- repo_files = ['.git', 'README.md', 'docs', 'examples']package_root = Path(__file__).parent.parent.parent+ pyproject_path = package_root / 'pyproject.toml'- # If all of these files/dirs exist, it's likely from git- if all(Path(package_root / file).exists() for file in repo_files):- try:- import subprocess+ # Try to read version from pyproject.toml+ if pyproject_path.exists():+ import re- version = subprocess.check_output(['git', 'describe', '--tags']).decode('utf-8').strip()- except Exception:- version = 'unknown'- source = 'git'+ with open(pyproject_path) as f:+ content = f.read()+ match = re.search(r'version\s*=\s*["\']([^"\']+)["\']', content)+ if match:+ version = f'v{match.group(1)}'+ else:+ # Fallback to importlib if regex doesn't find version+ from importlib.metadata import version as get_version++ version = f'v{get_version("browser-use")}'else:- # If no repo files found, try getting version from pip- from importlib.metadata import version+ # If pyproject.toml doesn't exist, try getting version from pip+ from importlib.metadata import version as get_version++ version = f'v{get_version("browser-use")}'- version = version('browser-use')+ # Determine source+ repo_files = ['.git', 'README.md', 'docs', 'examples']+ if all(Path(package_root / file).exists() for file in repo_files):+ source = 'git'+ else:source = 'pip'- except Exception:- version = 'unknown'++ except Exception as e:+ logger.debug(f'Error getting version: {e}')+ version = 'vunknown'source = 'unknown'+if source_override is not None:source = source_overridelogger.debug(f'Version: {version}, Source: {source}')