I want to add a nonce to a dynamically constructed script tag. The below does NOT add any nonce to the generated script tag. Anyone an idea how the nonce can be added?
var _wss = document.createElement('script');
_wss.nonce = 'random-string';
_wss.type = 'text/javascript';
_wss.charset = 'utf-8';
_wss.async = true;
_wss.src = "url";
var __wss = document.getElementsByTagName('script')[0];
__wss.parentNode.insertBefore(_wss, __wss);
The result is:
<script type="text/javascript" charset="utf-8" async src="url"></script>
Expected result:
<script nonce="random-string" type="text/javascript" charset="utf-8" async src="url"></script>
Thanks!