the heuristics may change to detect multiple * "forms" (e.g. registration and login) on one page with a
. * * @param {HTMLElement} aDocumentRoot * @param {object} aOptions * @param {boolean} [aOptions.ignoreForm = false] * True to always use owner document as the `form` * @return {formLike} * @throws Error if aDocumentRoot is null */ createFromDocumentRoot(aDocumentRoot, aOptions = {}) { if (!aDocumentRoot) { throw new Error("createFromDocumentRoot: aDocumentRoot is null"); } let formLike = { action: aDocumentRoot.baseURI, autocomplete: "on", ownerDocument: aDocumentRoot.ownerDocument, rootElement: aDocumentRoot, }; // FormLikes can be created when fields are inserted into the DOM. When // many, many fields are inserted one after the other, we create many // FormLikes, and computing the elements list becomes more and more // expensive. Making the elements list lazy means that it'll only // be computed when it's eventually needed (if ever). ChromeUtils.defineLazyGetter(formLike, "elements", function () { let elements = []; for (let el of aDocumentRoot.querySelectorAll( "input, select, textarea" )) { // Exclude elements inside the rootElement that are already in a as // they will be handled by their own FormLike. if (!el.form || aOptions.ignoreForm) { elements.push(el); } } return elements; }); this._addToJSONProperty(formLike); return formLike; }, /** * Create a FormLike object from an //,