Skip to content

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

refactor(tools): tighten evaluate() guard comment

Saurav Pandae5f9b46f95f1
diff --git a/browser_use/tools/service.py b/browser_use/tools/service.py
index 8e2cd965f..be34451a1 100644
--- a/browser_use/tools/service.py
+++ b/browser_use/tools/service.py
@@ -1775,23 +1775,15 @@ You will be given a query and the markdown of a webpage that has been filtered t
terminates_sequence=True,
)
async def evaluate(code: str, browser_session: BrowserSession):
- # Refuse on restricted profiles. SecurityWatchdog only hooks navigation,
- # so evaluate() would otherwise let the agent fetch() internal URLs or
- # read cookies/localStorage from any allowed origin's context, nullifying
- # the configured restrictions entirely.
+ # SecurityWatchdog only hooks navigation, so evaluate() would bypass
+ # profile restrictions via fetch() / direct origin access.
profile = browser_session.browser_profile
if profile.allowed_domains or profile.prohibited_domains or profile.block_ip_addresses:
return ActionResult(
- error=(
- 'evaluate() is disabled when allowed_domains, prohibited_domains, or '
- 'block_ip_addresses is set — this profile is configured as restricted, '
- 'and evaluate() would let an agent bypass those restrictions via fetch() '
- 'and direct origin access. Run on an unrestricted profile if you need '
- 'JS evaluation.'
- )
+ error='evaluate() is disabled on profiles configured with allowed_domains, '
+ 'prohibited_domains, or block_ip_addresses.'
)
- # Execute JavaScript with proper error handling and promise support
cdp_session = await browser_session.get_or_create_cdp_session()
try: