wait for element to load
loading = setInterval(function () { if (document.getElementById("myElement")) { // Element Has Loaded, Put your code here! clearInterval(loading); } }, 100); // Checks every 100ms(0.1s)
wait for element to be loaded
function waitForElementLoad(selector) { return new Promise((resolve, reject) => { let el = document.querySelector(selector); if (el) { resolve(el); return; } new MutationObserver((mutationRecords, observer) => { // Query for elements matching the specified selector Array.from(document.querySelectorAll(selector)).forEach((element) => { resolve(element); //Once we have resolved we don't need the observer anymore. observer.disconnect(); }); }).observe(document.documentElement, { childList: true, subtree: true, }); }); }