Skip to content

Automate browser based workflows with AI

fix(SKY-9402): always include native form inputs inside shadow DOM in visibility check (#6165)

LawyZhenga172924ea4d4
diff --git a/skyvern/webeye/scraper/domUtils.js b/skyvern/webeye/scraper/domUtils.js
index f8c6553e8..fc53ecfeb 100644
--- a/skyvern/webeye/scraper/domUtils.js
+++ b/skyvern/webeye/scraper/domUtils.js
@@ -452,11 +452,27 @@ function isHoverOnlyElement(element) {
// from playwright: https://github.com/microsoft/playwright/blob/1b65f26f0287c0352e76673bc5f85bc36c934b55/packages/playwright-core/src/server/injected/domUtils.ts#L100-L119
// NOTE: According this logic, some elements with aria-hidden won't be considered as invisible. And the result shows they are indeed interactable.
function isElementVisible(element) {
+ const tagLower = element.tagName.toLowerCase();
+
+ // Web Component libraries often hide native form inputs inside shadow DOM
+ // with CSS while rendering a styled overlay.
+ if (
+ element.getRootNode() instanceof ShadowRoot &&
+ (tagLower === "input" ||
+ tagLower === "textarea" ||
+ tagLower === "select") &&
+ !element.disabled
+ ) {
+ if (tagLower !== "input" || element.type !== "hidden") {
+ return true;
+ }
+ }
+
// TODO: This is a hack to not check visibility for option elements
// because they are not visible by default. We check their parent instead for visibility.
if (
- element.tagName.toLowerCase() === "option" ||
- (element.tagName.toLowerCase() === "input" &&
+ tagLower === "option" ||
+ (tagLower === "input" &&
(element.type === "radio" || element.type === "checkbox"))
)
return element.parentElement && isElementVisible(element.parentElement);
diff --git a/tests/unit/test_shadow_form_input_visibility.py b/tests/unit/test_shadow_form_input_visibility.py
new file mode 100644
index 000000000..4abea0957
--- /dev/null
+++ b/tests/unit/test_shadow_form_input_visibility.py
@@ -0,0 +1,57 @@
+"""
+Tests for shadow DOM form input visibility fix.
+
+Web Component libraries often hide native form inputs inside shadow DOM
+with CSS while rendering a styled overlay. The scraper must still include
+these native inputs so the agent can interact with them.
+"""
+
+import subprocess
+
+
+def _load_js() -> str:
+ from skyvern.webeye.scraper.scraper import load_js_script
+
+ return load_js_script()
+
+
+class TestShadowFormInputVisibility:
+ def test_js_syntax_valid(self):
+ result = subprocess.run(
+ ["node", "--check", "skyvern/webeye/scraper/domUtils.js"],
+ capture_output=True,
+ text=True,
+ )
+ assert result.returncode == 0, f"JS syntax error: {result.stderr}"
+
+ def test_shadow_form_input_guard_exists(self):
+ js = _load_js()
+ idx_fn = js.index("function isElementVisible(")
+ idx_fn_end = js.index("\nfunction ", idx_fn + 1)
+ body = js[idx_fn:idx_fn_end]
+ assert "getRootNode() instanceof ShadowRoot" in body
+ assert "tagLower" in body or "tagName" in body
+
+ def test_guard_covers_input_textarea_select(self):
+ js = _load_js()
+ idx_fn = js.index("function isElementVisible(")
+ idx_fn_end = js.index("\nfunction ", idx_fn + 1)
+ body = js[idx_fn:idx_fn_end]
+ for tag in ["input", "textarea", "select"]:
+ assert f'"{tag}"' in body, f"Shadow DOM guard must cover {tag} elements"
+
+ def test_guard_excludes_hidden_inputs(self):
+ js = _load_js()
+ idx_fn = js.index("function isElementVisible(")
+ idx_guard = js.index("getRootNode() instanceof ShadowRoot", idx_fn)
+ guard_block = js[idx_guard : idx_guard + 300]
+ assert "hidden" in guard_block, "Guard must exclude input[type=hidden]"
+
+ def test_guard_placed_before_visibility_checks(self):
+ js = _load_js()
+ idx_fn = js.index("function isElementVisible(")
+ idx_guard = js.index("getRootNode() instanceof ShadowRoot", idx_fn)
+ idx_rect = js.index("getBoundingClientRect", idx_fn)
+ idx_display = js.index('display === "contents"', idx_fn)
+ assert idx_guard < idx_rect, "Shadow form guard must run before bounding rect check"
+ assert idx_guard < idx_display, "Shadow form guard must run before display:contents check"