diff --git a/src/content/content_script.js b/src/content/content_script.js index e9554f6..370dcec 100644 --- a/src/content/content_script.js +++ b/src/content/content_script.js @@ -24,6 +24,7 @@ const { getTabData, getInputs, addInputListener, portSetup, isInFrame, addFormEl const contentOnMessage = require('./events/contentOnMessage'); const { loadFromLocalStorage, saveToLocalStorage } = require('../localStorage'); const storeLog = require('../partials/storeLog'); +const delay = require('../partials/delay'); let tabData; let storage; @@ -36,7 +37,19 @@ const contentScriptRun = async () => { } try { - tabData = await getTabData(); + let tabAttempt = 0; + + do { + tabData = await getTabData(); + + if (tabData?.status === 'complete') { + break; + } + + tabAttempt++; + await delay(() => {}, 200); + } + while (tabAttempt < 10) } catch (e) { throw new Error(e); } diff --git a/src/content/functions/pageLoadComplete.js b/src/content/functions/pageLoadComplete.js index 4db507d..bc0fe18 100644 --- a/src/content/functions/pageLoadComplete.js +++ b/src/content/functions/pageLoadComplete.js @@ -17,33 +17,14 @@ // along with this program. If not, see // -const { loadFromLocalStorage, saveToLocalStorage } = require('../../localStorage'); -const storeLog = require('../../partials/storeLog'); +const addInputListener = require('../functions/addInputListener'); +const getInputs = require('../functions/getInputs'); +const addFormElementsNumber = require('../functions/addFormElementsNumber'); +const getFormElements = require('../functions/getFormElements'); const pageLoadComplete = async tabID => { - let storage; - const activeElement = document?.activeElement; - - if (!activeElement) { - return false; - } - - const twofasInput = activeElement.getAttribute('data-twofas-input'); - - if (!twofasInput) { - return false; - } - - try { - storage = await loadFromLocalStorage([`tabData-${tabID}`, 'extensionID']); - } catch (err) { - await storeLog('error', 43, err, storage[`tabData-${tabID}`]?.url); - } - - storage[`tabData-${tabID}`].lastFocusedInput = twofasInput; - - return saveToLocalStorage({ [`tabData-${tabID}`]: storage[`tabData-${tabID}`] }) - .catch(err => storeLog('error', 44, err, storage[`tabData-${tabID}`]?.url)); + addInputListener(getInputs(), tabID); + addFormElementsNumber(getFormElements()); }; module.exports = pageLoadComplete; diff --git a/src/content/observer/observerConstants/notObservedAttributes.js b/src/content/observer/observerConstants/notObservedAttributes.js index dc4f272..ab097a9 100644 --- a/src/content/observer/observerConstants/notObservedAttributes.js +++ b/src/content/observer/observerConstants/notObservedAttributes.js @@ -23,6 +23,7 @@ const notObservedAttributes = [ 'data-twofas-input-listener', // CUSTOM 'data-ng-animate', + 'data-submitting', // GLOBAL ATTRIBUTES 'href', 'acceskey',