Skip to content

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

fix: only disable proxy for localhost CDP requests

Chase Xud96fff3816fd
diff --git a/browser_use/browser/session.py b/browser_use/browser/session.py
index be465753e..81e8e6a33 100644
--- a/browser_use/browser/session.py
+++ b/browser_use/browser/session.py
@@ -1524,9 +1524,11 @@ class BrowserSession(BaseModel):
)
# Run a tiny HTTP client to query for the WebSocket URL from the /json/version endpoint
- # Use trust_env=False to prevent proxy env vars (HTTP_PROXY, HTTPS_PROXY) from
- # routing localhost requests through a proxy, which causes 502 errors on Windows
- async with httpx.AsyncClient(trust_env=False) as client:
+ # For localhost/127.0.0.1, disable trust_env to prevent proxy env vars (HTTP_PROXY, HTTPS_PROXY)
+ # from routing local requests through a proxy, which causes 502 errors on Windows.
+ # Remote CDP URLs should still respect proxy settings.
+ is_localhost = parsed_url.hostname in ('localhost', '127.0.0.1', '::1')
+ async with httpx.AsyncClient(trust_env=not is_localhost) as client:
headers = self.browser_profile.headers or {}
version_info = await client.get(url, headers=headers)
self.logger.debug(f'Raw version info: {str(version_info)}')