Skip to main content
Adding "IntersectionObserver" and "mutation-observers" as OP's objective and troubleshooting.
Link
Source Link

Javascript IntersectionObserver on Inactive Tab?

I tried to use IntersectionObserver to check, when an element (button) is visible.

But when i tab out, so the tab is inactive, he doesnt see it anymore. When i tab in, he sends the console.log found instantly.

Any ideas, if there is a way, to check if the button is visible

const observer = new IntersectionObserver(([entry]) => { if (entry.isIntersecting) { console.log('found') }, { root: null, threshold: 0.1, // set offset 0.1 means trigger if atleast 10% of element in viewport }) observer.observe(document.querySelector(el)); 

I also tried MutationObserver but that cannot check if the button is in view. Just checking if there is code in background. And when its one time there, its there forever, also when its invisible than.

I just want to check if the button can be clicked right now, nothing more. But with MutationObserver he spams found, cause he found the code in background, also when the button is not in view.

I tried to search for someone with the same problem. Also tried mutationObserver but thats not the same.