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
manually fix remaining broken lines
Nick Sweeting89d48ad50f2c
diff --git a/browser_use/agent/prompts.py b/browser_use/agent/prompts.pyindex b78cfe5bc..e63b58b31 100644--- a/browser_use/agent/prompts.py+++ b/browser_use/agent/prompts.py@@ -1,4 +1,3 @@-import datetimeimport importlib.resourcesfrom datetime import datetimefrom typing import TYPE_CHECKING, List, Optional@@ -123,7 +122,7 @@ Interactive elements from top layer of the current page inside the viewport:error = result.error.split('\n')[-1]state_description += f'\nAction error {i + 1}/{len(self.result)}: ...{error}'- if self.state.screenshot and use_vision == True:+ if self.state.screenshot and use_vision is True:# Format message for vision modelreturn HumanMessage(content=[diff --git a/browser_use/agent/tests.py b/browser_use/agent/tests.pyindex 15c47357d..a0d084cc7 100644--- a/browser_use/agent/tests.py+++ b/browser_use/agent/tests.py@@ -147,7 +147,7 @@ def test_final_result(sample_history: AgentHistoryList):def test_is_done(sample_history: AgentHistoryList):- assert sample_history.is_done() == True+ assert sample_history.is_done() is Truedef test_urls(sample_history: AgentHistoryList):@@ -182,7 +182,7 @@ def test_empty_history():empty_history = AgentHistoryList(history=[])assert empty_history.last_action() is Noneassert empty_history.final_result() is None- assert empty_history.is_done() == False+ assert empty_history.is_done() is Falseassert len(empty_history.urls()) == 0diff --git a/browser_use/browser/dolphin_service.py b/browser_use/browser/dolphin_service.pyindex 971f09ae9..0e033a46d 100644--- a/browser_use/browser/dolphin_service.py+++ b/browser_use/browser/dolphin_service.py@@ -297,7 +297,7 @@ class DolphinBrowser(Browser):for page in self._pages:try:await page.close()- except:+ except BaseException:passself._pages = []diff --git a/browser_use/dom/tests/extraction_test.py b/browser_use/dom/tests/extraction_test.pyindex 8c3c605f7..4a5dda168 100644--- a/browser_use/dom/tests/extraction_test.py+++ b/browser_use/dom/tests/extraction_test.py@@ -1,12 +1,20 @@import asyncioimport time+from langchain_openai import ChatOpenAI+from browser_use.browser.browser import Browser, BrowserConfigfrom browser_use.browser.context import BrowserContext, BrowserContextConfigfrom browser_use.dom.service import DomServicefrom browser_use.utils import time_execution_sync+def count_string_tokens(string: str, model: str) -> int:+ """Count the number of tokens in a string using a specified model."""+ llm = ChatOpenAI(model=model)+ return llm.count_tokens(string)++async def test_process_html_file():config = BrowserContextConfig(cookies_file='cookies3.json',diff --git a/browser_use/logging_config.py b/browser_use/logging_config.pyindex 043252bd7..887fe7e7f 100644--- a/browser_use/logging_config.py+++ b/browser_use/logging_config.py@@ -77,7 +77,7 @@ def setup_logging():class BrowserUseFormatter(logging.Formatter):def format(self, record):- if type(record.name) == str and record.name.startswith('browser_use.'):+ if isinstance(record.name, str) and record.name.startswith('browser_use.'):record.name = record.name.split('.')[-2]return super().format(record)diff --git a/tests/test_service.py b/tests/test_service.pyindex 340085bff..f50f022ca 100644--- a/tests/test_service.py+++ b/tests/test_service.py@@ -122,7 +122,7 @@ class TestAgent:assert len(agent._last_result) == 1assert isinstance(agent._last_result[0], ActionResult)assert 'Test error' in agent._last_result[0].error- assert agent._last_result[0].include_in_memory == True+ assert agent._last_result[0].include_in_memory is Trueclass TestRegistry: