Lightpanda: the headless browser designed for AI and automation
feat(cdp): implement Accessibility.getPartialAXTree
Rohitd75ef37d4203
diff --git a/src/cdp/domains/accessibility.zig b/src/cdp/domains/accessibility.zigindex 3ecf397b9..7120ad333 100644--- a/src/cdp/domains/accessibility.zig+++ b/src/cdp/domains/accessibility.zig@@ -26,6 +26,7 @@ pub fn processMessage(cmd: *CDP.Command) !void {enable,disable,getFullAXTree,+ getPartialAXTree,queryAXTree,}, cmd.input.action) orelse return error.UnknownMethod;@@ -33,6 +34,7 @@ pub fn processMessage(cmd: *CDP.Command) !void {.enable => return enable(cmd),.disable => return disable(cmd),.getFullAXTree => return getFullAXTree(cmd),+ .getPartialAXTree => return getPartialAXTree(cmd),.queryAXTree => return queryAXTree(cmd),}}@@ -96,6 +98,29 @@ fn queryAXTree(cmd: *CDP.Command) !void {}) }, .{});}+fn getPartialAXTree(cmd: *CDP.Command) !void {+ const params = (try cmd.params(struct {+ nodeId: ?u32 = null,+ backendNodeId: ?u32 = null,+ objectId: ?[]const u8 = null,+ // Accepted for Chrome protocol compatibility. The ancestor chain is+ // not yet emitted; this returns the subtree rooted at the resolved+ // node, matching the scope of queryAXTree.+ fetchRelatives: ?bool = true,+ })) orelse return error.InvalidParams;++ const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded;+ const node = try dom.getNode(cmd.arena, bc, params.nodeId, params.backendNodeId, params.objectId);++ const frame = bc.mainFrame() orelse return error.FrameNotLoaded;+ const temp_arena = try frame.getArena(.medium, "AXNode");+ defer frame.releaseArena(temp_arena);++ // No filter: emit the full accessibility subtree rooted at the resolved+ // node, the same shape getFullAXTree produces for the document root.+ return cmd.sendResult(.{ .nodes = try bc.axnodeWriter(temp_arena, node, .{}) }, .{});+}+const testing = @import("../testing.zig");test "cdp.accessibility: queryAXTree requires nodeId, backendNodeId or objectId" {@@ -126,3 +151,32 @@ test "cdp.accessibility: queryAXTree with unknown nodeId returns error" {});try ctx.expectSentError(-31998, "NodeNotFound", .{ .id = 1 });}++test "cdp.accessibility: getPartialAXTree requires nodeId, backendNodeId or objectId" {+ var ctx = try testing.context();+ defer ctx.deinit();++ _ = try ctx.loadBrowserContext(.{ .id = "BID-A", .url = "cdp/ax_tree.html" });++ // Params present but no node identifier — dom.getNode returns MissingParams.+ try ctx.processMessage(.{+ .id = 1,+ .method = "Accessibility.getPartialAXTree",+ .params = .{ .fetchRelatives = true },+ });+ try ctx.expectSentError(-31998, "MissingParams", .{ .id = 1 });+}++test "cdp.accessibility: getPartialAXTree with unknown nodeId returns error" {+ var ctx = try testing.context();+ defer ctx.deinit();++ _ = try ctx.loadBrowserContext(.{ .id = "BID-A", .url = "cdp/ax_tree.html" });++ try ctx.processMessage(.{+ .id = 1,+ .method = "Accessibility.getPartialAXTree",+ .params = .{ .nodeId = 99999 },+ });+ try ctx.expectSentError(-31998, "NodeNotFound", .{ .id = 1 });+}