Skip to content

Commit f199816

Browse files
committed
support depth parameter for DOM.getDocument
1 parent 5e74e17 commit f199816

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/cdp/Node.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -565,13 +565,13 @@ test "cdp Node: Writer" {
565565
.localName = "div",
566566
.childNodeCount = 1,
567567
.parentId = 3,
568-
.children = &.{ .{
568+
.children = &.{.{
569569
.nodeId = 6,
570570
.localName = "a",
571571
.childNodeCount = 0,
572572
.parentId = 5,
573-
}}
574-
}
575-
} } }, json);
573+
}},
574+
} },
575+
} }, json);
576576
}
577577
}

src/cdp/domains/dom.zig

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,18 @@ pub fn processMessage(cmd: anytype) !void {
6060

6161
// https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-getDocument
6262
fn getDocument(cmd: anytype) !void {
63-
// const params = (try cmd.params(struct {
64-
// depth: ?u32 = null,
65-
// pierce: ?bool = null,
66-
// })) orelse return error.InvalidParams;
63+
const params = (try cmd.params(struct {
64+
// CDP documentation implies that 0 isn't valid, but it _does_ work in Chrome
65+
depth: ?i32 = null,
66+
pierce: ?bool = null,
67+
})) orelse return error.InvalidParams;
6768

6869
const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded;
6970
const page = bc.session.currentPage() orelse return error.PageNotLoaded;
7071
const doc = parser.documentHTMLToDocument(page.window.document);
7172

7273
const node = try bc.node_registry.register(parser.documentToNode(doc));
73-
return cmd.sendResult(.{ .root = bc.nodeWriter(node, .{}) }, .{});
74+
return cmd.sendResult(.{ .root = bc.nodeWriter(node, .{ .depth = params.depth orelse 3 }) }, .{});
7475
}
7576

7677
// https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-performSearch
@@ -451,7 +452,7 @@ fn requestChildNodes(cmd: anytype) !void {
451452

452453
try cmd.sendEvent("DOM.setChildNodes", .{
453454
.parentId = node.id,
454-
.nodes = bc.nodeWriter(node, .{.depth = params.depth, .exclude_root = true}),
455+
.nodes = bc.nodeWriter(node, .{ .depth = params.depth, .exclude_root = true }),
455456
}, .{
456457
.session_id = session_id,
457458
});
@@ -610,6 +611,7 @@ test "cdp.dom: getBoxModel" {
610611
try ctx.processMessage(.{ // Hacky way to make sure nodeId 0 exists in the registry
611612
.id = 3,
612613
.method = "DOM.getDocument",
614+
.params = .{ .depth = 3 },
613615
});
614616

615617
try ctx.processMessage(.{

0 commit comments

Comments
 (0)