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
refc: renamed cloud_browser to use_cloud
Saurav Panda0a13273fc20f
diff --git a/browser_use/browser/profile.py b/browser_use/browser/profile.pyindex 58327f1b6..daf7494e8 100644--- a/browser_use/browser/profile.py+++ b/browser_use/browser/profile.py@@ -1,3 +1,4 @@+import osimport sysimport tempfilefrom collections.abc import Iterable@@ -550,8 +551,15 @@ class BrowserProfile(BrowserConnectArgs, BrowserLaunchPersistentContextArgs, Bro# Session/connection configurationcdp_url: str | None = Field(default=None, description='CDP URL for connecting to existing browser instance')is_local: bool = Field(default=False, description='Whether this is a local browser instance')- cloud_browser: bool = Field(default=False, description='Use browser-use cloud browser service instead of local browser')- # label: str = 'default'+ use_cloud: bool = Field(+ default_factory=lambda: bool(os.getenv('BROWSER_USE_API_KEY')),+ description='Use browser-use cloud browser service instead of local browser',+ )++ @property+ def cloud_browser(self) -> bool:+ """Alias for use_cloud field for compatibility."""+ return self.use_cloud# custom options we provide that aren't native playwright kwargsdisable_security: bool = Field(default=False, description='Disable browser security features.')diff --git a/browser_use/browser/session.py b/browser_use/browser/session.pyindex b38207900..4056929f9 100644--- a/browser_use/browser/session.py+++ b/browser_use/browser/session.py@@ -253,7 +253,8 @@ class BrowserSession(BaseModel):# From BrowserNewContextArgsstorage_state: str | Path | dict[str, Any] | None = None,# BrowserProfile specific fields- cloud_browser: bool | None = None,+ use_cloud: bool | None = None,+ cloud_browser: bool | None = None, # Backward compatibility aliasdisable_security: bool | None = None,deterministic_rendering: bool | None = None,allowed_domains: list[str] | None = None,@@ -281,6 +282,10 @@ class BrowserSession(BaseModel):# Only pass non-None values to avoid validation errorsprofile_kwargs = {k: v for k, v in locals().items() if k not in ['self', 'browser_profile', 'id'] and v is not None}+ # Handle backward compatibility: map cloud_browser to use_cloud+ if 'cloud_browser' in profile_kwargs:+ profile_kwargs['use_cloud'] = profile_kwargs.pop('cloud_browser')+# if is_local is False but executable_path is provided, set is_local to Trueif is_local is False and executable_path is not None:profile_kwargs['is_local'] = True@@ -324,7 +329,7 @@ class BrowserSession(BaseModel):@propertydef cloud_browser(self) -> bool:"""Whether to use cloud browser service from browser profile."""- return self.browser_profile.cloud_browser+ return self.browser_profile.use_cloud# Main shared event bus for all browser session + all watchdogsevent_bus: EventBus = Field(default_factory=EventBus)@@ -506,7 +511,7 @@ class BrowserSession(BaseModel):try:# If no CDP URL, launch local browser or cloud browserif not self.cdp_url:- if self.browser_profile.cloud_browser:+ if self.browser_profile.use_cloud:# Use cloud browser servicetry:cloud_cdp_url = await get_cloud_browser_cdp_url()@@ -835,7 +840,7 @@ class BrowserSession(BaseModel):return# Clean up cloud browser session if using cloud browser- if self.browser_profile.cloud_browser:+ if self.browser_profile.use_cloud:try:from browser_use.browser.cloud import cleanup_cloud_clientdiff --git a/examples/browser/cloud_browser.py b/examples/browser/cloud_browser.pyindex ace05555f..15d397690 100644--- a/examples/browser/cloud_browser.py+++ b/examples/browser/cloud_browser.py@@ -25,7 +25,7 @@ async def main():agent = Agent(task='Go to https://github.com/browser-use/browser-use and find the number of stars',llm=ChatOpenAI(model='gpt-4.1-mini'),- browser=Browser(cloud_browser=True), # Enable cloud browser+ browser=Browser(use_cloud=True), # Enable cloud browser)try:diff --git a/tests/ci/test_cloud_browser.py b/tests/ci/test_cloud_browser.pyindex 23e3c2c3e..fa66d7ade 100644--- a/tests/ci/test_cloud_browser.py+++ b/tests/ci/test_cloud_browser.py@@ -229,18 +229,18 @@ class TestBrowserSessionCloudIntegration:async def test_cloud_browser_profile_property(self):"""Test that cloud_browser property works correctly."""- profile = BrowserProfile(cloud_browser=True)+ profile = BrowserProfile(use_cloud=True)session = BrowserSession(browser_profile=profile)assert session.cloud_browser is True- assert session.browser_profile.cloud_browser is True+ assert session.browser_profile.use_cloud is Trueasync def test_browser_session_cloud_browser_logic(self, mock_auth_config):"""Test that cloud browser profile settings work correctly."""# Test cloud browser profile creation- profile = BrowserProfile(cloud_browser=True)- assert profile.cloud_browser is True+ profile = BrowserProfile(use_cloud=True)+ assert profile.use_cloud is True# Test that BrowserSession respects cloud_browser settingsession = BrowserSession(browser_profile=profile)@@ -287,7 +287,7 @@ async def test_cloud_browser_auth_error_no_fallback(temp_config_dir):"""Test that cloud browser throws error when auth fails (no fallback)."""# Don't create auth config to trigger auth error- profile = BrowserProfile(cloud_browser=True)+ profile = BrowserProfile(use_cloud=True)# Test that cloud browser client raises error without fallbackwith patch('browser_use.browser.cloud.get_cloud_browser_cdp_url') as mock_cloud_cdp:@@ -300,7 +300,7 @@ async def test_cloud_browser_auth_error_no_fallback(temp_config_dir):assert 'BROWSER_USE_API_KEY environment variable' in str(exc_info.value)# Verify profile state unchanged (no fallback)- assert profile.cloud_browser is True+ assert profile.use_cloud is Trueassert profile.is_local is False