I am trying to generate random values for nonce, but the generated value don't show in the nonce attributes.
My generated code: It is giving an error getRandomValues is not a function
const nonce = Crypto.getRandomValues(new Uint8Array(32)).toString('base64');
const nonceBase64 = btoa(nonce);
const scripts = document.querySelectorAll('body script');
for (const script of scripts) {
script.setAttribute('nonce', nonceBase64);
}
The script in the document
<script>
// inline script
</script>
The rules is also set in my web.config file
<add name="Content-Security-Policy" value="default-src 'self';
script-src 'report-sample' 'self' https://www.google-analytics.com/analytics.js />
Can anyone assist me on fixing what is not right here? I spent days trying to solve it. I read different documentation but no result.