Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Report which visibility check dropped each hidden control in Task V3 observe (SKY-16393) (#8573)
pedrohsdba8b488c66c60
diff --git a/skyvern/forge/taskv3/tools.py b/skyvern/forge/taskv3/tools.pyindex 369268f18..10b5a7e27 100644--- a/skyvern/forge/taskv3/tools.py+++ b/skyvern/forge/taskv3/tools.py@@ -6005,6 +6005,10 @@ async () => {// Candidates the visibility gates below drop. Those drops are silent, so a page whose whole app// shell is behind a boot gate renders exactly like an empty one; this is what tells the two apart.let hiddenDropped = 0;+ // hiddenDropped split by the gate that dropped the control; each gate is a different fix.+ let hiddenDroppedOffCanvas = 0;+ let hiddenDroppedVisibility = 0;+ let hiddenDroppedZeroRect = 0;let phantomDropped = 0;let truncated = 0;let truncatedInComponents = 0;@@ -6121,12 +6125,12 @@ async () => {// like v1 (whose center_x check is only reached for a non-zero rect), so the zero-size// skinned-proxy carve-out below still runs for an off-screen-positioned skinned control.const centerX = (gr.left + gr.width) / 2 + window.scrollX;- if (ownGated && gr.width !== 0 && gr.height !== 0 && centerX < 0 && !_hScrolledAncestor(gateEl)) { hiddenDropped++; continue; }+ if (ownGated && gr.width !== 0 && gr.height !== 0 && centerX < 0 && !_hScrolledAncestor(gateEl)) { hiddenDropped++; hiddenDroppedOffCanvas++; continue; }// v1's isElementStyleVisibilityVisible (domUtils.js) drops a control whose own computed// visibility is not 'visible'. Scoped to non-zero-rect elements so the zero-size skinned-proxy// carve-out below still runs; visibility is read per-element, so a visibility:visible child of a// hidden ancestor is kept. A native checkbox/radio judges the parent here instead of itself.- if (ownGated && gr.width !== 0 && gr.height !== 0 && window.getComputedStyle(gateEl).visibility !== 'visible') { hiddenDropped++; continue; }+ if (ownGated && gr.width !== 0 && gr.height !== 0 && window.getComputedStyle(gateEl).visibility !== 'visible') { hiddenDropped++; hiddenDroppedVisibility++; continue; }let hidden = false;if (r.width === 0 || r.height === 0) {// Design systems skin a native SELECT/checkbox/radio/file input at zero size behind a styled@@ -6148,6 +6152,7 @@ async () => {// all-hidden, or all-off-canvas host is a phantom.} else {hiddenDropped++;+ hiddenDroppedZeroRect++;continue;}}@@ -6873,7 +6878,7 @@ async () => {}rec.ref = typeof r === 'number' ? r : null;}- const payload = JSON.stringify({ refsFresh: refsFresh, url: location.href, title: document.title, text: texts, textFull: texts.map((t) => { const f = fullText.get(t); return f && f !== t ? f : null; }), textTruncated: textFull, textDropped: textDropped, iframes: iframeInfo, frameCensus: frameCensus, dropped: dropped, truncated: truncated, truncatedInComponents: truncatedInComponents, unnamedAnonymous: unnamedAnonymous, unnamedBudget: unnamedBudget, unnamedDuplicated: unnamedDuplicated, unnamedUnverifiable: unnamedUnverifiable, unnamedUnsafe: unnamedUnsafe, unreadableRoot: sawUnreadableRoot, undiscoveredRoots: undiscoveredRoots, rootCount: allRoots.length - 1, hiddenListed: hiddenListed, hiddenDropped: hiddenDropped, phantomDropped: phantomDropped, markersMinted: markersWritten, markersReused: markersReused, pageMutated: mutated, elements: out });+ const payload = JSON.stringify({ refsFresh: refsFresh, url: location.href, title: document.title, text: texts, textFull: texts.map((t) => { const f = fullText.get(t); return f && f !== t ? f : null; }), textTruncated: textFull, textDropped: textDropped, iframes: iframeInfo, frameCensus: frameCensus, dropped: dropped, truncated: truncated, truncatedInComponents: truncatedInComponents, unnamedAnonymous: unnamedAnonymous, unnamedBudget: unnamedBudget, unnamedDuplicated: unnamedDuplicated, unnamedUnverifiable: unnamedUnverifiable, unnamedUnsafe: unnamedUnsafe, unreadableRoot: sawUnreadableRoot, undiscoveredRoots: undiscoveredRoots, rootCount: allRoots.length - 1, hiddenListed: hiddenListed, hiddenDropped: hiddenDropped, hiddenDroppedOffCanvas: hiddenDroppedOffCanvas, hiddenDroppedVisibility: hiddenDroppedVisibility, hiddenDroppedZeroRect: hiddenDroppedZeroRect, phantomDropped: phantomDropped, markersMinted: markersWritten, markersReused: markersReused, pageMutated: mutated, elements: out });return __OBSERVE_RETURN__;}"""@@ -7722,6 +7727,9 @@ _OBSERVE_SUMMED_KEYS = ("rootCount","hiddenListed","hiddenDropped",+ "hiddenDroppedOffCanvas",+ "hiddenDroppedVisibility",+ "hiddenDroppedZeroRect","phantomDropped","markersMinted","markersReused",@@ -8517,6 +8525,9 @@ def build_browser_tools("text_dropped": text_dropped,"hidden_listed": hidden_kept,"hidden_dropped": hidden_dropped,+ "hidden_dropped_off_canvas": int(data.get("hiddenDroppedOffCanvas") or 0),+ "hidden_dropped_visibility": int(data.get("hiddenDroppedVisibility") or 0),+ "hidden_dropped_zero_rect": int(data.get("hiddenDroppedZeroRect") or 0),"phantom_dropped": phantom_dropped,"iframes_in_component_roots": iframe_info.get("inComponents") or 0,"undiscovered_roots": data.get("undiscoveredRoots") or 0,diff --git a/tests/unit/test_taskv3_tools.py b/tests/unit/test_taskv3_tools.pyindex 6d6a1403e..5b9efb5d8 100644--- a/tests/unit/test_taskv3_tools.py+++ b/tests/unit/test_taskv3_tools.py@@ -1808,6 +1808,9 @@ async def test_observe_result_carries_count_only_summary_for_the_call_record() -"text_dropped","hidden_listed","hidden_dropped",+ "hidden_dropped_off_canvas",+ "hidden_dropped_visibility",+ "hidden_dropped_zero_rect","phantom_dropped","iframes_in_component_roots","undiscovered_roots",@@ -22135,6 +22138,8 @@ async def test_observe_discloses_that_a_populated_page_was_dropped_whole_by_the_assert "(0 interactive elements)" in r.content, r.contentassert "note: the page has 5 control(s) that are present but not visible" in r.content, r.contentassert r.data is not None and r.data["summary"]["hidden_dropped"] == 5+ assert r.data["summary"]["hidden_dropped_off_canvas"] == 1, r.data["summary"]+ assert r.data["summary"]["hidden_dropped_visibility"] == 4, r.data["summary"]@_skip_no_browser@@ -22159,6 +22164,105 @@ async def test_observe_stays_silent_about_hidden_chrome_when_it_can_still_see_thassert r.data is not None and r.data["summary"]["hidden_dropped"] == 1+_HIDDEN_DROP_BUCKETS = ("hidden_dropped_off_canvas", "hidden_dropped_visibility", "hidden_dropped_zero_rect")+++def _hidden_drop_split(summary: dict[str, Any]) -> dict[str, int]:+ return {bucket: summary[bucket] for bucket in _HIDDEN_DROP_BUCKETS}+++@_skip_no_browser+ ("controls", "bucket"),+ [+ (+ '<button style="position:absolute;left:-9999px">A</button>'+ '<a href="#b" style="position:absolute;left:-9999px">B</a>',+ "hidden_dropped_off_canvas",+ ),+ (+ '<button style="visibility:hidden">A</button><input style="visibility:hidden" placeholder="B">',+ "hidden_dropped_visibility",+ ),+ (+ '<button style="display:none">A</button>'+ '<button style="display:inline-block;width:0;height:0;padding:0;border:0;overflow:hidden">B</button>',+ "hidden_dropped_zero_rect",+ ),+ ],+)+async def test_observe_attributes_each_hidden_drop_to_the_gate_that_dropped_it(controls: str, bucket: str) -> None:+ # The three gates are three different fixes (a viewport assumption, a visibility predicate, a+ # layout edge), and the pooled count cannot say which one blinded a page.+ html = f"<!doctype html><html><head><title>Portal</title></head><body>{controls}</body></html>"+ async with _content_page(html) as page:+ tools = build_browser_tools(_fixed_page_provider(page))+ r = await _tool(tools, "observe").handler({})++ assert r.status == "ok" and r.data is not None, r.content+ summary = r.data["summary"]+ assert _hidden_drop_split(summary) == {b: (2 if b == bucket else 0) for b in _HIDDEN_DROP_BUCKETS}, summary+ assert summary["hidden_dropped"] == 2, summary+ assert "note: the page has 2 control(s) that are present but not visible" in r.content, r.content+++@_skip_no_browser+async def test_observe_splits_a_mixed_blind_page_by_gate_and_the_pooled_count_is_their_sum() -> None:+ # Distinct counts per gate, so a drop charged to the wrong bucket cannot still add up.+ html = (+ "<!doctype html><html><head><title>Portal</title></head><body>"+ '<button style="position:absolute;left:-9999px">Off</button>'+ '<button style="visibility:hidden">Vis1</button><button style="visibility:hidden">Vis2</button>'+ '<div style="display:none"><button>Z1</button><button>Z2</button><a href="#z">Z3</a></div>'+ "</body></html>"+ )+ async with _content_page(html) as page:+ tools = build_browser_tools(_fixed_page_provider(page))+ r = await _tool(tools, "observe").handler({})++ assert r.status == "ok" and r.data is not None, r.content+ summary = r.data["summary"]+ assert _hidden_drop_split(summary) == {+ "hidden_dropped_off_canvas": 1,+ "hidden_dropped_visibility": 2,+ "hidden_dropped_zero_rect": 3,+ }, summary+ assert summary["hidden_dropped"] == 6, summary+ assert "note: the page has 6 control(s) that are present but not visible" in r.content, r.content+++@_skip_no_browser+async def test_a_frames_hidden_drops_are_summed_into_the_page_split(monkeypatch: pytest.MonkeyPatch) -> None:+ # Each realm counts its own drops; a split counter left out of the frame merge would report only the+ # main frame's share while the pooled count reported the page's.+ monkeypatch.setattr(settings, "TASK_V3_FRAME_PERCEPTION", True)+ frame = (+ "<button style='position:absolute;left:-9999px'>FOff</button>"+ "<button style='visibility:hidden'>FVis</button>"+ "<button style='display:none'>FZ1</button><button style='display:none'>FZ2</button>"+ "<button>Frame Live</button>"+ )+ html = (+ '<button style="display:none">MainZ</button><button>Main Live</button>'+ f'<iframe srcdoc="{frame}" width="300" height="120"></iframe>'+ )+ async with _live_page(html) as page:+ tools = build_browser_tools(_fixed_page_provider(page))+ merged = await _tool(tools, "observe").handler({})++ assert merged.data is not None, merged.content+ summary = merged.data["summary"]+ assert _hidden_drop_split(summary) == {+ "hidden_dropped_off_canvas": 1,+ "hidden_dropped_visibility": 1,+ "hidden_dropped_zero_rect": 3,+ }, summary+ assert summary["hidden_dropped"] == 5, summary++# The shape SKY-15662 was diagnosed on: many live, visible per-row controls whose accessible name is# exactly the string carried by one button inside a display:none subtree the page ships on every# load. That subtree is a template the app clones to open its dialog, so the hidden button is the one