@@ -141,7 +141,7 @@ function playbackSelection(
141141 } ;
142142 }
143143
144- if ( mode === "progressive" ) {
144+ if ( mode === "progressive" && bootstrap . playback_credential_mode !== "omit" ) {
145145 const progressiveUrl = progressivePlaybackUrl ( bootstrap ) ;
146146 if ( progressiveUrl ) {
147147 return {
@@ -187,6 +187,12 @@ function playbackSelection(
187187 return null ;
188188}
189189
190+ function playbackCrossOrigin ( bootstrap : WatchPlaybackBootstrapResponse | null ) {
191+ return bootstrap ?. status === "ready" && bootstrap . playback_credential_mode === "omit"
192+ ? "anonymous"
193+ : "use-credentials" ;
194+ }
195+
190196function progressivePlaybackUrl ( bootstrap : WatchPlaybackBootstrapReady ) {
191197 if ( bootstrap . playable_state !== "hls_ready" || ! bootstrap . manifest_url ) {
192198 return null ;
@@ -253,6 +259,7 @@ function appendStartupLinkHeaders(
253259 headers : Headers ,
254260 edge : ReturnType < typeof playbackOrigin > ,
255261 selection : ReturnType < typeof playbackSelection > ,
262+ crossOrigin : "anonymous" | "use-credentials" ,
256263) {
257264 if ( edge ) {
258265 headers . append (
@@ -266,7 +273,7 @@ function appendStartupLinkHeaders(
266273 const preloadContentType = preload . contentType ?? "video/mp4" ;
267274 headers . append (
268275 "link" ,
269- `<${ linkHeaderValue ( preload . url ) } >; rel=preload; as=video; type="${ linkHeaderValue ( preloadContentType ) } "; crossorigin="use-credentials "; fetchpriority=high` ,
276+ `<${ linkHeaderValue ( preload . url ) } >; rel=preload; as=video; type="${ linkHeaderValue ( preloadContentType ) } "; crossorigin="${ crossOrigin } "; fetchpriority=high` ,
270277 ) ;
271278}
272279
@@ -295,6 +302,7 @@ export function renderFastEmbedHtml(options: FastEmbedRenderOptions) {
295302 : "" ;
296303 const preload = preloadablePlaybackSelection ( selection ) ;
297304 const preloadContentType = preload ?. contentType ?? "video/mp4" ;
305+ const crossOrigin = playbackCrossOrigin ( options . bootstrap ) ;
298306 const bootstrapMs =
299307 typeof options . bootstrapMs === "number"
300308 ? ` data-rend-bootstrap-ms="${ Math . max ( 0 , Math . round ( options . bootstrapMs ) ) } "`
@@ -310,7 +318,7 @@ export function renderFastEmbedHtml(options: FastEmbedRenderOptions) {
310318<title>Rend player</title>
311319${ edge ? `<link rel="dns-prefetch" href="${ html ( edge . dnsPrefetch ) } ">` : "" }
312320${ edge ? `<link rel="preconnect" href="${ html ( edge . origin ) } " crossorigin>` : "" }
313- ${ preload ? `<link rel="preload" as="video" href="${ html ( preload . url ) } " type="${ html ( preloadContentType ) } " crossorigin="use-credentials " fetchpriority="high">` : "" }
321+ ${ preload ? `<link rel="preload" as="video" href="${ html ( preload . url ) } " type="${ html ( preloadContentType ) } " crossorigin="${ html ( crossOrigin ) } " fetchpriority="high">` : "" }
314322<style>
315323html,body{margin:0;width:100%;height:100%;background:#050505;color:#f7f7f7}
316324body{overflow:hidden}
@@ -322,11 +330,11 @@ body{overflow:hidden}
322330</head>
323331<body>
324332<main class="rend-fast" aria-label="Video player" data-rend-player-state="${ html ( state ) } " data-rend-player-selected="${ html ( selection ?. label ?? "" ) } " data-rend-player-artifact="${ html ( selection ?. artifactPath ?? "" ) } " data-rend-ready-status="${ html ( ready ?. status ?? options . bootstrap ?. status ?? state ) } " data-rend-source-state="${ html ( ready ?. source_state ?? "" ) } " data-rend-playable-state="${ html ( ready ?. playable_state ?? "" ) } " data-rend-manifest-content-type="${ html ( ready ?. manifest_content_type ?? "" ) } " data-rend-opener-content-type="${ html ( ready ?. opener_content_type ?? "" ) } " data-rend-poster="${ html ( ready ?. poster_url ?? "" ) } " data-rend-prefetch-hint-count="${ html ( ready ?. prefetch_hints . length ?? 0 ) } " data-rend-playback-engine="native" data-rend-document-start-ms="0"${ bootstrapMs } data-rend-asset-id="${ html ( options . assetId ) } ">
325- <video class="rend-fast__video"${ source } ${ contentType } ${ poster } ${ autoPlay } ${ controls } ${ muted } playsinline preload="auto" crossorigin="use-credentials "></video>
333+ <video class="rend-fast__video"${ source } ${ contentType } ${ poster } ${ autoPlay } ${ controls } ${ muted } playsinline preload="auto" crossorigin="${ html ( crossOrigin ) } "></video>
326334<div class="rend-fast__message" role="status" aria-live="polite">${ html ( message ) } </div>
327335</main>
328336<script>
329- (()=>{const root=document.querySelector("[data-rend-player-state]");const video=document.querySelector("video");if(!root||!video)return;const assetId=${ jsString ( options . assetId ) } ;const preferredStartup=${ jsString ( preferredStartup ) } ;const bootstrapUrl=${ jsString ( options . bootstrapUrl ) } ;const autoPlay=${ options . autoPlay ? "true" : "false" } ;const bootstrapStarted=performance.now();const mark=(name)=>{if(!root.getAttribute(name))root.setAttribute(name,String(Math.round(performance.now())))};const dims=()=>{if(video.videoWidth)root.setAttribute("data-rend-selected-width",String(video.videoWidth));if(video.videoHeight)root.setAttribute("data-rend-selected-height",String(video.videoHeight))};const play=()=>{if(autoPlay)video.play().catch(()=>{})};const progressive=(data)=>{if(data.playable_state!=="hls_ready"||!data.manifest_url)return null;const byRendition=new Map();for(const hint of Array.isArray(data.prefetch_hints)?data.prefetch_hints:[]){const match=/^hls\\/([^/]+)\\/([^/]+)$/.exec(String(hint.artifact_path||""));if(!match)continue;const state=byRendition.get(match[1])||{init:false,segment:false};state.init=state.init||match[2]===\`init_\${match[1]}.mp4\`;state.segment=state.segment||match[2]==="segment_00000.m4s";byRendition.set(match[1],state)}let rendition="";for(const candidate of ["360p","480p","720p","1080p","2k","4k"]){const state=byRendition.get(candidate);if(state&&state.init&&state.segment){rendition=candidate;break}}if(!rendition)return null;try{const parsed=new URL(data.manifest_url);const prefix="/v/"+assetId+"/";if(!parsed.pathname.startsWith(prefix))return null;const artifactPath="hls/"+rendition+"/progressive.mp4";parsed.pathname=prefix+artifactPath;parsed.search="";parsed.hash="";return{artifactPath,contentType:"video/mp4",label:"progressive_mp4",url:parsed.toString()}}catch{return null}};const select=(data)=>{if(!data||data.status!=="ready")return null;if(preferredStartup==="opener"&&data.opener_url)return{artifactPath:"opener.mp4",contentType:data.opener_content_type||"video/mp4",label:"opener",url:data.opener_url};if(preferredStartup==="progressive"){const selected=progressive(data);if(selected)return selected}if(data.playable_state==="hls_ready"&&data.manifest_url)return{artifactPath:"hls/master.m3u8",contentType:data.manifest_content_type||"application/vnd.apple.mpegurl",label:"native_hls",url:data.manifest_url};if(data.opener_url)return{artifactPath:"opener.mp4",contentType:data.opener_content_type||"video/mp4",label:"opener",url:data.opener_url};if(data.playback_url)return{artifactPath:data.playable_state==="hls_ready"?"hls/master.m3u8":"opener.mp4",contentType:data.playback_content_type||"",label:"primary",url:data.playback_url};return null};video.addEventListener("loadedmetadata",()=>{dims();mark("data-rend-metadata-ms")},{once:true});video.addEventListener("canplay",()=>{dims();mark("data-rend-canplay-ms")},{once:true});video.addEventListener("playing",()=>{root.setAttribute("data-rend-player-state","playing");dims()});if("requestVideoFrameCallback"in video){video.requestVideoFrameCallback(()=>{dims();mark("data-rend-first-frame-ms")})}else{video.addEventListener("playing",()=>mark("data-rend-first-frame-ms"),{once:true})}if(!video.currentSrc&&!video.getAttribute("src")){fetch(bootstrapUrl,{credentials:"same-origin",headers:{accept:"application/json"}}).then(r=>r.ok?r.json():null).then(data=>{root.setAttribute("data-rend-bootstrap-ms",String(Math.round(performance.now()-bootstrapStarted)));const selected=select(data);if(!selected)return;root.setAttribute("data-rend-player-state","ready");root.setAttribute("data-rend-player-selected",selected.label);root.setAttribute("data-rend-player-artifact",selected.artifactPath);if(data.poster_url){root.setAttribute("data-rend-poster",data.poster_url);video.poster=data.poster_url}root.setAttribute("data-rend-ready-status",data.status||"ready");root.setAttribute("data-rend-source-state",data.source_state||"");root.setAttribute("data-rend-playable-state",data.playable_state||"");video.src=selected.url;video.load();play()}).catch(()=>{root.setAttribute("data-rend-player-state","playback_failure")})}else{play()}})();
337+ (()=>{const root=document.querySelector("[data-rend-player-state]");const video=document.querySelector("video");if(!root||!video)return;const assetId=${ jsString ( options . assetId ) } ;const preferredStartup=${ jsString ( preferredStartup ) } ;const bootstrapUrl=${ jsString ( options . bootstrapUrl ) } ;const autoPlay=${ options . autoPlay ? "true" : "false" } ;const bootstrapStarted=performance.now();const mark=(name)=>{if(!root.getAttribute(name))root.setAttribute(name,String(Math.round(performance.now())))};const dims=()=>{if(video.videoWidth)root.setAttribute("data-rend-selected-width",String(video.videoWidth));if(video.videoHeight)root.setAttribute("data-rend-selected-height",String(video.videoHeight))};const play=()=>{if(autoPlay)video.play().catch(()=>{})};const crossOrigin=(data)=>data&&data.playback_credential_mode==="omit"?"anonymous":"use-credentials";const progressive=(data)=>{if(data.playback_credential_mode==="omit"||data.playable_state!=="hls_ready"||!data.manifest_url)return null;const byRendition=new Map();for(const hint of Array.isArray(data.prefetch_hints)?data.prefetch_hints:[]){const match=/^hls\\/([^/]+)\\/([^/]+)$/.exec(String(hint.artifact_path||""));if(!match)continue;const state=byRendition.get(match[1])||{init:false,segment:false};state.init=state.init||match[2]===\`init_\${match[1]}.mp4\`;state.segment=state.segment||match[2]==="segment_00000.m4s";byRendition.set(match[1],state)}let rendition="";for(const candidate of ["360p","480p","720p","1080p","2k","4k"]){const state=byRendition.get(candidate);if(state&&state.init&&state.segment){rendition=candidate;break}}if(!rendition)return null;try{const parsed=new URL(data.manifest_url);const prefix="/v/"+assetId+"/";if(!parsed.pathname.startsWith(prefix))return null;const artifactPath="hls/"+rendition+"/progressive.mp4";parsed.pathname=prefix+artifactPath;parsed.search="";parsed.hash="";return{artifactPath,contentType:"video/mp4",label:"progressive_mp4",url:parsed.toString()}}catch{return null}};const select=(data)=>{if(!data||data.status!=="ready")return null;if(preferredStartup==="opener"&&data.opener_url)return{artifactPath:"opener.mp4",contentType:data.opener_content_type||"video/mp4",label:"opener",url:data.opener_url};if(preferredStartup==="progressive"){const selected=progressive(data);if(selected)return selected}if(data.playable_state==="hls_ready"&&data.manifest_url)return{artifactPath:"hls/master.m3u8",contentType:data.manifest_content_type||"application/vnd.apple.mpegurl",label:"native_hls",url:data.manifest_url};if(data.opener_url)return{artifactPath:"opener.mp4",contentType:data.opener_content_type||"video/mp4",label:"opener",url:data.opener_url};if(data.playback_url)return{artifactPath:data.playable_state==="hls_ready"?"hls/master.m3u8":"opener.mp4",contentType:data.playback_content_type||"",label:"primary",url:data.playback_url};return null};video.addEventListener("loadedmetadata",()=>{dims();mark("data-rend-metadata-ms")},{once:true});video.addEventListener("canplay",()=>{dims();mark("data-rend-canplay-ms")},{once:true});video.addEventListener("playing",()=>{root.setAttribute("data-rend-player-state","playing");dims()});if("requestVideoFrameCallback"in video){video.requestVideoFrameCallback(()=>{dims();mark("data-rend-first-frame-ms")})}else{video.addEventListener("playing",()=>mark("data-rend-first-frame-ms"),{once:true})}if(!video.currentSrc&&!video.getAttribute("src")){fetch(bootstrapUrl,{credentials:"same-origin",headers:{accept:"application/json"}}).then(r=>r.ok?r.json():null).then(data=>{root.setAttribute("data-rend-bootstrap-ms",String(Math.round(performance.now()-bootstrapStarted)));const selected=select(data);if(!selected)return;video.crossOrigin=crossOrigin(data);root.setAttribute("data-rend-player-state","ready");root.setAttribute("data-rend-player-selected",selected.label);root.setAttribute("data-rend-player-artifact",selected.artifactPath);if(data.poster_url){root.setAttribute("data-rend-poster",data.poster_url);video.poster=data.poster_url}root.setAttribute("data-rend-ready-status",data.status||"ready");root.setAttribute("data-rend-source-state",data.source_state||"");root.setAttribute("data-rend-playable-state",data.playable_state||"");video.src=selected.url;video.load();play()}).catch(()=>{root.setAttribute("data-rend-player-state","playback_failure")})}else{play()}})();
330338</script>
331339</body>
332340</html>` ;
@@ -383,6 +391,7 @@ export async function GET(
383391 const ready = bootstrap ?. status === "ready" ? bootstrap : null ;
384392 const selection = playbackSelection ( bootstrap , startup ) ;
385393 const edge = playbackOrigin ( ready ) ?? defaultPlaybackOriginHint ( ) ;
394+ const crossOrigin = playbackCrossOrigin ( bootstrap ) ;
386395 const headers = new Headers ( {
387396 "cache-control" : "no-store" ,
388397 "content-type" : "text/html; charset=utf-8" ,
@@ -395,7 +404,7 @@ export async function GET(
395404 headers . append ( "set-cookie" , setCookie ) ;
396405 }
397406 }
398- appendStartupLinkHeaders ( headers , edge , selection ) ;
407+ appendStartupLinkHeaders ( headers , edge , selection , crossOrigin ) ;
399408
400409 return new Response (
401410 renderFastEmbedHtml ( {
0 commit comments