"Refused to execute inline script because it violates the following Content Security Policy directive"
You added a Content-Security-Policy, and now the console shows this error and part of your page has stopped working. It means the page contains script written directly in the HTML (a <script> block with no src, or an attribute such as onclick="…"), and the directive the error names does not allow inline script. This page is for the developer who has to make that script run again without throwing away what the policy is for.
Why not just add 'unsafe-inline'?
Because it switches the protection off. Script injection (XSS) works by getting the browser to run attacker text as inline script. 'unsafe-inline' tells the browser to run any inline script, so the attacker's runs too. A policy whose script list contains 'unsafe-inline' and no nonce or hash is the first thing the checker marks high.
There is a second trap. If the list already has a nonce or a hash, adding 'unsafe-inline' does nothing at all: CSP Level 2 and later browsers ignore it when a nonce or hash is present. So it either disables your protection or has no effect, depending on what else is in the list.
Fix 1: a nonce, for pages your server renders
Generate at least 16 random bytes on every response, base64 them, and put the same value in the header and on each script tag you trust:
Content-Security-Policy: script-src 'nonce-q8d1fXo2mZb7J3kVt9rLwA==' 'strict-dynamic'; object-src 'none'; base-uri 'none' <script nonce="q8d1fXo2mZb7J3kVt9rLwA==">initApp();</script>
The value must change on every response; a nonce fixed in a config file is a password printed on every page. 'strict-dynamic' lets scripts you trusted load further scripts, so third-party loaders keep working, and it makes browsers ignore host lists for scripts, which is why a script that used to load from an allowed CDN now needs the nonce too. base-uri 'none' stops an injected <base> tag repointing your nonced relative URLs.
Fix 2: a hash, for static pages
If the script text never changes (a static site, a fixed analytics snippet), allow its exact content by hash. The value is the base64 of the SHA-256 of the text between the tags, every space and newline included. The CSP specification's own example: the script alert('Hello, world.'); is allowed by
script-src 'sha256-qznLcsROx4GACP2dm0UCKCzCG+HiZ1guq6ZZDob/Tng='
Change one character, or the indentation, and the hash no longer matches. Chrome prints the hash it expected in the error message itself; the checker also prints it when you test inline code, and the CLI does the same:
node cli.mjs "script-src 'self'" --inline script "alert('Hello, world.');"
Event handlers: onclick= needs moving, not allowing
Nonces never apply to attributes, and hashes match attributes only when the list also has 'unsafe-hashes'. The clean fix is to move the handler into a nonced or hashed script:
<button id="save">Save</button>
<script nonce="…">document.getElementById('save').addEventListener('click', save);</script>
If the error names script-src-attr, this is your case.
When the error names a directive you didn't write
Browsers fall back: an inline <script> is governed by script-src-elem, then script-src, then default-src. A policy of only default-src 'self' blocks inline script, because 'self' matches URLs, not inline text. And if the response carries two policies (two headers, or one header with a comma), the script must pass both; check them all. The checker's table shows which directive decides each kind of resource.
When to use something else
If the page is not yours (a browser extension's injected script, a SaaS widget you cannot change), the fix is the vendor's. If you want a live scan of a site's headers rather than a policy you have in hand, the Security Headers checker fetches them. If you are in report-only mode, nothing is blocked yet, and these errors are reports of what would be.