Javascript code in <script> doesn't get executed

Sorry if this is a dumb question but i can’t understand why

This doesn’t run

<script type="text/javascript">console.log('in script')</script>

But if i put the console.log into a file

/** log.js ** /
console.log('in file')

<script src="static/js/log.js"></script>

it runs.

This only happens on hosted test. on local test everything runs.

this is due to the “content-security-policy” property being set by the main twitch site where your extension iframe resides in.

it forbids inline Javascript (as well as stuff like inline event handlers) to avoid issues like cross site scripting attacks being facilitated by an extension (i.e. your extension accidentally executing malicious 3rd party script injected to the DOM).

so, in short, it’s behaving this way because it is supposed to do so, you will have to put your script into separate files, away from your markup.

also, if you write your own stuff you should probably set CSP as well, it’s generally the safer and better way and gives more unobtrusive code too. (separation between markup and script)

You should of got a CSP warning in the console anyway. So check for that!