Skip to content

Commit

Permalink
Fix weird page-load race on IE 11
Browse files Browse the repository at this point in the history
Sometimes, on IE 11, the demo app fails to load because "shaka" is
undefined when shakaDemo.init() is called.  This seems to have been
introduced in 5126324 when we started deferring script loading.
This bug has not appeared in a release version yet.

It seems that IE 11 sets the readyState on the document at the wrong
time when scripts are deferred.  Edge and Chrome both do the right
thing.

This came up during debugging while working on #1111, but this fix is
not part of the fix for #1111.

Change-Id: Ia42466acdced7ca67fed5a6e8270620b7d8dcd50
  • Loading branch information
joeyparrish committed Dec 4, 2017
1 parent b98ce99 commit 1c0a644
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion demo/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,5 +663,17 @@ if (document.readyState == 'loading' ||
window.addEventListener('load', shakaDemo.init);
}
} else {
shakaDemo.init();
/**
* Poll for Shaka Player on window. On IE 11, the document is "ready", but
* there are still deferred scripts being loaded. This does not occur on
* Chrome or Edge, which set the document's state at the correct time.
*/
var pollForShakaPlayer = function() {
if (window.shaka) {
shakaDemo.init();
} else {
setTimeout(pollForShakaPlayer, 100);
}
};
pollForShakaPlayer();
}

0 comments on commit 1c0a644

Please sign in to comment.