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
added BROWSER_USE_DISABLE_EXTENSIONS env var to disable extension
Saurav Panda556d1bc02201
diff --git a/browser_use/browser/profile.py b/browser_use/browser/profile.pyindex d2df6403f..7b506a783 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@@ -13,6 +14,16 @@ from browser_use.browser.cloud.views import CloudBrowserParamsfrom browser_use.config import CONFIGfrom browser_use.utils import _log_pretty_path, logger++def _get_enable_default_extensions_default() -> bool:+ """Get the default value for enable_default_extensions from env var or True."""+ env_val = os.getenv('BROWSER_USE_DISABLE_EXTENSIONS')+ if env_val is not None:+ # If DISABLE_EXTENSIONS is truthy, return False (extensions disabled)+ return env_val.lower() in ('0', 'false', 'no', 'off', '')+ return True++CHROME_DEBUG_PORT = 9242 # use a non-default port to avoid conflicts with other tools / devs using 9222DOMAIN_OPTIMIZATION_THRESHOLD = 100 # Convert domain lists to sets for O(1) lookup when >= this sizeCHROME_DISABLED_COMPONENTS = [@@ -588,8 +599,8 @@ class BrowserProfile(BrowserConnectArgs, BrowserLaunchPersistentContextArgs, Brodescription='Proxy settings. Use browser_use.browser.profile.ProxySettings(server, bypass, username, password)',)enable_default_extensions: bool = Field(- default=True,- description="Enable automation-optimized extensions: ad blocking (uBlock Origin), cookie handling (I still don't care about cookies), and URL cleaning (ClearURLs). All extensions work automatically without manual intervention. Extensions are automatically downloaded and loaded when enabled.",+ default_factory=_get_enable_default_extensions_default,+ description="Enable automation-optimized extensions: ad blocking (uBlock Origin), cookie handling (I still don't care about cookies), and URL cleaning (ClearURLs). All extensions work automatically without manual intervention. Extensions are automatically downloaded and loaded when enabled. Can be disabled via BROWSER_USE_DISABLE_EXTENSIONS=1 environment variable.",)demo_mode: bool = Field(default=False,diff --git a/browser_use/config.py b/browser_use/config.pyindex 9cea1e579..a951c4a39 100644--- a/browser_use/config.py+++ b/browser_use/config.py@@ -231,6 +231,9 @@ class FlatEnvConfig(BaseSettings):BROWSER_USE_PROXY_USERNAME: str | None = Field(default=None)BROWSER_USE_PROXY_PASSWORD: str | None = Field(default=None)+ # Extension env vars+ BROWSER_USE_DISABLE_EXTENSIONS: bool | None = Field(default=None)+class DBStyleEntry(BaseModel):"""Database-style entry with UUID and metadata."""@@ -487,6 +490,10 @@ class Config:if env_config.BROWSER_USE_LLM_MODEL:config['llm']['model'] = env_config.BROWSER_USE_LLM_MODEL+ # Extension settings+ if env_config.BROWSER_USE_DISABLE_EXTENSIONS is not None:+ config['browser_profile']['enable_default_extensions'] = not env_config.BROWSER_USE_DISABLE_EXTENSIONS+return configdiff --git a/tests/ci/test_extension_config.py b/tests/ci/test_extension_config.pynew file mode 100644index 000000000..0493019e6--- /dev/null+++ b/tests/ci/test_extension_config.py@@ -0,0 +1,123 @@+"""Tests for extension configuration environment variables."""++import os++import pytest+++class TestDisableExtensionsEnvVar:+ """Test BROWSER_USE_DISABLE_EXTENSIONS environment variable."""++ def test_default_value_is_true(self):+ """Without env var set, enable_default_extensions should default to True."""+ # Clear the env var if it exists+ original = os.environ.pop('BROWSER_USE_DISABLE_EXTENSIONS', None)+ try:+ # Import fresh to get the default+ from browser_use.browser.profile import _get_enable_default_extensions_default++ assert _get_enable_default_extensions_default() is True+ finally:+ if original is not None:+ os.environ['BROWSER_USE_DISABLE_EXTENSIONS'] = original++ @pytest.mark.parametrize(+ 'env_value,expected_enabled',+ [+ # Truthy values for DISABLE = extensions disabled (False)+ ('true', False),+ ('True', False),+ ('TRUE', False),+ ('1', False),+ ('yes', False),+ ('on', False),+ # Falsy values for DISABLE = extensions enabled (True)+ ('false', True),+ ('False', True),+ ('FALSE', True),+ ('0', True),+ ('no', True),+ ('off', True),+ ('', True),+ ],+ )+ def test_env_var_values(self, env_value: str, expected_enabled: bool):+ """Test various env var values are parsed correctly."""+ original = os.environ.get('BROWSER_USE_DISABLE_EXTENSIONS')+ try:+ os.environ['BROWSER_USE_DISABLE_EXTENSIONS'] = env_value+ from browser_use.browser.profile import _get_enable_default_extensions_default++ result = _get_enable_default_extensions_default()+ assert result is expected_enabled, (+ f"Expected enable_default_extensions={expected_enabled} for DISABLE_EXTENSIONS='{env_value}', got {result}"+ )+ finally:+ if original is not None:+ os.environ['BROWSER_USE_DISABLE_EXTENSIONS'] = original+ else:+ os.environ.pop('BROWSER_USE_DISABLE_EXTENSIONS', None)++ def test_browser_profile_uses_env_var(self):+ """Test that BrowserProfile picks up the env var."""+ original = os.environ.get('BROWSER_USE_DISABLE_EXTENSIONS')+ try:+ # Test with env var set to true (disable extensions)+ os.environ['BROWSER_USE_DISABLE_EXTENSIONS'] = 'true'++ from browser_use.browser.profile import BrowserProfile++ profile = BrowserProfile(headless=True)+ assert profile.enable_default_extensions is False, (+ 'BrowserProfile should disable extensions when BROWSER_USE_DISABLE_EXTENSIONS=true'+ )++ # Test with env var set to false (enable extensions)+ os.environ['BROWSER_USE_DISABLE_EXTENSIONS'] = 'false'+ profile2 = BrowserProfile(headless=True)+ assert profile2.enable_default_extensions is True, (+ 'BrowserProfile should enable extensions when BROWSER_USE_DISABLE_EXTENSIONS=false'+ )++ finally:+ if original is not None:+ os.environ['BROWSER_USE_DISABLE_EXTENSIONS'] = original+ else:+ os.environ.pop('BROWSER_USE_DISABLE_EXTENSIONS', None)++ def test_explicit_param_overrides_env_var(self):+ """Test that explicit enable_default_extensions parameter overrides env var."""+ original = os.environ.get('BROWSER_USE_DISABLE_EXTENSIONS')+ try:+ os.environ['BROWSER_USE_DISABLE_EXTENSIONS'] = 'true'++ from browser_use.browser.profile import BrowserProfile++ # Explicitly set to True should override env var+ profile = BrowserProfile(headless=True, enable_default_extensions=True)+ assert profile.enable_default_extensions is True, 'Explicit param should override env var'++ finally:+ if original is not None:+ os.environ['BROWSER_USE_DISABLE_EXTENSIONS'] = original+ else:+ os.environ.pop('BROWSER_USE_DISABLE_EXTENSIONS', None)++ def test_browser_session_uses_env_var(self):+ """Test that BrowserSession picks up the env var via BrowserProfile."""+ original = os.environ.get('BROWSER_USE_DISABLE_EXTENSIONS')+ try:+ os.environ['BROWSER_USE_DISABLE_EXTENSIONS'] = '1'++ from browser_use.browser import BrowserSession++ session = BrowserSession(headless=True)+ assert session.browser_profile.enable_default_extensions is False, (+ 'BrowserSession should disable extensions when BROWSER_USE_DISABLE_EXTENSIONS=1'+ )++ finally:+ if original is not None:+ os.environ['BROWSER_USE_DISABLE_EXTENSIONS'] = original+ else:+ os.environ.pop('BROWSER_USE_DISABLE_EXTENSIONS', None)