document.addEventListener("DOMContentLoaded", () => { let bodies = document.getElementsByTagName("body"); if(bodies.length === 1) { let body = bodies[0]; let xhr = new XMLHttpRequest(); xhr.addEventListener("load", (e) => { console.log(e); let video = document.createElement("video"); video.id = "video-player"; video.className = "video-js"; body.appendChild(video); let ctype = xhr.getResponseHeader("Content-Type"); let player = videojs("video-player"); let source = {}; source.type = ctype; source.src = "{{ stream }}"; player.src(source); }); xhr.open("HEAD", "{{ stream }}", true); xhr.send(); } });