Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

make it not a hard error if no required keys are set for a model

Nick Sweeting8ba99345425d
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index da04052a4..d909e7a8c 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -191,8 +191,8 @@ class Agent(Generic[Context]):
self._set_model_names()
# LLM API connection setup
- llm_api_env_vars = REQUIRED_LLM_API_ENV_VARS[self.llm.__class__.__name__]
- if not check_env_variables(llm_api_env_vars):
+ llm_api_env_vars = REQUIRED_LLM_API_ENV_VARS.get(self.llm.__class__.__name__, [])
+ if llm_api_env_vars and not check_env_variables(llm_api_env_vars):
logger.error(f'Environment variables not set for {self.llm.__class__.__name__}')
raise ValueError('Environment variables not set')
diff --git a/browser_use/agent/views.py b/browser_use/agent/views.py
index 0b5a8f952..2253c8612 100644
--- a/browser_use/agent/views.py
+++ b/browser_use/agent/views.py
@@ -28,8 +28,8 @@ REQUIRED_LLM_API_ENV_VARS = {
'ChatBedrockConverse': ['ANTHROPIC_API_KEY'],
'ChatAnthropic': ['ANTHROPIC_API_KEY'],
'ChatGoogleGenerativeAI': ['GEMINI_API_KEY'],
- 'ChatOllama': ['OLLAMA_API_KEY'],
'ChatDeepSeek': ['DEEPSEEK_API_KEY'],
+ 'ChatOllama': [],
}
diff --git a/browser_use/controller/service.py b/browser_use/controller/service.py
index 090384c64..dc526bc36 100644
--- a/browser_use/controller/service.py
+++ b/browser_use/controller/service.py
@@ -1,10 +1,11 @@
import asyncio
+import datetime
import enum
import json
import logging
import re
from typing import Dict, Generic, Optional, Type, TypeVar
-import datetime
+
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.prompts import PromptTemplate
@@ -330,7 +331,7 @@ class Controller(Generic[Context]):
msg = f'📄 Extracted from page\n: {content}\n'
logger.info(msg)
return ActionResult(extracted_content=msg)
-
+
# HTML Download
@self.registry.action(
'Save the raw HTML content of the current page to a local file',
@@ -341,31 +342,25 @@ class Controller(Generic[Context]):
try:
page = await browser.get_current_page()
html_content = await page.content()
-
+
# Create a filename based on the page URL
short_url = re.sub(r'^https?://(?:www\.)?|/$', '', page.url)
slug = re.sub(r'[^a-zA-Z0-9]+', '-', short_url).strip('-').lower()[:64]
- timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
+ timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
sanitized_filename = f'{slug}_{timestamp}.html'
-
+
# Save HTML to file
- with open(sanitized_filename, "w", encoding="utf-8") as f:
+ with open(sanitized_filename, 'w', encoding='utf-8') as f:
f.write(html_content)
-
- msg = f"Saved HTML content of page with URL {page.url} to ./{sanitized_filename}"
-
+
+ msg = f'Saved HTML content of page with URL {page.url} to ./{sanitized_filename}'
+
logger.info(msg)
- return ActionResult(
- extracted_content=msg,
- include_in_memory=True
- )
+ return ActionResult(extracted_content=msg, include_in_memory=True)
except Exception as e:
error_msg = f'Failed to save HTML content: {str(e)}'
logger.error(error_msg)
- return ActionResult(
- error=error_msg,
- extracted_content=''
- )
+ return ActionResult(error=error_msg, extracted_content='')
@self.registry.action(
'Scroll down the page by pixel amount - if no amount is specified, scroll down one page',