1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-20 16:07:45 +01:00

limit getFormElements to 50

This commit is contained in:
Kyle Spearrin 2017-10-11 09:01:59 -04:00
parent fe73ffc21e
commit 44b65a212e

View File

@ -34,7 +34,7 @@
1. Populate isFirefox 1. Populate isFirefox
2. Remove isChrome and isSafari since they are not used. 2. Remove isChrome and isSafari since they are not used.
3. Unminify and format to meet Mozilla review requirements. 3. Unminify and format to meet Mozilla review requirements.
4. Remove button and limit input types from getFormElements query selector 4. Remove unnecessary input types from getFormElements query selector and limit number of elements returned.
*/ */
function collect(document, undefined) { function collect(document, undefined) {
@ -240,7 +240,7 @@
}); });
// get all the form fields // get all the form fields
var theFields = Array.prototype.slice.call(getFormElements(theDoc)).map(function (el, elIndex) { var theFields = Array.prototype.slice.call(getFormElements(theDoc, 50)).map(function (el, elIndex) {
var field = {}, var field = {},
opId = '__' + elIndex, opId = '__' + elIndex,
elMaxLen = -1 == el.maxLength ? 999 : el.maxLength; elMaxLen = -1 == el.maxLength ? 999 : el.maxLength;
@ -548,13 +548,14 @@
} }
// get all the form elements that we care about // get all the form elements that we care about
function getFormElements(theDoc) { function getFormElements(theDoc, limit) {
var els = []; var els = [];
try { try {
els = theDoc.querySelectorAll('input:not([type="hidden"]):not([type="submit"]):not([type="reset"])' + els = theDoc.querySelectorAll('input:not([type="hidden"]):not([type="submit"]):not([type="reset"])' +
':not([type="button"]):not([type="image"]):not([type="file"]), select'); ':not([type="button"]):not([type="image"]):not([type="file"]), select');
} catch (e) { } } catch (e) { }
return els;
return limit && els.length > limit ? els.slice(0, limit) : els;
} }
// focus the element and optionally restore its original value // focus the element and optionally restore its original value