Skip to content

Automate browser based workflows with AI

fix(webeye): allow raw-CDP screenshot rescue on persistent-context browsers (#8588)

LawyZheng24d08f8ad0de
diff --git a/pyproject.toml b/pyproject.toml
index 3f2a23e7e..f33e8ac5d 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
[project]
name = "skyvern"
-version = "1.0.52"
+version = "1.0.53"
description = ""
authors = [{ name = "Skyvern AI", email = "[email protected]" }]
requires-python = ">=3.11,<3.15"
diff --git a/skyvern/webeye/utils/page.py b/skyvern/webeye/utils/page.py
index a9a1995fb..bd8744814 100644
--- a/skyvern/webeye/utils/page.py
+++ b/skyvern/webeye/utils/page.py
@@ -915,8 +915,11 @@ def _cdp_rescue_eligibility(
return ScreenshotEligibility.INELIGIBLE_ENGINE
if page.context is None:
return ScreenshotEligibility.INELIGIBLE_BROWSER
+ # launch_persistent_context (the stealth-Chromium fleet) exposes no owning Browser, so
+ # context.browser is None; CDP still attaches through context.new_cdp_session. Only exclude a
+ # Browser that is present and explicitly non-Chromium.
browser = page.context.browser
- if browser is None or browser.browser_type.name != "chromium":
+ if browser is not None and browser.browser_type.name != "chromium":
return ScreenshotEligibility.INELIGIBLE_BROWSER
return ScreenshotEligibility.ELIGIBLE
diff --git a/tests/unit/webeye/test_screenshot_cdp_fallback.py b/tests/unit/webeye/test_screenshot_cdp_fallback.py
index ce18cc317..312eb2b26 100644
--- a/tests/unit/webeye/test_screenshot_cdp_fallback.py
+++ b/tests/unit/webeye/test_screenshot_cdp_fallback.py
@@ -137,13 +137,11 @@ async def test_successful_capture_keeps_playwright_arguments_and_skips_cdp(mode:
@pytest.mark.asyncio
[email protected]("kind", ["full_page", "firefox", "webkit", "unknown_browser", "skycdp"])
[email protected]("kind", ["full_page", "firefox", "webkit", "skycdp"])
async def test_ineligible_captures_keep_animation_retry_and_never_attach(kind: str) -> None:
page = _page()
if kind in {"firefox", "webkit"}:
page.context.browser.browser_type.name = kind
- elif kind == "unknown_browser":
- page.context.browser = None
selection = None
if kind == "skycdp":
selection = SimpleNamespace(
diff --git a/tests/unit/webeye/test_screenshot_cdp_first_experiment.py b/tests/unit/webeye/test_screenshot_cdp_first_experiment.py
index af869bf84..7a39e09a7 100644
--- a/tests/unit/webeye/test_screenshot_cdp_first_experiment.py
+++ b/tests/unit/webeye/test_screenshot_cdp_first_experiment.py
@@ -66,6 +66,15 @@ def _page() -> MagicMock:
return page
+def _persistent_page() -> MagicMock:
+ """Production-shaped launch_persistent_context page: a Chromium context whose owning Browser handle
+ is None (Playwright/Patchright expose none for persistent contexts), CDP still reachable through
+ context.new_cdp_session."""
+ page = _page()
+ page.context.browser = None
+ return page
+
+
def _provider(variant: Any) -> MagicMock:
provider = MagicMock()
if isinstance(variant, Exception):
@@ -788,15 +797,15 @@ async def test_detach_elapsed_is_charged_to_remaining_budget(
@pytest.mark.asyncio
@pytest.mark.parametrize(
"kind",
- ["full_page", "firefox", "unknown_browser", "skycdp"],
+ ["full_page", "firefox", "skycdp"],
)
async def test_treatment_flag_ignored_on_ineligible_path(kind: str, monkeypatch: pytest.MonkeyPatch) -> None:
provider = _use_provider(monkeypatch, "treatment")
page = _page()
if kind == "firefox":
+ # A present, non-Chromium Browser (connect_over_cdp shape) stays ineligible — the Chromium gate
+ # survives the persistent-context null-safety fix.
page.context.browser.browser_type.name = "firefox"
- elif kind == "unknown_browser":
- page.context.browser = None
selection = None
if kind == "skycdp":
selection = SimpleNamespace(
@@ -815,6 +824,40 @@ async def test_treatment_flag_ignored_on_ineligible_path(kind: str, monkeypatch:
page.context.new_cdp_session.assert_not_awaited()
+# --- persistent-context (no owning Browser) eligibility -------------------------------------------
+
+
+async def test_persistent_context_treatment_reaches_cdp(monkeypatch: pytest.MonkeyPatch) -> None:
+ """A launch_persistent_context page (context.browser is None) is raw-CDP eligible: forced treatment
+ resolves the flag and attempts raw CDP first, exactly like the connect_over_cdp path. This is the
+ production-dominant stealth-Chromium shape that the browser-None gate silently excluded."""
+ provider = _use_provider(monkeypatch, "treatment")
+ page = _persistent_page()
+ page.screenshot.side_effect = None
+ page.screenshot.return_value = b"pw-should-not-run"
+ with skyvern_context.scoped(SkyvernContext(workflow_run_id="wr_1")):
+ result = await _current_viewpoint_screenshot_helper(page)
+ assert base64.b64encode(result).decode() == _png_bytes() # raw CDP produced the bytes
+ provider.get_value_cached.assert_awaited_once() # eligible -> flag resolved
+ page.context.new_cdp_session.assert_awaited_once() # raw CDP attempted first
+ page.screenshot.assert_not_awaited() # CDP produced bytes; Playwright never ran
+
+
+async def test_persistent_context_control_uses_cdp_rescue_after_timeout(monkeypatch: pytest.MonkeyPatch) -> None:
+ """The legacy control-arm CDP rescue also applies to persistent contexts: after the Playwright
+ capture times out, the raw-CDP rescue runs through the context (no owning Browser needed) instead of
+ falling through to the animation retry."""
+ _use_provider(monkeypatch, None) # control
+ page = _persistent_page()
+ with skyvern_context.scoped(SkyvernContext(workflow_run_id="wr_1")):
+ result = await _current_viewpoint_screenshot_helper(page)
+ assert base64.b64encode(result).decode() == _png_bytes() # rescued over raw CDP
+ page.screenshot.assert_awaited_once() # Playwright first (timed out)
+ page.context.new_cdp_session.assert_awaited_once() # then CDP rescue via the context
+
+
# --- arm observability & assignment ---------------------------------------------------------------
diff --git a/tests/unit/webeye/test_screenshot_observability.py b/tests/unit/webeye/test_screenshot_observability.py
index c5f079689..35de51178 100644
--- a/tests/unit/webeye/test_screenshot_observability.py
+++ b/tests/unit/webeye/test_screenshot_observability.py
@@ -279,7 +279,6 @@ async def test_scaled_viewport_decline_emits_declined_outcome(monkeypatch: pytes
[
("full_page", "ineligible_full_page"),
("firefox", "ineligible_browser"),
- ("unknown_browser", "ineligible_browser"),
("skycdp", "ineligible_engine"),
],
)
@@ -289,8 +288,6 @@ async def test_ineligible_paths_emit_decline_reason(kind: str, reason: str, monk
page = _page()
if kind == "firefox":
page.context.browser.browser_type.name = "firefox"
- elif kind == "unknown_browser":
- page.context.browser = None
selection = None
if kind == "skycdp":
selection = SimpleNamespace(
diff --git a/uv.lock b/uv.lock
index 20f2bfa6c..cd42397cd 100644
--- a/uv.lock
+++ b/uv.lock
@@ -6840,7 +6840,7 @@ wheels = [
[[package]]
name = "skyvern"
-version = "1.0.52"
+version = "1.0.53"
source = { editable = "." }
dependencies = [
{ name = "cachetools" },