From 2dde0dc4f30e390490207975e41d7f832c0c2db1 Mon Sep 17 00:00:00 2001 From: varjolintu Date: Tue, 23 Apr 2019 09:29:18 +0300 Subject: [PATCH] Wrap IntersectionObserver inside try/catch --- keepassxc-browser/content/pwgen.js | 34 ++++++++++++++++++------------ 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/keepassxc-browser/content/pwgen.js b/keepassxc-browser/content/pwgen.js index 157769e..f06ceaa 100644 --- a/keepassxc-browser/content/pwgen.js +++ b/keepassxc-browser/content/pwgen.js @@ -24,22 +24,26 @@ const DOMRectToArray = function(domRect) { * - intersectionRatio > 0 -> shown * - isIntersecting === true -> shown */ -kpxcPassword.observer = new IntersectionObserver((entries) => { - for (const entry of entries) { - const rect = DOMRectToArray(entry.boundingClientRect); +try { + kpxcPassword.observer = new IntersectionObserver((entries) => { + for (const entry of entries) { + const rect = DOMRectToArray(entry.boundingClientRect); - if ((entry.intersectionRatio === 0 && !entry.isIntersecting) || (rect.some(x => x < -10))) { - kpxcPassword.icon.style.display = 'none'; - } else if (entry.intersectionRatio > 0 && entry.isIntersecting) { - kpxcPassword.icon.style.display = 'block'; + if ((entry.intersectionRatio === 0 && !entry.isIntersecting) || (rect.some(x => x < -10))) { + kpxcPassword.icon.style.display = 'none'; + } else if (entry.intersectionRatio > 0 && entry.isIntersecting) { + kpxcPassword.icon.style.display = 'block'; - // Wait for possible DOM animations - setTimeout(() => { - kpxcPassword.setIconPosition(kpxcPassword.icon, entry.target); - }, 500); + // Wait for possible DOM animations + setTimeout(() => { + kpxcPassword.setIconPosition(kpxcPassword.icon, entry.target); + }, 500); + } } - } -}); + }); +} catch (err) { + console.log(err); +} kpxcPassword.init = function() { if ('initPasswordGenerator' in _called) { @@ -55,7 +59,9 @@ kpxcPassword.initField = function(field, inputs, pos) { } // Observer the visibility - kpxcPassword.observer.observe(field); + if (kpxcPassword.observer) { + kpxcPassword.observer.observe(field); + } if (field.getAttribute('kpxc-password-generator')) { return;