I keep running into this annoying problem where I get ReferenceError: Twitch is not defined when trying to embed a Twitch stream on my website. Here’s the code I’m using:
<div class="stream-container" id="playerWrapper">
<script src="https://player.twitch.tv/js/embed/v1.js"></script>
<div id="streamDiv"></div>
<script type="text/javascript">
var settings = {width:800,height:450,channel:"gamingStreamer123"};
var streamPlayer = new Twitch.Player("streamDiv", settings);
streamPlayer.setVolume(0.3);
</script>
</div>
The weird thing is that when I test this exact same code in online editors like JSFiddle, everything works perfectly fine. But when I put it on my actual website, it throws that Twitch undefined error. I can see the embed script is loading properly in the browser dev tools under the network tab.
Using a simple iframe embed works without issues, but I need the JavaScript API for more control over the player. Has anyone dealt with this before? What could be blocking the Twitch object from being available on my page?