Skip to content

Automate browser based workflows with AI

fix(SKY-8931): strip Browser logs from user-facing browser launch errors (#5716)

LawyZheng6babf8a1d779
diff --git a/skyvern/exceptions.py b/skyvern/exceptions.py
index 770fd8fd5..eefcb560e 100644
--- a/skyvern/exceptions.py
+++ b/skyvern/exceptions.py
@@ -373,6 +373,8 @@ class UnknownErrorWhileCreatingBrowserContext(SkyvernException):
# Patchright timeout errors include a verbose "Call log" section with launch args.
trimmed_message = raw_message.split("Call log:")[0].strip()
+ # Browser launch errors include a "Browser logs" section with the binary path and flags.
+ trimmed_message = trimmed_message.split("Browser logs:")[0].strip()
normalized_message = " ".join(trimmed_message.split())
timeout_match = re.search(r"Timeout\s+(\d+)ms\s+exceeded", normalized_message, flags=re.IGNORECASE)
diff --git a/tests/unit/test_exception_messages.py b/tests/unit/test_exception_messages.py
index a2200f8a2..c14ca3776 100644
--- a/tests/unit/test_exception_messages.py
+++ b/tests/unit/test_exception_messages.py
@@ -109,3 +109,34 @@ def test_unknown_error_display_server_no_display() -> None:
error = UnknownErrorWhileCreatingBrowserContext("dynamic-browser", inner_exception)
message = str(error)
assert "browser display/graphics stack" in message
+
+
+def test_unknown_error_strips_browser_logs_with_internal_path() -> None:
+ """SKY-8931: Browser logs section exposes internal browser binary path."""
+ inner_exception = Exception(
+ "BrowserType.launch_persistent_context: Target page, context or browser has been closed\n\n"
+ "Browser logs:\n"
+ "<launching> /opt/internal-browser/chromium/chrome "
+ "--disable-field-trial-config --disable-background-networking"
+ )
+ error = UnknownErrorWhileCreatingBrowserContext("dynamic-browser", inner_exception)
+ message = str(error)
+ assert "/opt/internal-browser" not in message
+ assert "Browser logs:" not in message
+ assert "--disable-field-trial-config" not in message
+ assert "Target page, context or browser has been closed" in message
+ assert "[email protected]" in message
+
+
+def test_unknown_error_timeout_with_browser_logs_still_formats_structured() -> None:
+ """Timeout + Browser logs: the structured 'timed out after N seconds' path must win."""
+ inner_exception = Exception(
+ "BrowserType.launch_persistent_context: Timeout 180000ms exceeded.\n\n"
+ "Browser logs:\n"
+ "<launching> /opt/internal-browser/chromium/chrome --disable-field-trial-config"
+ )
+ error = UnknownErrorWhileCreatingBrowserContext("dynamic-browser", inner_exception)
+ message = str(error)
+ assert "timed out after 180 seconds" in message
+ assert "/opt/internal-browser" not in message
+ assert "Browser logs:" not in message