From 1c86186f40cae1de01862fe853df5f8b99be45de Mon Sep 17 00:00:00 2001 From: varjolintu Date: Wed, 8 Jul 2020 08:28:55 +0300 Subject: [PATCH] Fix MutationObserver reinit --- keepassxc-browser/content/keepassxc-browser.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/keepassxc-browser/content/keepassxc-browser.js b/keepassxc-browser/content/keepassxc-browser.js index 1a1d6fd..80488ad 100755 --- a/keepassxc-browser/content/keepassxc-browser.js +++ b/keepassxc-browser/content/keepassxc-browser.js @@ -875,6 +875,7 @@ kpxc.p = null; kpxc.url = null; kpxc.submitUrl = null; kpxc.credentials = []; +kpxc.observer = null; const initContentScript = async function() { try { @@ -889,11 +890,12 @@ const initContentScript = async function() { return; } - if (kpxc.settings.useObserver) { + if (kpxc.settings.useObserver && !kpxc.observer) { kpxc.initObserver(); } await kpxc.updateDatabaseState(); + kpxc.switchIcons(); await kpxc.initCredentialFields(); // Retrieve submitted credentials if available. @@ -920,7 +922,7 @@ const initContentScript = async function() { kpxc.rememberCredentials(creds.username, creds.password, creds.url, creds.oldCredentials); } } catch (err) { - console.log('Error: Cannot load extension settings'); + console.log('initContentScript error: ', err); } }; @@ -936,7 +938,7 @@ kpxc.init = function() { // Detects DOM changes in the document kpxc.initObserver = function() { - const observer = new MutationObserver(function(mutations, obs) { + kpxc.observer = new MutationObserver(function(mutations, obs) { if (document.visibilityState === 'hidden' || kpxcUI.mouseDown) { return; } @@ -981,7 +983,7 @@ kpxc.initObserver = function() { // define what element should be observed by the observer // and what types of mutations trigger the callback - observer.observe(document, { + kpxc.observer.observe(document, { subtree: true, attributes: true, childList: true, @@ -2022,12 +2024,8 @@ kpxcEvents.clearCredentials = function() { }; kpxcEvents.triggerActivatedTab = async function() { - // Doesn't run a second time because of _called.initCredentialFields set to true kpxc.init(); - await kpxc.updateDatabaseState(); - kpxc.switchIcons(); - // initCredentialFields calls also "retrieve_credentials", to prevent it // check of init() was already called if (_called.initCredentialFields && (kpxc.url && kpxc.submitUrl) && kpxc.settings.autoRetrieveCredentials) {