From cdfcf4dc540b251d4709dfb10e1f3416b266ed06 Mon Sep 17 00:00:00 2001 From: Yiannis Christodoulou Date: Fri, 9 Jan 2026 10:54:45 +0200 Subject: [PATCH] Improve focus and scroll behavior for embedded video player Prevent automatic focus on the video element when in embed mode to avoid unexpected behavior. Update scroll logic to only scroll the video into view if not in an iframe, or if explicitly requested via a URL parameter, improving user experience for embedded players. --- .../components/video-player/VideoJSPlayer.jsx | 5 ++++- .../js/components/VideoJS/VideoJSEmbed.jsx | 16 +++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/frontend-tools/video-js/src/components/video-player/VideoJSPlayer.jsx b/frontend-tools/video-js/src/components/video-player/VideoJSPlayer.jsx index 1090f36f..125a7bc7 100644 --- a/frontend-tools/video-js/src/components/video-player/VideoJSPlayer.jsx +++ b/frontend-tools/video-js/src/components/video-player/VideoJSPlayer.jsx @@ -2312,7 +2312,10 @@ function VideoJSPlayer({ videoId = 'default-video', showTitle = true, showRelate // Make the video element focusable const videoElement = playerRef.current.el(); videoElement.setAttribute('tabindex', '0'); - videoElement.focus(); + + if (!isEmbedPlayer) { + videoElement.focus(); + } // Add context menu (right-click) handler to the player wrapper and video element // Attach to player wrapper (this catches all clicks on the player) diff --git a/frontend/src/static/js/components/VideoJS/VideoJSEmbed.jsx b/frontend/src/static/js/components/VideoJS/VideoJSEmbed.jsx index 1b21e98f..0e16c061 100644 --- a/frontend/src/static/js/components/VideoJS/VideoJSEmbed.jsx +++ b/frontend/src/static/js/components/VideoJS/VideoJSEmbed.jsx @@ -186,11 +186,17 @@ const VideoJSEmbed = ({ // Scroll to the video player with smooth behavior const videoElement = document.querySelector(inEmbedRef.current ? '#video-embed' : '#video-main'); if (videoElement) { - videoElement.scrollIntoView({ - behavior: 'smooth', - block: 'center', - inline: 'nearest' - }); + const urlScroll = getUrlParameter('scroll'); + const isIframe = window.parent !== window; + + // Only scroll if not in an iframe, OR if explicitly requested via scroll=1 parameter + if (!isIframe || urlScroll === '1' || urlScroll === 'true') { + videoElement.scrollIntoView({ + behavior: 'smooth', + block: 'center', + inline: 'nearest' + }); + } } } else { console.warn('VideoJS player not found for timestamp navigation');