The html loads fine in chrome, and sending the update command with a proper string results in the template running and everything flows according to plan.
But when loading the template in casparcg, when update() is called the elements it is trying to change values don’t exist yet, and the template crashes out or does not update the elements.
I’ve come to this conclusion logging variables to console, and they are undefined then update() tries to access them.
Any way to avoid this situation?
setTimeout’ing the insertion code to only run after 2000ms fixes this, but is no solution.
I am a novice JavaScript programmer, still trying to figure out my way trough it. But I think I read somewhere, that there is an event called “window.loaded” or something similar, that you can subscribe to and that gets fired after the page has finished loading. That should do the trick.
It’s hard to help without you posting your code. My guess is that you are defining update() before the element exits, move your update() to a <script> tag just before </body> or wrap update/play/stop() etc… in:
window.addEventListener('DOMContentLoaded', function() {
// ORIGINAL CODE HERE
});