Wait until Canvas gets created in DOM

Hi all,
I have this code:

    canvas2 = mCreateCanvas(m4.windowWidth, m4.windowHeight, m4.WEBGL);
    m4.setAttributes('antialias', true);
    glCanvas = document.getElementById('defaultCanvas0').getContext('webgl');


which sometimes fails at that line:


because glCanvas is not defined. How can I wait until Canvas2 is defined in the DOM?

Aren’t you doing that stuff inside callback setup()? :no_mouth:

Sure it’s in the setup(). Anyway your solution to my other post pretty solves the issue