Skip to content

Automate browser based workflows with AI

feat(SKY-11953): observe omits input values by default; passwords never emitted (#7285)

Marc Kelechavaf25f0b97a634
diff --git a/skyvern/cli/core/browser_ops.py b/skyvern/cli/core/browser_ops.py
index a0dbdb9d3..313b13b76 100644
--- a/skyvern/cli/core/browser_ops.py
+++ b/skyvern/cli/core/browser_ops.py
@@ -560,16 +560,11 @@ _ROLE_TO_TAG: dict[str, str] = {
"treeitem": "li",
}
-_PASSWORD_NAME_RE = re.compile(
- r"\bpass(?:word|phrase|code)s?\b|\bsecret\b|\btoken\b|\bcredential\b|\bpwd\b|\bpasswd\b|\bpin\b",
- re.IGNORECASE,
-)
-
# Structural fields always kept in serialized output; display fields filtered if empty.
_ELEMENT_KEEP_ALWAYS = frozenset({"ref", "role"})
_OBSERVE_INTERACTABLES_JS = r"""
-(scopeSelector) => {
+({ scopeSelector, includeValues }) => {
const root = scopeSelector ? document.querySelector(scopeSelector) : document.body;
if (!root) return [];
@@ -604,6 +599,8 @@ _OBSERVE_INTERACTABLES_JS = r"""
.trim();
if (labelsText) return labelsText;
}
+ // Deliberate: unlabeled non-password inputs may surface their value as the accessible
+ // name (identification fallback), independent of includeValues; passwords never do.
return (element.innerText || element.textContent || element.getAttribute("placeholder") || (isPassword(element) ? "" : element.value) || "")
.replace(/\s+/g, " ")
.trim();
@@ -681,15 +678,13 @@ _OBSERVE_INTERACTABLES_JS = r"""
return Boolean(nativeRole(element) || widgetRoles.has(explicitRole(element)) || staticClick(element) || frameworkClick(element) || knownClass(element) || pointer(element) || (tag === "div" && element.getAttribute("tabindex") === "0") || optionLike(element));
};
- return Array.from(root.querySelectorAll("*"))
+ // querySelectorAll excludes the root itself — a scoped observe must still surface the scoped element.
+ return (scopeSelector ? [root, ...root.querySelectorAll("*")] : Array.from(root.querySelectorAll("*")))
.filter(candidate)
.map((element) => {
const tag = element.tagName.toLowerCase();
const item = { role: roleFor(element), name: text(element), tag, selector: cssPath(element) };
- if (isPassword(element)) {
- item.value = "";
- item.is_password = true;
- } else if (["input", "textarea", "select", "option"].includes(tag)) {
+ if (includeValues === true && !isPassword(element) && ["input", "textarea", "select", "option"].includes(tag)) {
item.value = element.value || element.getAttribute("value") || "";
}
if (tag === "select") item.options = Array.from(element.options).map((option) => text(option));
@@ -859,19 +854,15 @@ def _flatten_a11y_tree(node: dict[str, Any] | None) -> list[dict[str, Any]]:
return []
result: list[dict[str, Any]] = []
if node.get("role") and node["role"] != "WebArea":
+ # a11y snapshots carry current input values; drop them at capture so the guarded
+ # DOM scan (includeValues gate in _OBSERVE_INTERACTABLES_JS) is the only value source.
+ node.pop("value", None)
result.append(node)
for child in node.get("children", []):
result.extend(_flatten_a11y_tree(child))
return result
-def _is_password_field(role: str, name: str) -> bool:
- """DESIGN-2: Detect password-type fields for value redaction."""
- if _PASSWORD_NAME_RE.search(name):
- return True
- return role == "textbox" and "password" in name.lower()
-
-
def _extract_options(node: dict[str, Any]) -> list[str] | None:
"""Extract option labels from combobox/listbox children."""
children = node.get("children")
@@ -881,12 +872,19 @@ def _extract_options(node: dict[str, Any]) -> list[str] | None:
return opts if opts else None
-async def _get_dom_observe_elements(page: Any, selector: str | None = None) -> list[dict[str, Any]]:
+async def _get_dom_observe_elements(
+ page: Any,
+ selector: str | None = None,
+ include_values: bool = False,
+) -> list[dict[str, Any]]:
evaluate = getattr(page, "evaluate", None)
if evaluate is None:
return []
try:
- result = await evaluate(_OBSERVE_INTERACTABLES_JS, selector)
+ result = await evaluate(
+ _OBSERVE_INTERACTABLES_JS,
+ {"scopeSelector": selector, "includeValues": include_values},
+ )
except Exception:
return []
if not isinstance(result, list):
@@ -935,10 +933,8 @@ def _merge_dom_observe_elements(
and _ROLE_TO_TAG.get(existing.get("role", ""), "") == dom_element.get("tag", "")
):
existing["selector"] = dom_selector
- if dom_element.get("value") is not None and existing.get("value") is None:
- existing["value"] = dom_element.get("value")
- if dom_element.get("is_password"):
- existing["is_password"] = True
+ if dom_element.get("value") is not None:
+ existing["value"] = dom_element["value"]
if dom_element.get("options") and not existing.get("children"):
existing["options"] = dom_element.get("options")
matched_existing = True
@@ -950,31 +946,6 @@ def _merge_dom_observe_elements(
if dom_selector:
selector_seen.add(dom_selector)
- # Any accessible name the DOM identifies as a password field redacts EVERY element
- # sharing that (role, name, tag) key — a duplicate accessible name must not let an
- # unflagged a11y value slip through.
- password_keys = {
- _key(dom_element.get("role", ""), dom_element.get("name", ""), dom_element.get("tag", ""))
- for dom_element in dom_elements
- if dom_element.get("is_password")
- }
- if password_keys:
- # Keys present among the ORIGINAL a11y elements (NOT the appended DOM elements — an
- # appended DOM password would otherwise "match" itself and defeat the fail-closed check).
- a11y_password_keys = {
- _key(e.get("role", ""), e.get("name", ""), _ROLE_TO_TAG.get(e.get("role", ""), "")) for e in a11y_elements
- }
- for element in merged:
- role = element.get("role", "")
- if _key(role, element.get("name", ""), _ROLE_TO_TAG.get(role, "")) in password_keys:
- element["is_password"] = True
- if password_keys - a11y_password_keys:
- # Fail closed: a DOM password field could not be mapped to any original a11y element
- # (unlabeled or divergent accessible name). Redact every a11y textbox value so a
- # password can never leak through an unmatched pairing.
- for element in merged:
- if element.get("role") == "textbox" and element.get("value"):
- element["is_password"] = True
return merged
@@ -983,8 +954,12 @@ async def do_observe(
selector: str | None = None,
interactive_only: bool = True,
max_elements: int = 50,
+ include_values: bool = False,
) -> ObserveResult:
"""Capture interactive elements with stable refs for batch operations."""
+ # Execute-step params arrive as untyped JSON; a string like "false" must not
+ # enable value capture — the opt-in counts only as a literal boolean True.
+ include_values = include_values is True
accessibility = getattr(page, "accessibility", None)
if selector and accessibility is not None:
element_handle = await page.locator(selector).first.element_handle()
@@ -995,7 +970,7 @@ async def do_observe(
snapshot = None
all_elements = _flatten_a11y_tree(snapshot)
- dom_elements = await _get_dom_observe_elements(page, selector)
+ dom_elements = await _get_dom_observe_elements(page, selector, include_values)
if interactive_only:
all_elements = [e for e in all_elements if e.get("role") in INTERACTIVE_ROLES]
@@ -1030,11 +1005,6 @@ async def do_observe(
for i, elem in enumerate(capped):
role = elem.get("role", "")
name = elem.get("name", "")
- value = elem.get("value")
-
- # DESIGN-2: Redact password field values — by DOM input type (is_password) or name.
- if elem.get("is_password") or (value and _is_password_field(role, name)):
- value = "***"
key = (role, name)
match_index = elem.get("_match_index", 0)
@@ -1046,7 +1016,7 @@ async def do_observe(
name=name,
tag=elem.get("tag") or _ROLE_TO_TAG.get(role, ""),
selector=elem.get("selector"),
- value=value,
+ value=elem.get("value"),
options=elem.get("options") or _extract_options(elem),
match_index=match_index,
needs_disambiguation=full_group_size[key] > 1,
@@ -1081,6 +1051,11 @@ def serialize_elements(elements: list[ObservedElement]) -> list[dict[str, Any]]:
return result
+def ref_map_from_elements(elements: list[dict[str, Any]]) -> dict[str, dict[str, Any]]:
+ """Ref-map/registry entries persist across calls — they hold ref-resolution fields, never input values."""
+ return {element["ref"]: {k: v for k, v in element.items() if k != "value"} for element in elements}
+
+
def ref_to_selector(elem: dict[str, Any]) -> str:
"""Convert an observed element's a11y data to a Playwright role selector."""
if selector := elem.get("selector"):
@@ -1193,7 +1168,7 @@ async def do_execute(
# If session publication rejects the snapshot (a concurrent navigation
# invalidated it), the batch must not act on it either.
if step.tool == "observe" and result and "elements" in result:
- new_map = {elem["ref"]: elem for elem in result["elements"]}
+ new_map = ref_map_from_elements(result["elements"])
if on_ref_map_update is None or on_ref_map_update(new_map):
ref_map = new_map
else:
diff --git a/skyvern/cli/mcp_tools/browser.py b/skyvern/cli/mcp_tools/browser.py
index a3ddca2f8..718eef6c3 100644
--- a/skyvern/cli/mcp_tools/browser.py
+++ b/skyvern/cli/mcp_tools/browser.py
@@ -27,6 +27,7 @@ from skyvern.cli.core.browser_ops import (
do_observe,
do_screenshot,
parse_extract_schema,
+ ref_map_from_elements,
ref_to_selector,
select_native_option_if_targeted,
serialize_elements,
@@ -2256,8 +2257,15 @@ async def skyvern_observe(
int,
Field(description="Max elements to return. Default 50.", ge=1, le=200),
] = 50,
+ include_values: Annotated[
+ bool,
+ Field(
+ description="Include current values for non-password inputs. "
+ "Password values are never returned. Default false."
+ ),
+ ] = False,
) -> dict[str, Any]:
- """Snapshot interactive elements with refs reusable in this browser session until the next observe or page/document context change (rarely earlier — on 'Unknown ref', re-observe)."""
+ """Snapshot interactive elements with refs reusable in this browser session until the next observe or page/document context change (rarely earlier — on 'Unknown ref', re-observe). Input values are omitted by default; set include_values=True to return non-password values. Password values are never returned."""
try:
page, ctx = await get_page(session_id=session_id, cdp_url=cdp_url)
except BrowserNotAvailableError:
@@ -2273,6 +2281,7 @@ async def skyvern_observe(
selector=selector,
interactive_only=interactive_only,
max_elements=max_elements,
+ include_values=include_values,
)
timer.mark("sdk")
except Exception as e:
@@ -2286,7 +2295,7 @@ async def skyvern_observe(
elements = serialize_elements(result.elements)
replace_session_ref_map(
- {element["ref"]: element for element in elements},
+ ref_map_from_elements(elements),
session_id=ctx.session_id,
cdp_url=ctx.cdp_url,
generation=generation,
@@ -2299,7 +2308,8 @@ async def skyvern_observe(
'{tool: "click", params: {ref: "e0"}}. '
"Refs remain valid across calls in this browser session until the next skyvern_observe, "
"skyvern_navigate, same-tab navigation, or tab/frame switch. Same-document DOM changes can also "
- "invalidate ordinal refs; re-observe on 'Unknown ref' or unexpected failures."
+ "invalidate ordinal refs; re-observe on 'Unknown ref' or unexpected failures. "
+ "Input values are omitted unless include_values=true; password values are never returned."
)
return make_result(
"skyvern_observe",
@@ -2381,7 +2391,7 @@ async def _dispatch_step(
page, _ = await get_page(session_id=session_id, cdp_url=cdp_url)
if on_observe_page is not None:
on_observe_page(page_ref_key(page))
- accepted = {"selector", "interactive_only", "max_elements"}
+ accepted = {"selector", "interactive_only", "max_elements", "include_values"}
filtered = {k: v for k, v in params.items() if k in accepted}
result = await _do_observe(page, **filtered)
return {
diff --git a/tests/unit/test_mcp_observe_execute.py b/tests/unit/test_mcp_observe_execute.py
index bac855b89..10d1c5f0e 100644
--- a/tests/unit/test_mcp_observe_execute.py
+++ b/tests/unit/test_mcp_observe_execute.py
@@ -11,10 +11,10 @@ import pytest
from skyvern.cli.core import session_manager
from skyvern.cli.core.browser_ops import (
+ _OBSERVE_INTERACTABLES_JS,
ExecuteStep,
ObserveResult,
_flatten_a11y_tree,
- _is_password_field,
do_execute,
do_observe,
ref_to_selector,
@@ -62,6 +62,35 @@ def _make_page(a11y_tree: dict[str, Any] | None = None) -> AsyncMock:
return page
+def _make_values_page() -> AsyncMock:
+ """Page with a non-password input (DOM value present) and a password input (DOM value absent)."""
+ tree = _make_a11y_tree(
+ children=[
+ {"role": "textbox", "name": "Email", "value": "[email protected]"},
+ {"role": "textbox", "name": "Current", "value": "snapshot-secret"},
+ ]
+ )
+ page = _make_page(tree)
+ page.evaluate = AsyncMock(
+ return_value=[
+ {
+ "role": "textbox",
+ "name": "Email",
+ "tag": "input",
+ "selector": "#email",
+ "value": "[email protected]",
+ },
+ {
+ "role": "textbox",
+ "name": "Current",
+ "tag": "input",
+ "selector": "#password",
+ },
+ ]
+ )
+ return page
+
+
# ---------------------------------------------------------------------------
# Unit tests: _flatten_a11y_tree
# ---------------------------------------------------------------------------
@@ -102,32 +131,6 @@ class TestFlattenA11yTree:
assert flat[0]["name"] == "Click me"
-# ---------------------------------------------------------------------------
-# Unit tests: _is_password_field
-# ---------------------------------------------------------------------------
-
-
-class TestIsPasswordField:
- def test_password_name(self) -> None:
- assert _is_password_field("textbox", "Password") is True
-
- def test_passphrase_name(self) -> None:
- assert _is_password_field("textbox", "Enter your passphrase") is True
-
- def test_secret_name(self) -> None:
- assert _is_password_field("textbox", "API Secret") is True
-
- def test_token_name(self) -> None:
- assert _is_password_field("textbox", "Auth Token") is True
-
- def test_non_password(self) -> None:
- assert _is_password_field("textbox", "Email") is False
-
- def test_button_with_password_name(self) -> None:
- # buttons named "password" still match the regex
- assert _is_password_field("button", "Show Password") is True
-
-
# ---------------------------------------------------------------------------
# Unit tests: ref_to_selector
# ---------------------------------------------------------------------------
@@ -187,19 +190,33 @@ class TestDoObserve:
assert refs == ["e0", "e1", "e2", "e3"]
@pytest.mark.asyncio
- async def test_password_redaction(self) -> None:
- """DESIGN-2: Password field values must be redacted."""
+ async def test_default_omits_values(self) -> None:
page = _make_page()
- result = await do_observe(page)
- password_elem = next(e for e in result.elements if e.name == "Password")
- assert password_elem.value == "***"
+ observed = serialize_elements((await do_observe(page)).elements)
+
+ assert all("value" not in element for element in observed)
@pytest.mark.asyncio
- async def test_non_password_value_preserved(self) -> None:
- page = _make_page()
- result = await do_observe(page)
- email_elem = next(e for e in result.elements if e.name == "Email")
- assert email_elem.value == ""
+ async def test_include_values_keeps_non_password_dom_value_only(self) -> None:
+ page = _make_values_page()
+
+ observed = serialize_elements((await do_observe(page, include_values=True)).elements)
+
+ email = next(element for element in observed if element["name"] == "Email")
+ password = next(element for element in observed if element["name"] == "Current")
+ assert email["value"] == "[email protected]"
+ assert "value" not in password
+
+ @pytest.mark.asyncio
+ async def test_non_boolean_include_values_fails_closed(self) -> None:
+ page = _make_values_page()
+
+ await do_observe(page, include_values="false") # type: ignore[arg-type]
+
+ page.evaluate.assert_awaited_once_with(
+ _OBSERVE_INTERACTABLES_JS,
+ {"scopeSelector": None, "includeValues": False},
+ )
@pytest.mark.asyncio
async def test_max_elements_cap(self) -> None:
@@ -253,7 +270,9 @@ class TestDoObserve:
)
page = _make_page(tree)
result = await do_observe(page)
- assert result.elements[0].options == ["US", "UK", "CA"]
+ country = serialize_elements(result.elements)[0]
+ assert country["options"] == ["US", "UK", "CA"]
+ assert "value" not in country
@pytest.mark.asyncio
async def test_dom_interactables_are_merged_with_selectors(self) -> None:
@@ -322,7 +341,6 @@ class TestDoObserve:
"name": "East",
"tag": "option",
"selector": "#region > option:nth-of-type(2)",
- "value": "east",
}
]
)
@@ -332,31 +350,9 @@ class TestDoObserve:
east_option = next(element for element in serialized if element["name"] == "East")
assert east_option["selector"] == "#region > option:nth-of-type(2)"
- assert east_option["value"] == "east"
+ assert "value" not in east_option
assert ref_to_selector(east_option) == "#region > option:nth-of-type(2)"
- @pytest.mark.asyncio
- async def test_dom_password_field_value_redacted_by_type_not_name(self) -> None:
- # A password input whose accessible name is NOT password-like must still be redacted
- # when the DOM scan flags it (is_password); its raw value must never surface.
- page = _make_page(_make_a11y_tree(children=[]))
- page.evaluate = AsyncMock(
- return_value=[
- {
- "role": "textbox",
- "name": "Current",
- "tag": "input",
- "value": "",
- "is_password": True,
- "selector": "#pw",
- }
- ]
- )
- result = await do_observe(page)
- serialized = serialize_elements(result.elements)
- pw = next(element for element in serialized if element["name"] == "Current")
- assert pw["value"] == "***"
-
@pytest.mark.asyncio
async def test_duplicate_label_options_do_not_get_wrong_selector(self) -> None:
# Two a11y options share a label and two DOM options share it too. The merge must NOT
@@ -382,14 +378,12 @@ class TestDoObserve:
"name": "North",
"tag": "option",
"selector": "#r > option:nth-of-type(1)",
- "value": "n1",
},
{
"role": "option",
"name": "North",
"tag": "option",
"selector": "#r > option:nth-of-type(2)",
- "value": "n2",
},
]
)
@@ -398,37 +392,6 @@ class TestDoObserve:
a11y_norths = [e for e in serialized if e["name"] == "North" and not e.get("selector")]
assert len(a11y_norths) == 2
- @pytest.mark.asyncio
- async def test_duplicate_name_password_redacts_all_a11y_values(self) -> None:
- # A password field whose accessible name is shared with another textbox must have its
- # a11y value redacted even when the DOM match is ambiguous (duplicate name).
- tree = _make_a11y_tree(
- children=[
- {"role": "textbox", "name": "Current", "value": "s3cr3t"},
- {"role": "textbox", "name": "Current", "value": ""},
- ]
- )
- page = _make_page(tree)
- page.evaluate = AsyncMock(
- return_value=[
- {
- "role": "textbox",
- "name": "Current",
- "tag": "input",
- "value": "",
- "is_password": True,
- "selector": "#pw",
- },
- ]
- )
- result = await do_observe(page, max_elements=100)
- serialized = serialize_elements(result.elements)
- currents = [element for element in serialized if element["name"] == "Current"]
- assert currents, serialized
- for element in currents:
- assert element["value"] in ("***", "", None), element
- assert all("s3cr3t" not in str(element.get("value") or "") for element in serialized)
-
@pytest.mark.asyncio
async def test_match_index_stable_when_cap_reorders(self) -> None:
# A selector-bearing duplicate reordered ahead of the cap must NOT shift the nth ordinal
@@ -451,34 +414,6 @@ class TestDoObserve:
assert selectorless_dups, result.elements
assert selectorless_dups[0].match_index == 0
- @pytest.mark.asyncio
- async def test_divergent_name_dom_password_fails_closed(self) -> None:
- # If a DOM password field's accessible name diverges from the a11y name (so it cannot be
- # mapped), fail closed: redact every a11y textbox value rather than leak the a11y value.
- tree = _make_a11y_tree(
- children=[
- {"role": "textbox", "name": "Account", "value": "s3cr3t"},
- ]
- )
- page = _make_page(tree)
- page.evaluate = AsyncMock(
- return_value=[
- {
- "role": "textbox",
- "name": "DifferentName",
- "tag": "input",
- "value": "",
- "is_password": True,
- "selector": "#pw",
- },
- ]
- )
- result = await do_observe(page, max_elements=100)
- serialized = serialize_elements(result.elements)
- account = next(element for element in serialized if element["name"] == "Account")
- assert account["value"] == "***"
- assert all("s3cr3t" not in str(element.get("value") or "") for element in serialized)
-
@pytest.mark.asyncio
async def test_role_to_tag_mapping(self) -> None:
page = _make_page()
@@ -757,6 +692,85 @@ class TestSkyvernObserveMCP:
assert len(result["data"]["elements"]) == 4
assert result["data"]["element_count"] == 4
+ @pytest.mark.asyncio
+ async def test_default_observe_omits_values_from_output_and_registry(
+ self,
+ monkeypatch: pytest.MonkeyPatch,
+ ) -> None:
+ page = _make_page()
+ ctx = BrowserContext(mode="local")
+ state = make_session_state(context=ctx)
+ monkeypatch.setattr(mcp_browser, "get_page", AsyncMock(return_value=(page, ctx)))
+
+ async with scoped_session(state):
+ result = await mcp_browser.skyvern_observe()
+
+ assert all("value" not in element for element in result["data"]["elements"])
+ assert all("value" not in element for element in state._observed_refs["refs"].values())
+
+ @pytest.mark.asyncio
+ async def test_observe_include_values_keeps_values_out_of_registry(
+ self,
+ monkeypatch: pytest.MonkeyPatch,
+ ) -> None:
+ page = _make_values_page()
+ ctx = BrowserContext(mode="local")
+ state = make_session_state(context=ctx)
+ monkeypatch.setattr(mcp_browser, "get_page", AsyncMock(return_value=(page, ctx)))
+
+ async with scoped_session(state):
+ result = await mcp_browser.skyvern_observe(include_values=True)
+
+ email = next(element for element in result["data"]["elements"] if element["name"] == "Email")
+ assert email["value"] == "[email protected]"
+ assert all("value" not in element for element in state._observed_refs["refs"].values())
+
+ @pytest.mark.asyncio
+ async def test_observe_include_values_keeps_non_password_dom_value(
+ self,
+ monkeypatch: pytest.MonkeyPatch,
+ ) -> None:
+ page = _make_values_page()
+ ctx = BrowserContext(mode="local")
+ monkeypatch.setattr(mcp_browser, "get_page", AsyncMock(return_value=(page, ctx)))
+
+ result = await mcp_browser.skyvern_observe(include_values=True)
+
+ email = next(element for element in result["data"]["elements"] if element["name"] == "Email")
+ password = next(element for element in result["data"]["elements"] if element["name"] == "Current")
+ assert email["value"] == "[email protected]"
+ assert "value" not in password
+
+ @pytest.mark.asyncio
+ async def test_observe_preserves_existing_positional_parameter_order(
+ self,
+ monkeypatch: pytest.MonkeyPatch,
+ ) -> None:
+ page = _make_page()
+ ctx = BrowserContext(mode="local")
+ observe = AsyncMock(
+ return_value=ObserveResult(
+ url=page.url,
+ title="Login Page",
+ elements=[],
+ element_count=0,
+ total_on_page=0,
+ )
+ )
+ monkeypatch.setattr(mcp_browser, "get_page", AsyncMock(return_value=(page, ctx)))
+ monkeypatch.setattr(mcp_browser, "do_observe", observe)
+
+ result = await mcp_browser.skyvern_observe(None, None, None, False, 7)
+
+ assert result["ok"] is True
+ observe.assert_awaited_once_with(
+ page,
+ selector=None,
+ interactive_only=False,
+ max_elements=7,
+ include_values=False,
+ )
+
@pytest.mark.asyncio
async def test_observe_no_browser(self, monkeypatch: pytest.MonkeyPatch) -> None:
from skyvern.cli.mcp_tools._session import BrowserNotAvailableError
@@ -844,6 +858,27 @@ class TestSkyvernExecuteMCP:
click_call = mcp_browser.skyvern_click.call_args
assert 'role=button[name="Sign In"]' in str(click_call)
+ @pytest.mark.asyncio
+ async def test_execute_observe_threads_include_values(self, monkeypatch: pytest.MonkeyPatch) -> None:
+ page = _make_page()
+ ctx = BrowserContext(mode="local")
+ observe = AsyncMock(
+ return_value=ObserveResult(
+ url=page.url,
+ title="Login Page",
+ elements=[],
+ element_count=0,
+ total_on_page=0,
+ )
+ )
+ monkeypatch.setattr(mcp_browser, "get_page", AsyncMock(return_value=(page, ctx)))
+ monkeypatch.setattr("skyvern.cli.core.browser_ops.do_observe", observe)
+
+ result = await mcp_browser.skyvern_execute(steps=[{"tool": "observe", "params": {"include_values": True}}])
+
+ assert result["ok"] is True
+ observe.assert_awaited_once_with(page, include_values=True)
+
@pytest.mark.asyncio
async def test_execute_resolves_ref_from_prior_observe(self, monkeypatch: pytest.MonkeyPatch) -> None:
page = _make_page()
@@ -867,6 +902,25 @@ class TestSkyvernExecuteMCP:
assert execute_result["data"]["steps_completed"] == 1
assert mcp_browser.skyvern_click.call_args.kwargs["selector"] == 'role=button[name="Sign In"]'
+ @pytest.mark.asyncio
+ async def test_execute_observe_include_values_keeps_values_out_of_registry(
+ self,
+ monkeypatch: pytest.MonkeyPatch,
+ ) -> None:
+ page = _make_values_page()
+ ctx = BrowserContext(mode="local")
+ state = make_session_state(context=ctx)
+ monkeypatch.setattr(mcp_browser, "get_page", AsyncMock(return_value=(page, ctx)))
+
+ async with scoped_session(state):
+ result = await mcp_browser.skyvern_execute(steps=[{"tool": "observe", "params": {"include_values": True}}])
+
+ elements = result["data"]["results"][0]["data"]["elements"]
+ email = next(element for element in elements if element["name"] == "Email")
+ assert email["value"] == "[email protected]"
+ assert state._observed_refs["refs"]
+ assert all("value" not in element for element in state._observed_refs["refs"].values())
+
@pytest.mark.asyncio
async def test_execute_resolves_ref_from_prior_observe_without_session_id(
self,
@@ -1355,7 +1409,6 @@ class TestSkyvernExecuteMCP:
"name": "East",
"tag": "option",
"selector": option_selector,
- "value": "east",
}
]
),