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
fix: redirect logging to stderr so MCP stdio doesn't break (#2748)
Laith Weinberger4d05218d7d5c
diff --git a/browser_use/cli.py b/browser_use/cli.pyindex 7ad1e88fd..5b32f1779 100644--- a/browser_use/cli.py+++ b/browser_use/cli.py@@ -169,7 +169,9 @@ try:from textual.containers import Container, HorizontalGroup, VerticalScrollfrom textual.widgets import Footer, Header, Input, Label, Link, RichLog, Staticexcept ImportError:- print('⚠️ CLI addon is not installed. Please install it with: `pip install "browser-use[cli]"` and try again.')+ print(+ '⚠️ CLI addon is not installed. Please install it with: `pip install "browser-use[cli]"` and try again.', file=sys.stderr+ )sys.exit(1)diff --git a/browser_use/logging_config.py b/browser_use/logging_config.pyindex 863ce6f17..950d0479f 100644--- a/browser_use/logging_config.py+++ b/browser_use/logging_config.py@@ -112,7 +112,7 @@ def setup_logging(stream=None, log_level=None, force_setup=False, debug_log_filereturn super().format(record)# Setup single handler for all loggers- console = logging.StreamHandler(stream or sys.stdout)+ console = logging.StreamHandler(stream or sys.stderr)# Determine the log level to use firstif log_type == 'result':@@ -184,7 +184,7 @@ def setup_logging(stream=None, log_level=None, force_setup=False, debug_log_file# Use the CDP-specific logging levelsetup_cdp_logging(level=cdp_level,- stream=stream or sys.stdout,+ stream=stream or sys.stderr,format_string='%(levelname)-8s [%(name)s] %(message)s' if log_type != 'result' else '%(message)s',)except ImportError:diff --git a/browser_use/mcp/server.py b/browser_use/mcp/server.pyindex f76669376..680a65584 100644--- a/browser_use/mcp/server.py+++ b/browser_use/mcp/server.py@@ -26,12 +26,12 @@ Or as an MCP server in Claude Desktop or other MCP clients:import osimport sys-from browser_use.llm import ChatAWSBedrock-# Set environment variables BEFORE any browser_use imports to prevent early loggingos.environ['BROWSER_USE_LOGGING_LEVEL'] = 'critical'os.environ['BROWSER_USE_SETUP_LOGGING'] = 'false'+from browser_use.llm import ChatAWSBedrock+import asyncioimport jsonimport logging