From 1c0a644a35792646d81efc69c279cce28bdc631e Mon Sep 17 00:00:00 2001 From: Joey Parrish Date: Mon, 4 Dec 2017 12:56:31 -0800 Subject: [PATCH] Fix weird page-load race on IE 11 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 51263249 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 --- demo/main.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/demo/main.js b/demo/main.js index 9ff2ff3b02..519ac8086f 100644 --- a/demo/main.js +++ b/demo/main.js @@ -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(); }