From 1f247077d08a4b09c614d9b9437aa2646d32ff75 Mon Sep 17 00:00:00 2001 From: varjolintu Date: Sun, 29 Mar 2020 14:01:18 +0300 Subject: [PATCH] Ignore main HTML element from MutationObserver --- .../content/keepassxc-browser.js | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/keepassxc-browser/content/keepassxc-browser.js b/keepassxc-browser/content/keepassxc-browser.js index 9308283..b5f6231 100755 --- a/keepassxc-browser/content/keepassxc-browser.js +++ b/keepassxc-browser/content/keepassxc-browser.js @@ -705,8 +705,17 @@ kpxcObserverHelper.getInputs = function(target) { return inputs; }; +// Gets of generates an ID for the element kpxcObserverHelper.getId = function(target) { - return target.classList.length === 0 ? target.id : target.classList; + if (target.classList.length > 0) { + return target.classlist; + } + + if (target.id !== '') { + return target.id; + } + + return `kpxc${target.clientTop}${target.clientLeft}${target.clientWidth}${target.clientHeight}`; }; kpxcObserverHelper.ignoredElement = function(target) { @@ -858,8 +867,11 @@ kpxc.initObserver = function() { } for (const mut of mutations) { - // Skip text nodes - if (mut.target.nodeType === Node.TEXT_NODE) { + // Skip text nodes and base HTML element + if (mut.target.nodeType === Node.TEXT_NODE + || mut.target.nodeName === 'HTML' + || mut.target.nodeName === 'LINK' + || mut.target.nodeName === 'HEAD') { continue; } @@ -868,8 +880,9 @@ kpxc.initObserver = function() { // Handle attributes only if CSS display is modified if (mut.type === 'attributes') { - // Check if some class is changed that folds a form or input field(s) - if (mut.attributeName === 'class' && mut.target.querySelectorAll('form input').length > 0) { + // Check if some class is changed that holds a form or input field(s). Ignore large forms. + const formInput = mut.target.querySelector('form input'); + if (mut.attributeName === 'class' && formInput !== null && formInput.form.length < 20) { kpxc.initCredentialFields(true); continue; }