Skip to content

Commit c31299d

Browse files
committed
fix: use direct iframe for YouTube embeds
Replace oEmbed iframe-in-iframe approach with a direct responsive iframe wrapper for YouTube videos. This avoids sizing issues caused by oEmbed's fixed dimensions and enables proper autoplay on click.
1 parent d796aa9 commit c31299d

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

internal/templates/views/index.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,22 @@
510510
return;
511511
}
512512

513+
// YouTube embeds: use direct iframe with responsive wrapper
514+
// to avoid iframe-in-iframe sizing issues from oEmbed fixed dimensions
515+
var ytSrcMatch = embedHtml.match(/src="(https:\/\/www\.youtube\.com\/embed\/[^"]+)"/);
516+
if (ytSrcMatch) {
517+
var ytSrc = ytSrcMatch[1];
518+
// Add autoplay param if not present
519+
if (ytSrc.indexOf('autoplay') === -1) {
520+
ytSrc += (ytSrc.indexOf('?') !== -1 ? '&' : '?') + 'autoplay=1';
521+
}
522+
container.innerHTML = '<div class="youtube-embed-wrapper"><iframe width="100%" height="100%" src="' + ytSrc + '" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; fullscreen" allowfullscreen></iframe></div>';
523+
container.onclick = null;
524+
container.classList.remove('is-video');
525+
container.style.cursor = 'default';
526+
return;
527+
}
528+
513529
// Security: Use sandboxed iframe to isolate external embed content
514530
// This prevents embedded content from accessing the parent page
515531
var iframe = document.createElement('iframe');

0 commit comments

Comments
 (0)