@kjacobs ah yes, many features of the host products are actually loaded asynchronously. As such, executing code on load may get you stuck in a race condition.
If you want to resolve this, you will have to determine which element you require to be available and create logic to wait for this element to be available (I haven’t tested this code, I’m writing it on the fly):
function waitForElement(selector, callback) {
var count = 0;
var interval = window.setInterval(function() {
count++;
if (count > 10) {
callback(new Error('timeout'));
} else if (document.querySelectorAll(selector).length > 0) {
window.clearInterval(interval);
callback();
}
}, 500);
}
waitForElement('#myElementId', function (err) {
if (!err) {
console.log('the element is available!');
} else {
console.log('the element is NOT available after 5 seconds');
}
});
You can also use 3rd party libraries like arrive.