Lightpanda: the headless browser designed for AI and automation
accname: ignore a blank aria-label
Adrià Arrufat858a692399ce
diff --git a/src/SemanticTree.zig b/src/SemanticTree.zigindex a78c42d24..a983eaf04 100644--- a/src/SemanticTree.zig+++ b/src/SemanticTree.zig@@ -250,7 +250,7 @@ fn visitNode(const xpath = ctx.xpath_buffer.items;const has_explicit_label = if (node.is(Element)) |el|- el.getAttributeInterned("aria-label") != null or el.getAttributeInterned("title") != null+ !isAllWhitespace(el.getAttributeInterned("aria-label") orelse "") or el.getAttributeInterned("title") != nullelsefalse;diff --git a/src/browser/tests/cdp/accname.html b/src/browser/tests/cdp/accname.htmlindex c9d7c57fd..479f04612 100644--- a/src/browser/tests/cdp/accname.html+++ b/src/browser/tests/cdp/accname.html@@ -8,6 +8,12 @@<span id="button" role="button">Click me</span><div id="nested" role="link">Read <span>more</span></div>+ <!-- A blank aria-label is ignored (AccName step 2D): the name still comes+ from contents. -->+ <div id="empty_label" role="button" aria-label="">Sat 10</div>+ <div id="blank_label" role="button" aria-label=" ">Pick</div>+ <div id="set_label" role="button" aria-label="Saturday">Sat 10</div>+<!-- No name-from-content: a bare div, and a role that isn't name-from-content. --><div id="plain">ignored text</div><div id="pres" role="presentation">ignored</div>diff --git a/src/server/cdp/AXNode.zig b/src/server/cdp/AXNode.zigindex 430f906d1..3865d107a 100644--- a/src/server/cdp/AXNode.zig+++ b/src/server/cdp/AXNode.zig@@ -26,6 +26,7 @@ const TreeWalker = @import("../../browser/webapi/TreeWalker.zig");const interactive = @import("../../browser/interactive.zig");const NodeRegistry = @import("../../NodeRegistry.zig");+const isAllWhitespace = @import("../../string.zig").isAllWhitespace;const log = lp.log;const jsonStringify = std.json.Stringify;@@ -983,7 +984,10 @@ fn writeName(}}- if (el.getAttributeInterned("aria-label")) |aria_label| {+ // A blank aria-label is ignored (accname 2D), so the name comes+ // from content instead.+ const aria_label = el.getAttributeInterned("aria-label") orelse "";+ if (!isAllWhitespace(aria_label)) {try w.write(aria_label);return .aria_label;}@@ -2038,6 +2042,9 @@ test "AXNode: getName name-from-content honors explicit role" {.{ .selector = "#button", .expected = "Click me" },// Recurses through child elements; the space here is real source whitespace..{ .selector = "#nested", .expected = "Read more" },+ .{ .selector = "#empty_label", .expected = "Sat 10" },+ .{ .selector = "#blank_label", .expected = "Pick" },+ .{ .selector = "#set_label", .expected = "Saturday" },// No role, or a non-name-from-content role: no name from contents..{ .selector = "#plain", .expected = null },.{ .selector = "#pres", .expected = null },