Skip to content

Lightpanda: the headless browser designed for AI and automation

minor, webapi: Prevent outerHTML of document's element's from being written

Karl Seguine4387bf7faa0
diff --git a/src/browser/webapi/Element.zig b/src/browser/webapi/Element.zig
index bfb758281..8cf7ce2c9 100644
--- a/src/browser/webapi/Element.zig
+++ b/src/browser/webapi/Element.zig
@@ -466,6 +466,11 @@ pub fn setOuterHTML(self: *Element, html: []const u8, frame: *Frame) !void {
const node = self.asNode();
const parent = node._parent orelse return;
+ // The parent of a documentElement is the Document, which cannot be modified.
+ if (parent._type == .document) {
+ return error.NoModificationAllowed;
+ }
+
frame.domChanged();
if (html.len > 0) {
const fragment = (try Node.DocumentFragment.init(frame)).asNode();