Merge pull request #928 from keepassxreboot/fix/165_mo

Fix MutationObserver reinit
This commit is contained in:
Sami Vänttinen 2020-07-08 14:01:53 +03:00 committed by GitHub
commit c88ee5bbfc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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) {