Skip to content

Automate browser based workflows with AI

[SKY-12007] Scope CDP http(s) redaction to CDP context-creation errors (#7475)

LawyZheng9a69fd9d698f
diff --git a/skyvern/exceptions.py b/skyvern/exceptions.py
index 6d6999917..b2b75756e 100644
--- a/skyvern/exceptions.py
+++ b/skyvern/exceptions.py
@@ -515,7 +515,14 @@ class UnknownErrorWhileCreatingBrowserContext(SkyvernException):
if isinstance(exception, CdpConnectionConfigurationError):
return exception.message or str(exception)
- raw_message = redact_cdp_endpoint_urls(str(exception).strip())
+ # BrowserFactory.create_browser_context wraps every creator/setup failure, so an http(s) URL
+ # here is only known to be a CDP discovery endpoint (rather than an ordinary proxy/public-IP
+ # probe URL the user needs) when the error carries a CDP-connection signal. Default to ws/wss
+ # redaction and escalate to http(s)+ws(s) redaction only for connect_over_cdp/WebSocket errors.
+ raw = str(exception).strip()
+ raw_message = (
+ redact_cdp_endpoint_urls(raw) if _is_browser_connection_error(raw) else redact_ws_endpoint_urls(raw)
+ )
raw_lower = raw_message.lower()
# Browser launch environment errors: worker cannot initialize the
diff --git a/tests/unit/test_exception_messages.py b/tests/unit/test_exception_messages.py
index d7fd5cfca..36dd900b3 100644
--- a/tests/unit/test_exception_messages.py
+++ b/tests/unit/test_exception_messages.py
@@ -105,6 +105,40 @@ def test_unknown_error_redacts_http_cdp_discovery_url() -> None:
assert "[remote browser endpoint]" in message
+def test_unknown_error_preserves_generic_http_url() -> None:
+ # A non-CDP setup failure (proxy/public-IP probe) can echo an ordinary http(s) URL the user
+ # needs to diagnose their own configuration; with no CDP signal present it must not be redacted.
+ inner_exception = Exception("Proxy health check failed: GET http://proxy.example.com:8080/status returned 503")
+ message = str(UnknownErrorWhileCreatingBrowserContext("dynamic-browser", inner_exception))
+
+ assert "http://proxy.example.com:8080/status" in message
+ assert "[remote browser endpoint]" not in message
+ assert "returned 503" in message
+
+
+def test_unknown_error_redacts_generic_ws_url() -> None:
+ # Even without a CDP signal, a ws/wss URL is unambiguously a devtools socket that may carry the
+ # vendor host or embedded credentials, so ws/wss endpoints are always redacted.
+ inner_exception = Exception("Browser setup failed talking to wss://user:[email protected]/session/tok-42")
+ message = str(UnknownErrorWhileCreatingBrowserContext("dynamic-browser", inner_exception))
+
+ assert "wss://" not in message
+ assert "tok-42" not in message
+ assert "vendor.internal" not in message
+ assert "[remote browser endpoint]" in message
+
+
+def test_unknown_error_preserves_useful_non_sensitive_prose() -> None:
+ # A generic setup failure carrying an ordinary http(s) URL should reach the user intact so the
+ # message stays actionable.
+ inner_exception = Exception("Failed to reach public IP service at https://api.ipify.org")
+ message = str(UnknownErrorWhileCreatingBrowserContext("dynamic-browser", inner_exception))
+
+ assert "https://api.ipify.org" in message # nosemgrep: incomplete-url-substring-sanitization
+ assert "Failed to reach public IP service" in message
+ assert "[remote browser endpoint]" not in message
+
+
def test_captcha_not_solved_in_time_is_captcha_solve_error() -> None:
# The action handler catches CaptchaSolveError before its generic arm; this
# subclass relationship is what routes captcha-solve failures to the handled