Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/cdp/Node.zig
Original file line number Diff line number Diff line change
Expand Up @@ -565,13 +565,13 @@ test "cdp Node: Writer" {
.localName = "div",
.childNodeCount = 1,
.parentId = 3,
.children = &.{ .{
.children = &.{.{
.nodeId = 6,
.localName = "a",
.childNodeCount = 0,
.parentId = 5,
}}
}
} } }, json);
}},
} },
} }, json);
}
}
14 changes: 8 additions & 6 deletions src/cdp/domains/dom.zig
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +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 {
// depth: ?u32 = null,
// pierce: ?bool = null,
// })) orelse return error.InvalidParams;
const Params = struct {
// CDP documentation implies that 0 isn't valid, but it _does_ work in Chrome
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, .{}) }, .{});
return cmd.sendResult(.{ .root = bc.nodeWriter(node, .{ .depth = params.depth }) }, .{});
}

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

try cmd.sendEvent("DOM.setChildNodes", .{
.parentId = node.id,
.nodes = bc.nodeWriter(node, .{.depth = params.depth, .exclude_root = true}),
.nodes = bc.nodeWriter(node, .{ .depth = params.depth, .exclude_root = true }),
}, .{
.session_id = session_id,
});
Expand Down