Accessing "this.app" from external js script

This question is similar to [SOLVED] Cannot access pc.app on application startup

Turns out setInterval works as I thought, but still looking for something cleaner.

//playcanvas is loaded in an iframe, so "window" refers to the window inside the iframe, aka the playcanvas app
window.addEventListener("DOMContentLoaded",function(){
        console.log("playcanvas's index.html is loaded");
        var pcReadyTrigger = setInterval(function(){
                if(typeof document.getElementById("playcanvas-iframe").contentWindow.window.pc !== 'undefined'){
                        clearInterval(pcReadyTrigger);
                        afterPcReady();
                }
        }, 100); //wait 100ms and check if pc is loaded again.
});

function afterPcReady(){
        var app1 = document.getElementById("playcanvas-iframe").contentWindow.window.pc.Application.getApplication();
        console.log(app1);
}