Menu

Missing frame-src in CSP Blocks YouTube, Kills Watch Logs
📰

Missing frame-src in CSP Blocks YouTube, Kills Watch Logs

DEV Community: webdev·cometa-kaito·16 days ago
#BGXisX6h
#devtowebdev#devto#dev#youtube#self
Long article (753 words) — no AI summary yet.
Reading 0:00
15s threshold

Conclusion

Without a frame-src directive in the CSP, default-src 'self' blocks the iframe embed itself, so no YouTube video plays at all — even with script-src allowing the YouTube domain. And if script-src doesn't allow that domain either, the IFrame Player API script can't load, so window.YT — which the player depends on — never gets defined. That means playback isn't the only thing that breaks: the watch-time logging that monitors playback state and reports it also stops, silently. The fix was adding the exact domains YouTube actually uses to three separate directives: script-src , img-src , and frame-src .

Symptom

The CSP for a learning-video platform was defined in one place, securityHeaders in next.config.ts . Before the fix it looked like this:

const securityHeaders = [ // ...…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.