mirror of
https://github.com/keepassxreboot/keepassxc-browser.git
synced 2026-03-11 08:54:43 +00:00
Wrap IntersectionObserver inside try/catch
This commit is contained in:
parent
009a797493
commit
2dde0dc4f3
1 changed files with 20 additions and 14 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue