Skip to content

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

lint

mertunsalle00ad12c4081
diff --git a/browser_use/tools/registry/service.py b/browser_use/tools/registry/service.py
index d57edf46c..846d2e239 100644
--- a/browser_use/tools/registry/service.py
+++ b/browser_use/tools/registry/service.py
@@ -40,14 +40,14 @@ class Registry(Generic[Context]):
def exclude_action(self, action_name: str) -> None:
"""Exclude an action from the registry after initialization.
-
+
If the action is already registered, it will be removed from the registry.
The action is also added to the exclude_actions list to prevent re-registration.
"""
# Add to exclude list to prevent future registration
if action_name not in self.exclude_actions:
self.exclude_actions.append(action_name)
-
+
# Remove from registry if already registered
if action_name in self.registry.actions:
del self.registry.actions[action_name]
diff --git a/browser_use/tools/service.py b/browser_use/tools/service.py
index 213672f4c..1a3e4b18f 100644
--- a/browser_use/tools/service.py
+++ b/browser_use/tools/service.py
@@ -1346,10 +1346,10 @@ Validated Code (after quote fixing):
def exclude_action(self, action_name: str) -> None:
"""Exclude an action from the tools registry.
-
+
This method can be used to remove actions after initialization,
useful for enforcing constraints like disabling screenshot when use_vision != 'auto'.
-
+
Args:
action_name: Name of the action to exclude (e.g., 'screenshot')
"""
diff --git a/tests/ci/test_screenshot_exclusion.py b/tests/ci/test_screenshot_exclusion.py
index 683dc53fd..98782c651 100644
--- a/tests/ci/test_screenshot_exclusion.py
+++ b/tests/ci/test_screenshot_exclusion.py
@@ -61,7 +61,7 @@ def test_screenshot_included_with_use_vision_auto():
def test_screenshot_excluded_with_custom_tools_and_use_vision_false():
"""Test that screenshot action is excluded even when user passes custom tools and use_vision=False.
-
+
This is the critical test case that verifies the fix:
When users pass their own Tools instance with screenshot included,
the Agent should still enforce the exclusion if use_vision != 'auto'.
@@ -81,14 +81,14 @@ def test_screenshot_excluded_with_custom_tools_and_use_vision_false():
)
# Verify screenshot is excluded even though user passed custom tools
- assert (
- 'screenshot' not in agent.tools.registry.registry.actions
- ), 'Screenshot should be excluded when use_vision=False, even with custom tools'
+ assert 'screenshot' not in agent.tools.registry.registry.actions, (
+ 'Screenshot should be excluded when use_vision=False, even with custom tools'
+ )
def test_screenshot_excluded_with_custom_tools_and_use_vision_true():
"""Test that screenshot action is excluded even when user passes custom tools and use_vision=True.
-
+
This is another critical test case:
When users pass their own Tools instance with screenshot included,
the Agent should still enforce the exclusion if use_vision != 'auto'.
@@ -113,9 +113,9 @@ def test_screenshot_excluded_with_custom_tools_and_use_vision_true():
# Verify screenshot is excluded even though user passed custom tools
# The key test: screenshot should be excluded after Agent init
- assert (
- 'screenshot' not in agent.tools.registry.registry.actions
- ), f'Screenshot should be excluded when use_vision=True, even with custom tools (had screenshot before: {has_screenshot_before})'
+ assert 'screenshot' not in agent.tools.registry.registry.actions, (
+ f'Screenshot should be excluded when use_vision=True, even with custom tools (had screenshot before: {has_screenshot_before})'
+ )
def test_screenshot_included_with_custom_tools_and_use_vision_auto():
@@ -135,9 +135,9 @@ def test_screenshot_included_with_custom_tools_and_use_vision_auto():
)
# Verify screenshot is kept when use_vision='auto'
- assert (
- 'screenshot' in agent.tools.registry.registry.actions
- ), 'Screenshot should be included when use_vision="auto", even with custom tools'
+ assert 'screenshot' in agent.tools.registry.registry.actions, (
+ 'Screenshot should be included when use_vision="auto", even with custom tools'
+ )
def test_tools_exclude_action_method():