diff --git a/src/components/common/YoutubeVideo.astro b/src/components/common/YoutubeVideo.astro index 689e350..dfa882d 100644 --- a/src/components/common/YoutubeVideo.astro +++ b/src/components/common/YoutubeVideo.astro @@ -158,17 +158,23 @@ const { // We'd want to only do this for in-viewport or near-viewport ones: https://github.com/ampproject/amphtml/pull/5003 this.addEventListener('click', this.addIframe); + // Detect Safari + const isSafari = navigator.userAgent.includes('Safari') && !navigator.userAgent.includes('Chrome'); + + // Detect mobile browser + const isMobile = navigator.userAgent.includes('Mobi') || navigator.userAgent.includes('Android'); + // Chrome & Edge desktop have no problem with the basic YouTube Embed with ?autoplay=1 // However Safari desktop and most/all mobile browsers do not successfully track the user gesture of clicking through the creation/loading of the iframe, // so they don't autoplay automatically. Instead we must load an additional 2 sequential JS files (1KB + 165KB) (un-br) for the YT Player API // TODO: Try loading the the YT API in parallel with our iframe and then attaching/playing it. #82 - this.needsYTApiForAutoplay = navigator.vendor.includes('Apple') || navigator.userAgent.includes('Mobi'); + this.needsYTApiForAutoplay = isSafari || isMobile; } /** * Add a to the head */ - static addPrefetch(kind, url, as) { + static addPrefetch(kind: string, url: string, as: string | undefined) { const linkEl = document.createElement('link'); linkEl.rel = kind; linkEl.href = url; @@ -217,7 +223,7 @@ const { }); } - async addYTPlayerIframe(params) { + async addYTPlayerIframe(params: any[] | URLSearchParams) { this.fetchYTPlayerApi(); await this.ytApiPromise; @@ -231,7 +237,7 @@ const { videoId: this.videoId, playerVars: paramsObj, events: { - onReady: (event) => { + onReady: (event: { target: { playVideo: () => void; }; }) => { event.target.playVideo(); }, }, diff --git a/src/components/widgets/BlogHighlightedPosts.astro b/src/components/widgets/BlogHighlightedPosts.astro index 38a00d7..53e5453 100644 --- a/src/components/widgets/BlogHighlightedPosts.astro +++ b/src/components/widgets/BlogHighlightedPosts.astro @@ -34,7 +34,7 @@ const posts = APP_BLOG.isEnabled ? await findPostsByIds(postIds) : []; { APP_BLOG.isEnabled ? ( - +
{title && (
diff --git a/src/components/widgets/BlogLatestPosts.astro b/src/components/widgets/BlogLatestPosts.astro index 9b45383..3173434 100644 --- a/src/components/widgets/BlogLatestPosts.astro +++ b/src/components/widgets/BlogLatestPosts.astro @@ -35,7 +35,7 @@ const posts = APP_BLOG.isEnabled ? await findLatestPosts({ count }) : []; { APP_BLOG.isEnabled ? ( - +
{title && (
diff --git a/src/components/widgets/Features.astro b/src/components/widgets/Features.astro index d7aab28..b1faa9c 100644 --- a/src/components/widgets/Features.astro +++ b/src/components/widgets/Features.astro @@ -30,7 +30,7 @@ const { title={title} subtitle={subtitle} tagline={tagline} - classes={classes?.headline} + classes={classes?.headline as Record} /> } /> - + } />