@@ -60,17 +60,18 @@ pub fn processMessage(cmd: anytype) !void {
60
60
61
61
// https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-getDocument
62
62
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 ;
67
68
68
69
const bc = cmd .browser_context orelse return error .BrowserContextNotLoaded ;
69
70
const page = bc .session .currentPage () orelse return error .PageNotLoaded ;
70
71
const doc = parser .documentHTMLToDocument (page .window .document );
71
72
72
73
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 }) }, .{});
74
75
}
75
76
76
77
// https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-performSearch
@@ -451,7 +452,7 @@ fn requestChildNodes(cmd: anytype) !void {
451
452
452
453
try cmd .sendEvent ("DOM.setChildNodes" , .{
453
454
.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 }),
455
456
}, .{
456
457
.session_id = session_id ,
457
458
});
@@ -610,6 +611,7 @@ test "cdp.dom: getBoxModel" {
610
611
try ctx .processMessage (.{ // Hacky way to make sure nodeId 0 exists in the registry
611
612
.id = 3 ,
612
613
.method = "DOM.getDocument" ,
614
+ .params = .{ .depth = 3 },
613
615
});
614
616
615
617
try ctx .processMessage (.{
0 commit comments