FIX: Trick Safari into loading video previews (#10244)

FIX: Trick Safari into loading video previews (#10244)

diff --git a/app/assets/javascripts/discourse/app/initializers/post-decorations.js b/app/assets/javascripts/discourse/app/initializers/post-decorations.js
index 7b7d543..2146cbb 100644
--- a/app/assets/javascripts/discourse/app/initializers/post-decorations.js
+++ b/app/assets/javascripts/discourse/app/initializers/post-decorations.js
@@ -38,6 +38,23 @@ export default {
         },
         { id: "discourse-audio" }
       );
+
+      const caps = container.lookup("capabilities:main");
+      if (caps.isSafari) {
+        api.decorateCookedElement(
+          elem => {
+            const video = elem.querySelector("video");
+            if (video && !video.poster) {
+              const source = video.querySelector("source");
+              if (source) {
+                // this tricks Safari into loading the video preview
+                source.parentElement.load();
+              }
+            }
+          },
+          { id: "safari-video-poster", afterAdopt: true }
+        );
+      }
     });
   }
 };

GitHub sha: 9e160f58

1 Like

This commit appears in #10244 which was merged by pmusaraj.