From eb225a83cb079d9be359f8239732642425616206 Mon Sep 17 00:00:00 2001 From: Matthieu Wipliez <89922776+github-matthieu-wipliez@users.noreply.github.com> Date: Mon, 23 Dec 2024 16:47:01 +0100 Subject: [PATCH] Autoplay detection update: ignore NotSupportedError exceptions (#12603) * Ignore NotSupportedError exceptions in autoplay detection This error is caused by a Content Security Policy that disables data: scheme for media URLs. Before this PR, this error would cause autoplay to be disabled; now, if this error is raised it has the same effect as disabling autoplay detection. * Remove warning that has been addressed by #11822 --- libraries/autoplayDetection/autoplay.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libraries/autoplayDetection/autoplay.js b/libraries/autoplayDetection/autoplay.js index 3ca4c4a8d11..4b70145539a 100644 --- a/libraries/autoplayDetection/autoplay.js +++ b/libraries/autoplayDetection/autoplay.js @@ -1,7 +1,6 @@ let autoplayEnabled = null; /** - * DEVELOPER WARNING: IMPORTING THIS LIBRARY MAY MAKE YOUR ADAPTER NO LONGER COMPATIBLE WITH APP PUBLISHERS USING WKWEBVIEW * Note: this function returns true if detection is not done yet. This is by design: if autoplay is not allowed, * the call to video.play() will fail immediately, otherwise it may not terminate. * @returns true if autoplay is not forbidden @@ -41,8 +40,12 @@ function startDetection() { // if the video is played on a WebView with playsinline = false, this stops the video, to prevent it from being displayed fullscreen videoElement.src = ''; }) - .catch(() => { - autoplayEnabled = false; + .catch((error) => { + if (error instanceof DOMException && error.name === 'NotSupportedError') { + // ignore this error caused by a Content Security Policy that disables data: scheme for media URLs + } else { + autoplayEnabled = false; + } }); }