From 32fdea0206f29f1b790a02cb05dbfb1954bc24c2 Mon Sep 17 00:00:00 2001 From: Mike Date: Mon, 31 Oct 2022 22:09:24 -0700 Subject: [PATCH] fix(extension) fires JS event upon editing input fields (#575) --- passExtension/passProcessor.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/passExtension/passProcessor.js b/passExtension/passProcessor.js index 5f9c746..56da5f7 100644 --- a/passExtension/passProcessor.js +++ b/passExtension/passProcessor.js @@ -1,5 +1,16 @@ var PassProcessor = function() {}; +/** + * Dispatches a synthetic event of a given type on a given element. + * @param {string} type the event type to dispatch + * @param {Element} el the element upon which to dispatch it + */ +var dispatchEvent = function(type, el) { + var evt = document.createEvent('Event'); + evt.initEvent(type, true, true); + el.dispatchEvent(evt); +}; + PassProcessor.prototype = { run: function(arguments) { var url @@ -19,6 +30,8 @@ finalize: function(arguments) { if (passwordElement) { passwordElement.setAttribute('value', arguments["password"]) passwordElement.value = arguments["password"] + dispatchEvent("input", passwordElement) + dispatchEvent("change", passwordElement) } } @@ -27,6 +40,8 @@ finalize: function(arguments) { if (usernameElement) { usernameElement.setAttribute('value', arguments["username"]) usernameElement.value = arguments["username"] + dispatchEvent("input", usernameElement) + dispatchEvent("change", usernameElement) } } }