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 web_voyager_agent.py example
Ulrich Soeffinga7685d3e3000
diff --git a/browser_use/browser/context.py b/browser_use/browser/context.pyindex 16522d9c9..b6df50be2 100644--- a/browser_use/browser/context.py+++ b/browser_use/browser/context.py@@ -86,7 +86,7 @@ class BrowserContextConfig(BaseModel):wait_between_actions: 1.0Time to wait between multiple per step actions- browser_window_size: {'width': 1280, 'height': 1100}+ browser_window_size: BrowserContextWindowSizeDefault browser window sizeno_viewport: Falsediff --git a/examples/use-cases/web_voyager_agent.py b/examples/use-cases/web_voyager_agent.pyindex 723fa8b0b..4ecb11c16 100644--- a/examples/use-cases/web_voyager_agent.py+++ b/examples/use-cases/web_voyager_agent.py@@ -8,20 +8,31 @@ import syssys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))from dotenv import load_dotenv-from langchain_openai import AzureChatOpenAI+from langchain_openai import AzureChatOpenAI, ChatOpenAIfrom pydantic import SecretStrfrom browser_use.agent.service import Agentfrom browser_use.browser.browser import Browser, BrowserConfig, BrowserContextConfig+from browser_use.browser.context import BrowserContextWindowSize# Load environment variablesload_dotenv()-# Validate required environment variables-required_env_vars = ['AZURE_OPENAI_KEY', 'AZURE_OPENAI_ENDPOINT']-for var in required_env_vars:- if not os.getenv(var):- raise ValueError(f'{var} is not set. Please add it to your environment variables.')+# Set LLM based on defined environment variables and enable memory if OPENAI_API_KEY is set (otherwise Memory initialization will fail)+if os.getenv('OPENAI_API_KEY'):+ llm = ChatOpenAI(+ model='gpt-4o',+ )+elif os.getenv('AZURE_OPENAI_KEY') and os.getenv('AZURE_OPENAI_ENDPOINT'):+ llm = AzureChatOpenAI(+ model='gpt-4o',+ api_version='2024-10-21',+ azure_endpoint=os.getenv('AZURE_OPENAI_ENDPOINT', ''),+ api_key=SecretStr(os.getenv('AZURE_OPENAI_KEY', '')),+ )+else:+ raise ValueError('No LLM found. Please set OPENAI_API_KEY or AZURE_OPENAI_KEY and AZURE_OPENAI_ENDPOINT.')+browser = Browser(config=BrowserConfig(@@ -32,20 +43,11 @@ browser = Browser(minimum_wait_page_load_time=1, # 3 on prodmaximum_wait_page_load_time=10, # 20 on prod# no_viewport=True,- browser_window_size={- 'width': 1280,- 'height': 1100,- },+ browser_window_size=BrowserContextWindowSize(width=1280, height=1100),# trace_path='./tmp/web_voyager_agent',),))-llm = AzureChatOpenAI(- model='gpt-4o',- api_version='2024-10-21',- azure_endpoint=os.getenv('AZURE_OPENAI_ENDPOINT', ''),- api_key=SecretStr(os.getenv('AZURE_OPENAI_KEY', '')),-)# TASK = """# Find the lowest-priced one-way flight from Cairo to Montreal on February 21, 2025, including the total travel time and number of stops. on https://www.google.com/travel/flights/@@ -63,6 +65,7 @@ async def main():llm=llm,browser=browser,validate_output=True,+ enable_memory=False,)history = await agent.run(max_steps=50)history.save_to_file('./tmp/history.json')