Fixes YouTube embeds (#37126)

This commit is contained in:
Echo
2025-12-04 17:27:20 +01:00
committed by Claire
parent 43f8760c95
commit 140e011e73

View File

@@ -40,17 +40,20 @@ const domParser = new DOMParser();
const handleIframeUrl = (html, url, providerName) => { const handleIframeUrl = (html, url, providerName) => {
const document = domParser.parseFromString(html, 'text/html').documentElement; const document = domParser.parseFromString(html, 'text/html').documentElement;
const iframe = document.querySelector('iframe'); const iframe = document.querySelector('iframe');
const startTime = new URL(url).searchParams.get('t') const startTime = new URL(url).searchParams.get('t');
if (iframe) { if (iframe) {
const iframeUrl = new URL(iframe.src) const iframeUrl = new URL(iframe.src);
iframeUrl.searchParams.set('autoplay', 1) iframeUrl.searchParams.set('autoplay', 1);
iframeUrl.searchParams.set('auto_play', 1) iframeUrl.searchParams.set('auto_play', 1);
if (startTime && providerName === "YouTube") iframeUrl.searchParams.set('start', startTime) if (providerName === 'YouTube') {
iframeUrl.searchParams.set('start', startTime || '');
iframe.referrerPolicy = 'strict-origin-when-cross-origin';
}
iframe.src = iframeUrl.href iframe.src = iframeUrl.href;
// DOM parser creates html/body elements around original HTML fragment, // DOM parser creates html/body elements around original HTML fragment,
// so we need to get innerHTML out of the body and not the entire document // so we need to get innerHTML out of the body and not the entire document