function waitForElementToDisplay(selector, callback, checkFrequencyInMs = 100, timeoutInMs = 10000) { const startTimeInMs = Date.now(); if(!callback){ callback = () => document.querySelector(selector).style.display = 'none'; } (function loopSearch() { if (document.querySelector(selector) != null) { callback(); return; } setTimeout(function () { if (timeoutInMs && Date.now() - startTimeInMs > timeoutInMs){ return; } loopSearch(); }, checkFrequencyInMs); })(); }