From 42b2757967307a45a039ca44ba7b1ff302e947cc Mon Sep 17 00:00:00 2001 From: Erayd Date: Sun, 20 Oct 2019 05:37:44 +1300 Subject: [PATCH] Autofill: re-set the field value if necessary (#182) --- src/inject.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/inject.js b/src/inject.js index 2e9aedb..0a14e96 100644 --- a/src/inject.js +++ b/src/inject.js @@ -409,6 +409,7 @@ } // Set the field value + let initialValue = el.value || el.getAttribute("value"); el.setAttribute("value", value); el.value = value; @@ -417,6 +418,13 @@ el.dispatchEvent(new Event(eventName, { bubbles: true })); } + // re-set value if unchanged after firing post-fill events + // (in case of sabotage by the site's own event handlers) + if ((el.value || el.getAttribute("value")) === initialValue) { + el.setAttribute("value", value); + el.value = value; + } + // Finally unfocus the element el.dispatchEvent(new Event("blur", { bubbles: true })); return true;