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
fix/cdp_url_parsing
shubham-02173c294f7a384
diff --git a/browser_use/browser/session.py b/browser_use/browser/session.pyindex 8584a107a..0d3d1a534 100644--- a/browser_use/browser/session.py+++ b/browser_use/browser/session.py@@ -5,6 +5,7 @@ import loggingfrom functools import cached_propertyfrom pathlib import Pathfrom typing import TYPE_CHECKING, Any, Literal, Self, Union, cast, overload+from urllib.parse import urlunparsefrom uuid import UUIDimport httpx@@ -1477,11 +1478,24 @@ class BrowserSession(BaseModel):self.logger.debug(f'Error stopping old CDP client: {e}')self._cdp_client_root = None+ from urllib.parse import urlparse,urlunparse;+if not self.cdp_url.startswith('ws'):# If it's an HTTP URL, fetch the WebSocket URL from /json/version endpoint- url = self.cdp_url.rstrip('/')- if not url.endswith('/json/version'):- url = url + '/json/version'+ parsed_url = urlparse(self.cdp_url)+ path = parsed_url.path.rstrip('/')++ if not path.endswith('/json/version'):+ path = path + '/json/version'++ url = urlunparse((+ parsed_url.scheme,+ parsed_url.netloc,+ path,+ parsed_url.params,+ parsed_url.query,+ parsed_url.fragment+ ))# Run a tiny HTTP client to query for the WebSocket URL from the /json/version endpointasync with httpx.AsyncClient() as client: