You are probably correct.
Here’s an update…
Add a toggle element named dom_loaded to the layout.
Add this javascript that will check the toggle when the DOM is loaded:
window.addEventListener('DOMContentLoaded', (event) => {
dmx.parse("dom_loaded.check()")
});
Change the while condition to also make sure the toggle is checked: