support depth parameter for DOM.getDocument

This commit is contained in:
Karl Seguin
2025-07-17 14:15:58 +08:00
parent 5e74e17b41
commit f199816fcd
2 changed files with 12 additions and 10 deletions

View File

@@ -570,8 +570,8 @@ test "cdp Node: Writer" {
.localName = "a", .localName = "a",
.childNodeCount = 0, .childNodeCount = 0,
.parentId = 5, .parentId = 5,
}} }},
} } },
} } }, json); } }, json);
} }
} }

View File

@@ -60,17 +60,18 @@ pub fn processMessage(cmd: anytype) !void {
// https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-getDocument // https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-getDocument
fn getDocument(cmd: anytype) !void { fn getDocument(cmd: anytype) !void {
// const params = (try cmd.params(struct { const params = (try cmd.params(struct {
// depth: ?u32 = null, // CDP documentation implies that 0 isn't valid, but it _does_ work in Chrome
// pierce: ?bool = null, depth: ?i32 = null,
// })) orelse return error.InvalidParams; pierce: ?bool = null,
})) orelse return error.InvalidParams;
const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded; const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded;
const page = bc.session.currentPage() orelse return error.PageNotLoaded; const page = bc.session.currentPage() orelse return error.PageNotLoaded;
const doc = parser.documentHTMLToDocument(page.window.document); const doc = parser.documentHTMLToDocument(page.window.document);
const node = try bc.node_registry.register(parser.documentToNode(doc)); const node = try bc.node_registry.register(parser.documentToNode(doc));
return cmd.sendResult(.{ .root = bc.nodeWriter(node, .{}) }, .{}); return cmd.sendResult(.{ .root = bc.nodeWriter(node, .{ .depth = params.depth orelse 3 }) }, .{});
} }
// https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-performSearch // https://chromedevtools.github.io/devtools-protocol/tot/DOM/#method-performSearch
@@ -610,6 +611,7 @@ test "cdp.dom: getBoxModel" {
try ctx.processMessage(.{ // Hacky way to make sure nodeId 0 exists in the registry try ctx.processMessage(.{ // Hacky way to make sure nodeId 0 exists in the registry
.id = 3, .id = 3,
.method = "DOM.getDocument", .method = "DOM.getDocument",
.params = .{ .depth = 3 },
}); });
try ctx.processMessage(.{ try ctx.processMessage(.{