Skip to content

Commit 3e3428d

Browse files
committed
Always send CORS header on video requests in prod
1 parent cbd04f9 commit 3e3428d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

dotcom-rendering/src/components/SelfHostedVideoPlayer.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,15 @@ export const SelfHostedVideoPlayer = forwardRef(
185185
showPlayIcon ? 'play' : 'pause'
186186
}-${atomId}`;
187187

188+
/**
189+
* We need CORS enabled to show subtitles on a video as it allows access to the VTT file.
190+
* We don't want a client to not request CORS headers on a video request, then to request
191+
* the same video with CORS headers, as the response could be cached without the headers, which
192+
* will result in the video failing to load. Therefore, we always request CORS headers in production.
193+
*/
194+
const requestCORS =
195+
showSubtitles && process.env.NODE_ENV !== 'production';
196+
188197
return (
189198
<>
190199
{/* eslint-disable-next-line jsx-a11y/media-has-caption -- Not all videos require captions. */}
@@ -194,7 +203,7 @@ export const SelfHostedVideoPlayer = forwardRef(
194203
videoStyles(width, height),
195204
showSubtitles && subtitleStyles(subtitleSize),
196205
]}
197-
crossOrigin={showSubtitles ? 'anonymous' : undefined}
206+
crossOrigin={requestCORS ? 'anonymous' : undefined}
198207
ref={ref}
199208
tabIndex={0}
200209
data-testid="self-hosted-video-player"

0 commit comments

Comments
 (0)