@@ -60,17 +60,18 @@ pub fn processMessage(cmd: anytype) !void {
6060
6161// https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-getDocument
6262fn 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