Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

js function declared as string #454

Merged
merged 1 commit into from
Feb 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions lib/a11y/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,13 @@ export function buildHierarchicalTree(nodes: AccessibilityNode[]): TreeResult {
nodes.forEach((node) => {
const hasChildren = node.childIds && node.childIds.length > 0;
const hasValidName = node.name && node.name.trim() !== "";
const isInteractive =
node.role !== "none" &&
node.role !== "generic" &&
node.role !== "InlineTextBox"; //add other interactive roles here

// Skip nodes that have no semantic value (no name and no children)
if (!hasValidName && !hasChildren) {
// Include nodes that are either named, have children, or are interactive
if (!hasValidName && !hasChildren && !isInteractive) {
return;
}

Expand Down Expand Up @@ -177,7 +181,7 @@ export async function getAccessibilityTree(

// This function is wrapped into a string and sent as a CDP command
// It is not meant to be actually executed here
function getNodePath(el: Element) {
const functionString = `function getNodePath(el) {
if (!el || el.nodeType !== Node.ELEMENT_NODE) return "";
const pathSegments = [];
let current = el;
Expand All @@ -196,17 +200,15 @@ function getNodePath(el: Element) {
}
const segment = index > 1 ? tagName + "[" + index + "]" : tagName;
pathSegments.unshift(segment);
current = current.parentNode as Element;
current = current.parentNode;
if (!current || !current.parentNode) break;
if (current.nodeName.toLowerCase() === "html") {
pathSegments.unshift("html");
break;
}
}
return "/" + pathSegments.join("/");
}

const functionString = getNodePath.toString();
}`;

export async function getXPathByResolvedObjectId(
cdpClient: CDPSession,
Expand Down
Loading