diff --git a/src/browser/webapi/Document.zig b/src/browser/webapi/Document.zig index 3af6a59b..3313bcdf 100644 --- a/src/browser/webapi/Document.zig +++ b/src/browser/webapi/Document.zig @@ -491,7 +491,13 @@ pub fn elementsFromPoint(self: *Document, x: f64, y: f64, page: *Page) ![]const return result.items; } -pub fn getDocType(_: *const Document) ?*DocumentType { +pub fn getDocType(self: *Document) ?*Node { + var tw = @import("TreeWalker.zig").Full.init(self.asNode(), .{}); + while (tw.next()) |node| { + if (node._type == .document_type) { + return node; + } + } return null; } diff --git a/src/browser/webapi/HTMLDocument.zig b/src/browser/webapi/HTMLDocument.zig index 18aa9f56..8082ac67 100644 --- a/src/browser/webapi/HTMLDocument.zig +++ b/src/browser/webapi/HTMLDocument.zig @@ -215,6 +215,15 @@ pub fn getDocType(self: *HTMLDocument, page: *Page) !*DocumentType { if (self._document_type) |dt| { return dt; } + + var tw = @import("TreeWalker.zig").Full.init(self.asNode(), .{}); + while (tw.next()) |node| { + if (node._type == .document_type) { + self._document_type = node.as(DocumentType); + return self._document_type.?; + } + } + self._document_type = try page._factory.node(DocumentType{ ._proto = undefined, ._name = "html",