I am trying to auto-populate some input fields when the page fully loads. However, there are other scripts I can't control which change the page. So if I try to do anything like these options, I get element not found.
window.addEventListener("load", (event) => {
init();
});
or
if (document.readyState !== "loading") {
init();
} else {
document.addEventListener("DOMContentLoaded", function () {
init();
});
}
When can I call init()
so that all other scripts have been executed (aka I won't get element not found error)? Right now, I am using setTimeOut() which obviously isn't ideal.
References: