From 4d0c9361654086c8365e3ba01db812563426392b Mon Sep 17 00:00:00 2001 From: Bryan Wilson Date: Wed, 19 Jul 2023 17:56:49 -0700 Subject: [PATCH 1/2] Catch and retry video module YT IFrame API ready errs Retry setting window.onYouTubeIframeAPIReady.resolve to JQuery Deferred obj .resolve up to 3 times before finally failing Log err message to console Catch and retry only TypeErrors which should result from .resolve TypeError This is direclty in edx-platform since I couldn't figure out how to override in the theme due to the webpack bundling that is done directly into VideoBlockPreview.js via add_webpack_to_frament in video_module.py ENG-97 --- .../xmodule/js/src/video/01_initialize.js | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/common/lib/xmodule/xmodule/js/src/video/01_initialize.js b/common/lib/xmodule/xmodule/js/src/video/01_initialize.js index 6051cc42862..5b0d6ca5cae 100644 --- a/common/lib/xmodule/xmodule/js/src/video/01_initialize.js +++ b/common/lib/xmodule/xmodule/js/src/video/01_initialize.js @@ -90,6 +90,7 @@ function(VideoPlayer, i18n, moment, _) { _youtubeApiDeferred = null, _oldOnYouTubeIframeAPIReady; + const setupOnYouTubeIframeAPIReadyMaxCalls=3; Initialize.prototype = methodsDict; @@ -165,14 +166,32 @@ function(VideoPlayer, i18n, moment, _) { // // If this global function is already defined, we store it first, and make // sure that it gets executed when our Deferred object is resolved. + let setupOnYouTubeIframeAPIReadyCallsCount = 0; + setupOnYouTubeIframeAPIReady = function() { + setupOnYouTubeIframeAPIReadyCallsCount++; + if (setupOnYouTubeIframeAPIReadyCallsCount > setupOnYouTubeIframeAPIReadyMaxCalls) { + throw new Error('Too many OnYouTubeIframeAPIReady retries after TypeError...giving up.'); + } + _oldOnYouTubeIframeAPIReady = window.onYouTubeIframeAPIReady || undefined; window.onYouTubeIframeAPIReady = function() { window.onYouTubeIframeAPIReady.resolve(); }; - window.onYouTubeIframeAPIReady.resolve = _youtubeApiDeferred.resolve; + try { + window.onYouTubeIframeAPIReady.resolve = _youtubeApiDeferred.resolve; + } catch (e) { + console.error('Error while trying to resolve the Deferred object responsible for calling OnYouTubeIframeAPIReady callbacks.'); + console.error(e); + if (e instanceof TypeError) { + setupOnYouTubeIframeAPIReady(); // Try again up to defined max calls. + } + else { + throw e; + } + } window.onYouTubeIframeAPIReady.done = _youtubeApiDeferred.done; if (_oldOnYouTubeIframeAPIReady) { From b1b36215f4dd5f591c6fc4d16d8388d2cd4cd9fb Mon Sep 17 00:00:00 2001 From: Bryan Wilson Date: Thu, 20 Jul 2023 10:35:35 -0700 Subject: [PATCH 2/2] additional console error msg for window.onYouTubeIframeAPIReady err --- common/lib/xmodule/xmodule/js/src/video/01_initialize.js | 1 + 1 file changed, 1 insertion(+) diff --git a/common/lib/xmodule/xmodule/js/src/video/01_initialize.js b/common/lib/xmodule/xmodule/js/src/video/01_initialize.js index 5b0d6ca5cae..1ff8b591b7f 100644 --- a/common/lib/xmodule/xmodule/js/src/video/01_initialize.js +++ b/common/lib/xmodule/xmodule/js/src/video/01_initialize.js @@ -184,6 +184,7 @@ function(VideoPlayer, i18n, moment, _) { window.onYouTubeIframeAPIReady.resolve = _youtubeApiDeferred.resolve; } catch (e) { console.error('Error while trying to resolve the Deferred object responsible for calling OnYouTubeIframeAPIReady callbacks.'); + console.error('window.onYouTubeIframeAPIReady is ' + window.onYouTubeIframeAPIReady); console.error(e); if (e instanceof TypeError) { setupOnYouTubeIframeAPIReady(); // Try again up to defined max calls.