Skip to content

Commit 2855029

Browse files
authored
js function declared as string (#454)
1 parent b216072 commit 2855029

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/a11y/utils.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,13 @@ export function buildHierarchicalTree(nodes: AccessibilityNode[]): TreeResult {
7777
nodes.forEach((node) => {
7878
const hasChildren = node.childIds && node.childIds.length > 0;
7979
const hasValidName = node.name && node.name.trim() !== "";
80+
const isInteractive =
81+
node.role !== "none" &&
82+
node.role !== "generic" &&
83+
node.role !== "InlineTextBox"; //add other interactive roles here
8084

81-
// Skip nodes that have no semantic value (no name and no children)
82-
if (!hasValidName && !hasChildren) {
85+
// Include nodes that are either named, have children, or are interactive
86+
if (!hasValidName && !hasChildren && !isInteractive) {
8387
return;
8488
}
8589

@@ -177,7 +181,7 @@ export async function getAccessibilityTree(
177181

178182
// This function is wrapped into a string and sent as a CDP command
179183
// It is not meant to be actually executed here
180-
function getNodePath(el: Element) {
184+
const functionString = `function getNodePath(el) {
181185
if (!el || el.nodeType !== Node.ELEMENT_NODE) return "";
182186
const pathSegments = [];
183187
let current = el;
@@ -196,17 +200,15 @@ function getNodePath(el: Element) {
196200
}
197201
const segment = index > 1 ? tagName + "[" + index + "]" : tagName;
198202
pathSegments.unshift(segment);
199-
current = current.parentNode as Element;
203+
current = current.parentNode;
200204
if (!current || !current.parentNode) break;
201205
if (current.nodeName.toLowerCase() === "html") {
202206
pathSegments.unshift("html");
203207
break;
204208
}
205209
}
206210
return "/" + pathSegments.join("/");
207-
}
208-
209-
const functionString = getNodePath.toString();
211+
}`;
210212

211213
export async function getXPathByResolvedObjectId(
212214
cdpClient: CDPSession,

0 commit comments

Comments
 (0)