From 1b6be13d116f46617d71739ff8ca074a1b02cd24 Mon Sep 17 00:00:00 2001 From: "Tommy D. Rossi" Date: Tue, 3 Feb 2026 12:36:54 +0100 Subject: [PATCH] Dedupe parent names that are substrings of child names in aria snapshot --- playwriter/src/aria-snapshot.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/playwriter/src/aria-snapshot.ts b/playwriter/src/aria-snapshot.ts index f5f565c..e221d31 100644 --- a/playwriter/src/aria-snapshot.ts +++ b/playwriter/src/aria-snapshot.ts @@ -478,6 +478,15 @@ function isTextRole(role: string): boolean { return role === 'statictext' || role === 'inlinetextbox' } +function isSubstringOfAny(needle: string, haystack: Set): boolean { + for (const str of haystack) { + if (str.includes(needle)) { + return true + } + } + return false +} + // ============================================================================ // Main Functions // ============================================================================ @@ -687,7 +696,7 @@ export async function getAriaSnapshot({ page, locator, refFilter, wsUrl, interac } const hasChildren = childLines.length > 0 - const nameToUse = hasName && childNames.has(name) ? '' : name + const nameToUse = hasName && (childNames.has(name) || isSubstringOfAny(name, childNames)) ? '' : name const hasNameToUse = nameToUse.length > 0 const isWrapper = SKIP_WRAPPER_ROLES.has(role) const isInteractive = INTERACTIVE_ROLES.has(role)