Maybe you can use addOnLoad, it's a javascript funtion that executes when the client is completely loaded. An example is: mx.addOnLoad(function() { console.log("You can use client functionality now"); });
You can find more here: https://apidocs.rnd.mendix.com/9/client/mx.html
If this does not work, you can also set a timeout to let the function run later.