Lightpanda: the headless browser designed for AI and automation
webapi: list fieldset, object and output in form.elements
Jay Hemnanif7e926b363f5
diff --git a/src/browser/tests/element/html/form.html b/src/browser/tests/element/html/form.htmlindex a8df7c3de..4eddb14ae 100644--- a/src/browser/tests/element/html/form.html+++ b/src/browser/tests/element/html/form.html@@ -750,6 +750,29 @@}</script>+<form id="listed_form">+ <fieldset name="fs">+ <input name="q" value="1">+ </fieldset>+ <output name="out">x</output>+ <object name="obj"></object>+</form>+<fieldset form="listed_form" name="outside"></fieldset>++<script id="elements_includes_listed_elements">+{+ // fieldset, output and object are listed elements, but none of them submits+ const form = $('#listed_form')+ testing.expectEqual('FIELDSET,INPUT,OUTPUT,OBJECT,FIELDSET', Array.from(form.elements).map((e) => e.tagName).join(','))+ testing.expectEqual(5, form.length)+ testing.expectEqual('outside', form.elements[4].name)+ testing.expectEqual('FIELDSET', form.elements.fs.tagName)+ testing.expectEqual(form.elements.fs, form.fs)+ testing.expectEqual(form.elements[2], form[2])+ testing.expectEqual('q=1', Array.from(new FormData(form)).map(([k, v]) => k + '=' + v).join('&'))+}+</script>+<form id="button_type_form"><button type="invalid" id="invalid_type"></button><button type="SUBMIT" id="upper_type"></button>diff --git a/src/browser/webapi/collections/node_live.zig b/src/browser/webapi/collections/node_live.zigindex 28dfd9c36..6ea793d8d 100644--- a/src/browser/webapi/collections/node_live.zig+++ b/src/browser/webapi/collections/node_live.zig@@ -78,7 +78,7 @@ const Filters = union(Mode) {selected_options,links,anchors,- form: struct { form: *Form, form_id: ?[]const u8, image_buttons: bool, outputs: bool },+ form: struct { form: *Form, form_id: ?[]const u8, image_buttons: bool, outputs: bool, listed: bool },document_named: []const u8,fn TypeOf(comptime mode: Mode) type {@@ -370,7 +370,11 @@ pub fn NodeLive(comptime mode: Mode) type {},.form => {const el = node.is(Element) orelse return false;- const is_control = isFormControl(el) or (self._filter.outputs and el.getTag() == .output);+ const is_control = isFormControl(el) or switch (el.getTag()) {+ .output => self._filter.outputs or self._filter.listed,+ .fieldset, .object => self._filter.listed,+ else => false,+ };if (is_control == false) {return false;}diff --git a/src/browser/webapi/element/html/Form.zig b/src/browser/webapi/element/html/Form.zigindex 47cfc8f48..084135ab5 100644--- a/src/browser/webapi/element/html/Form.zig+++ b/src/browser/webapi/element/html/Form.zig@@ -98,7 +98,7 @@ pub fn setMethod(self: *Form, method: []const u8, frame: *Frame) !void {}pub fn getElements(self: *Form, frame: *Frame) !*HTMLFormControlsCollection {- const node_live = self.iterator(.{ .image_buttons = false }, frame);+ const node_live = self.iterator(.{ .image_buttons = false, .listed = true }, frame);const elements = try frame._factory.chained(.{node_live.htmlCollectionValue(),HTMLFormControlsCollection{ ._proto = undefined },@@ -110,6 +110,7 @@ pub fn getElements(self: *Form, frame: *Frame) !*HTMLFormControlsCollection {const IteratorOpts = struct {image_buttons: bool = true, // form.elements doesn't incude input type=imageoutputs: bool = false, // only reset() wants <output>+ listed: bool = false, // form.elements also lists <fieldset>, <object> and <output>};pub fn iterator(self: *Form, opts: IteratorOpts, frame: *Frame) NodeLive(.form) {@@ -119,7 +120,7 @@ pub fn iterator(self: *Form, opts: IteratorOpts, frame: *Frame) NodeLive(.form)elseself.asNode(); // No ID: walk only form subtree (no external controls possible)- return NodeLive(.form).init(root, .{ .form = self, .form_id = form_id, .image_buttons = opts.image_buttons, .outputs = opts.outputs }, frame);+ return NodeLive(.form).init(root, .{ .form = self, .form_id = form_id, .image_buttons = opts.image_buttons, .outputs = opts.outputs, .listed = opts.listed }, frame);}fn getAction(self: *Form, frame: *Frame) ![]const u8 {@@ -287,7 +288,7 @@ pub fn ownerOf(element: *Element, frame: *Frame) ?*Form {}fn getAtIndex(self: *Form, index: usize, frame: *Frame) ?*Element {- var it = self.iterator(.{ .image_buttons = false }, frame);+ var it = self.iterator(.{ .image_buttons = false, .listed = true }, frame);return it.getAtIndex(index, frame);}@@ -299,7 +300,7 @@ fn namedItem(self: *Form, name: []const u8, frame: *Frame) !?HTMLFormControlsCol}var first: ?*Element = null;- var it = self.iterator(.{ .image_buttons = false }, frame);+ var it = self.iterator(.{ .image_buttons = false, .listed = true }, frame);while (it.next()) |element| {if (HTMLFormControlsCollection.matchesName(element, name) == false) {continue;@@ -354,7 +355,7 @@ pub const JsApi = struct {return error.NotHandled;}- var it = self.iterator(.{ .image_buttons = false }, frame);+ var it = self.iterator(.{ .image_buttons = false, .listed = true }, frame);while (it.next()) |element| {if (HTMLFormControlsCollection.matchesName(element, field_name)) {return js.v8.DontEnum;