Skip to content

Lightpanda: the headless browser designed for AI and automation

cdp: emit frameId on the document element, not the document node

Adrià Arrufatdcc90d60c986
diff --git a/src/server/cdp/Node.zig b/src/server/cdp/Node.zig
index 85c54f7cd..eaefba5e8 100644
--- a/src/server/cdp/Node.zig
+++ b/src/server/cdp/Node.zig
@@ -220,8 +220,9 @@ pub const Writer = struct {
try w.objectField("localName");
try w.write(element.getLocalName());
- // Chrome names the hosted frame on frame-owner elements; that's how
- // clients pair an <iframe> with its Page.frameAttached id.
+ // Chrome names the hosted frame on frame-owner elements and the own
+ // frame on the document element; that's how clients pair an <iframe>
+ // with its Page.frameAttached id.
if (element.is(IFrame)) |iframe| {
if (iframe.getContentDocument()) |document| {
if (document._frame) |child| {
@@ -229,17 +230,17 @@ pub const Writer = struct {
try w.write(&id.toFrameId(child._frame_id));
}
}
+ } else if (dom_node._parent) |dom_parent| {
+ if (dom_parent._type == .document) {
+ if (dom_parent.subtype(DOMNode.Document)._frame) |frame| {
+ try w.objectField("frameId");
+ try w.write(&id.toFrameId(frame._frame_id));
+ }
+ }
}
} else {
try w.objectField("localName");
try w.write("");
-
- if (dom_node._type == .document) {
- if (dom_node.subtype(DOMNode.Document)._frame) |frame| {
- try w.objectField("frameId");
- try w.write(&id.toFrameId(frame._frame_id));
- }
- }
}
try w.objectField("nodeType");
diff --git a/src/server/cdp/domains/dom.zig b/src/server/cdp/domains/dom.zig
index 1a6a92d7d..ac2028414 100644
--- a/src/server/cdp/domains/dom.zig
+++ b/src/server/cdp/domains/dom.zig
@@ -1343,13 +1343,13 @@ test "cdp.dom: getFrameOwner returns the owner iframe element" {
.frameId = &id.toFrameId(child._frame_id),
} }, .{ .id = 11 });
- // So does a document, for its own frame.
- const child_document = try bc.node_registry.register(child.window._document.asNode());
+ // So does the document element, for its own frame.
+ const child_html = try bc.node_registry.register(child.window._document.getDocumentElement().?.asNode());
try ctx.processMessage(.{ .id = 12, .method = "DOM.describeNode", .sessionId = "SID-X", .params = .{
- .backendNodeId = child_document.id,
+ .backendNodeId = child_html.id,
} });
try ctx.expectSentResult(.{ .node = .{
- .nodeName = "#document",
+ .localName = "html",
.frameId = &id.toFrameId(child._frame_id),
} }, .{ .id = 12 });