From eef5f3fec26591913413df22659501fc002304a0 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Thu, 17 Jul 2025 19:05:17 +0800 Subject: [PATCH] support null params to CDP DOM.getDocument --- src/cdp/domains/dom.zig | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cdp/domains/dom.zig b/src/cdp/domains/dom.zig index 4ddb40a9..a88932fc 100644 --- a/src/cdp/domains/dom.zig +++ b/src/cdp/domains/dom.zig @@ -60,18 +60,19 @@ pub fn processMessage(cmd: anytype) !void { // https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-getDocument fn getDocument(cmd: anytype) !void { - const params = (try cmd.params(struct { + const Params = struct { // CDP documentation implies that 0 isn't valid, but it _does_ work in Chrome - depth: ?i32 = null, - pierce: ?bool = null, - })) orelse return error.InvalidParams; + depth: i32 = 3, + pierce: bool = false, + }; + const params = try cmd.params(Params) orelse Params{}; const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded; const page = bc.session.currentPage() orelse return error.PageNotLoaded; const doc = parser.documentHTMLToDocument(page.window.document); const node = try bc.node_registry.register(parser.documentToNode(doc)); - return cmd.sendResult(.{ .root = bc.nodeWriter(node, .{ .depth = params.depth orelse 3 }) }, .{}); + return cmd.sendResult(.{ .root = bc.nodeWriter(node, .{ .depth = params.depth }) }, .{}); } // https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-performSearch @@ -611,7 +612,6 @@ test "cdp.dom: getBoxModel" { try ctx.processMessage(.{ // Hacky way to make sure nodeId 0 exists in the registry .id = 3, .method = "DOM.getDocument", - .params = .{ .depth = 3 }, }); try ctx.processMessage(.{