If you remove apiIsReady = true; then it creates an infinity loop. And that’s why, the browser will freeze.
Without apiIsReady set to true, you are creating loop that adds new value to array with each iteration of that same array.
You could check if array contains that value, if not, then push it
function load_all_waitting_inits()
{
for(var opts of waitting_inits) // new values are being added with each iteration, preventing loop to end
{
init(opts); // parse value of waitting_inits array
}
}
function init(opts) {
loadPlayer();
if (apiIsReady) { // always false
addVideo(opts.video, opts.playerVars || {});
}
else
{
waitting_inits.push(opts) // here you are adding values infinitely
}
}
<off-topic>
Sorry, but it is cross posting. Though it may not be against any “rules” it is not good net etiquette. It is a discourtesy to members of both forums. Perhaps not much of a problem for short easy replies, but I imagine if a member went through the trouble of putting together a more extensive reply they would be less than pleased if they discovered that someone else had already gone through the same trouble at another forum.
Somewhat better net etiquette would be to cross reference the topics. eg. “I’ve also asked this question here” so that members could follow both topics and know where progress was at. I say “somewhat better” because it is arguable that asking people to visit two places in order to know what is going on could be a big ask.
IMHO a much better approach is to post in one or the other, and if it fails to get any traction only then post the same to another.
</off-topic>
To get back on-topic, thank you for posting the solution here.