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
add ruff dependency
Nick Sweetinge6900d128771
diff --git a/browser_use/browser/browser.py b/browser_use/browser/browser.pyindex d1c1cb1b7..4bfc02572 100644--- a/browser_use/browser/browser.py+++ b/browser_use/browser/browser.py@@ -7,7 +7,7 @@ import gcimport loggingimport osimport subprocess-from typing import Any, Literal+from typing import Literalimport requestsfrom playwright.async_api import Browser as PlaywrightBrowser@@ -15,7 +15,7 @@ from playwright.async_api import (Playwright,async_playwright,)-from pydantic import BaseModel, ConfigDict, Field, field_validator+from pydantic import AliasChoices, BaseModel, ConfigDict, Fieldfrom typing_extensions import TypedDictfrom browser_use.browser.chrome import (@@ -79,37 +79,17 @@ class BrowserConfig(BaseModel):cdp_url: str | None = Nonebrowser_class: Literal['chromium', 'firefox', 'webkit'] = 'chromium'- browser_binary_path: str | None = None- browser_instance_path: str | None = Field(None, deprecated=True) # Old name for browser_binary_path- chrome_instance_path: str | None = Field(None, deprecated=True) # Old name for browser_binary_path+ browser_binary_path: str | None = Field(default=None, alias=AliasChoices('browser_instance_path', 'chrome_instance_path'))extra_browser_args: list[str] = Field(default_factory=list)headless: bool = Falsedisable_security: bool = Falsedeterministic_rendering: bool = False- keep_alive: bool = False # used to be called _force_keep_browser_alive+ keep_alive: bool = Field(default=False, alias='_force_keep_browser_alive') # used to be called _force_keep_browser_aliveproxy: ProxySettings | None = Nonenew_context_config: BrowserContextConfig = Field(default_factory=BrowserContextConfig)- @field_validator('browser_binary_path', mode='before')- def handle_browser_instance_path(cls, v: Any, info: Any) -> Any:- # If browser_binary_path is None but browser_instance_path is set, use that value- if v is None and ('browser_instance_path' in info.data or 'chrome_instance_path' in info.data):- return info.data.get('browser_instance_path', info.data.get('chrome_instance_path'))-- assert info.data.get('browser_class') == 'chromium', (- 'browser_binary_path only supports chromium-based browsers (make sure browser_class=chromium)'- )- return v-- @field_validator('keep_alive', mode='before')- def handle_force_keep_browser_alive(cls, v: Any, info: Any) -> Any:- # If keep_alive is False but _force_keep_browser_alive is set, use that value- if v is False and '_force_keep_browser_alive' in info.data:- return info.data.get('_force_keep_browser_alive')- return v-# @singleton: TODO - think about id singleton makes sense here# @dev By default this is a singleton, but you can create multiple instances if you need to.diff --git a/browser_use/browser/context.py b/browser_use/browser/context.pyindex 733c85abe..6c2495982 100644--- a/browser_use/browser/context.py+++ b/browser_use/browser/context.py@@ -152,7 +152,7 @@ class BrowserContextConfig(BaseModel):allowed_domains: list[str] | None = Noneinclude_dynamic_attributes: bool = True- keep_alive: bool = False # used to be called _force_keep_context_alive+ keep_alive: bool = Field(default=False, alias='_force_keep_context_alive') # used to be called _force_keep_context_aliveis_mobile: bool | None = Nonehas_touch: bool | None = Nonegeolocation: dict | None = Nonediff --git a/examples/features/follow_up_tasks.py b/examples/features/follow_up_tasks.pyindex bfd299090..1dcf9c92c 100644--- a/examples/features/follow_up_tasks.py+++ b/examples/features/follow_up_tasks.py@@ -17,7 +17,7 @@ browser = Browser(config=BrowserConfig(browser_binary_path='/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',new_context_config=BrowserContextConfig(- _force_keep_context_alive=True,+ keep_alive=True,),),)diff --git a/pyproject.toml b/pyproject.tomlindex b64a16395..c87cb96f3 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -24,17 +24,20 @@ dependencies = ["langchain-ollama==0.2.2","google-api-core>=2.24.0","pyperclip>=1.9.0",- # only used for examples that use copy/paste"pyobjc>=11.0; platform_system == 'darwin'",- # only used to get screen resolution on macOS"screeninfo>=0.8.1; platform_system != 'darwin'","typing-extensions>=4.12.2",- # only used to get screen resolution on Linux/Windows]+# google-api-core: only used for Google LLM APIs+# pyperclip: only used for examples that use copy/paste+# pyobjc: only used to get screen resolution on macOS+# screeninfo: only used to get screen resolution on Linux/Windows+# markdownify: used for page text content extraction for passing to LLMurls = { "Repository" = "https://github.com/browser-use/browser-use" }[project.optional-dependencies]dev = [+ "ruff>=0.11.2","tokencost>=0.1.16","build>=1.2.2","pytest>=8.3.3",@@ -71,3 +74,8 @@ include = ["browser_use/dom/buildDomTree.js",]+[tool.uv]+dev-dependencies = [+ "ruff>=0.11.2",+]+