click() only works after setTimeout, but can’t find the dependency
On a mobile version of a webpage (really just if (window.innerWidth <= 1024){}
), I have a script to run a click() method on an element (a fullscreen icon) after the user clicks on an image. It all works as expected when I have a setTimeout(()=>element.click()}, 600)
. When I remove the timeout or set it to shorter wait times (100ms <= 500ms), it “works”, but the visuals aren’t correct. I speculate something needs to load / run before the click() can be run, and I want to put an eventListener or another MutationObserve on it. But I can’t find any difference in document.body before and after the timeout. What am I missing here?
How to persist MutationObserver after window.location change?
Lets say I am observing the document
using MutationObserver
: