CSP nonces with Cloudflare Workers

Thank you for your answer, you are absolutely right.

I also corrected my mistake. I’ll post the code if it helps.

Code for Cloudflare Workers: https://gist.github.com/richie5um/b2999177b27095af13ec619e44742116

Code for WordPress :

add_filter( 'script_loader_tag', 'add_nonce_to_script', 10, 3 );
function add_nonce_to_script( $tag, $handle, $source ) {
$search = "type="text/javascript"";
$replace = "type="text/javascript" nonce=""";
$subject = $tag;

$output = str_replace($search, $replace, $subject);
return $output;
}