Skip to content

Commit 2db4ecd

Browse files
committed
cdp: add DOM.getFrameOwner
1 parent bc82023 commit 2db4ecd

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/cdp/domains/dom.zig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub fn processMessage(cmd: anytype) !void {
3939
getContentQuads,
4040
getBoxModel,
4141
requestChildNodes,
42+
getFrameOwner,
4243
}, cmd.input.action) orelse return error.UnknownMethod;
4344

4445
switch (action) {
@@ -55,6 +56,7 @@ pub fn processMessage(cmd: anytype) !void {
5556
.getContentQuads => return getContentQuads(cmd),
5657
.getBoxModel => return getBoxModel(cmd),
5758
.requestChildNodes => return requestChildNodes(cmd),
59+
.getFrameOwner => return getFrameOwner(cmd),
5860
}
5961
}
6062

@@ -461,6 +463,24 @@ fn requestChildNodes(cmd: anytype) !void {
461463
return cmd.sendResult(null, .{});
462464
}
463465

466+
fn getFrameOwner(cmd: anytype) !void {
467+
const params = (try cmd.params(struct {
468+
frameId: []const u8,
469+
})) orelse return error.InvalidParams;
470+
471+
const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded;
472+
const target_id = bc.target_id orelse return error.TargetNotLoaded;
473+
if (std.mem.eql(u8, target_id, params.frameId) == false) {
474+
return cmd.sendError(-32000, "Frame with the given id does not belong to the target.");
475+
}
476+
477+
const page = bc.session.currentPage() orelse return error.PageNotLoaded;
478+
const doc = parser.documentHTMLToDocument(page.window.document);
479+
480+
const node = try bc.node_registry.register(parser.documentToNode(doc));
481+
return cmd.sendResult(.{ .nodeId = node.id, .backendNodeId = node.id }, .{});
482+
}
483+
464484
const testing = @import("../testing.zig");
465485

466486
test "cdp.dom: getSearchResults unknown search id" {

0 commit comments

Comments
 (0)