Can't apply container size when open or refresh page

It’s not entirely clear what your problem is. What does your script look like with three.js?
But I guess you don’t have a function onWindowResize(). Have a look at some examples from the collection, like RaycastingToLine.