From 9e160f58ab695758e08011f3d1b0aab826bd38f4 Mon Sep 17 00:00:00 2001 From: Penar Musaraj Date: Wed, 15 Jul 2020 18:14:14 -0400 Subject: [PATCH] FIX: Trick Safari into loading video previews (#10244) --- .../app/initializers/post-decorations.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/assets/javascripts/discourse/app/initializers/post-decorations.js b/app/assets/javascripts/discourse/app/initializers/post-decorations.js index 7b7d543aa87..2146cbbe2a6 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 } + ); + } }); } };