docgen icon indicating copy to clipboard operation
docgen copied to clipboard

Refused to execute inline script because it violates the following Content Security Policy directive

Open henrymcbean opened this issue 3 years ago • 6 comments

Exported my Node API calls from Postman then used Docgen to generate my index.html file then copied to the root of my public folder. When I view the html file via my node server in the browser I am getting a console errors. The first error complained about the favicon.ico so I copied one to the public folder which removed the error. I am unable to remove the CSP error after trying suggested methods in the error using Helmet middleware options.

If open html file directly with the browser I don't get the CSP error so it only happens when I accessing the file via Node API server root. Please advice, full error listed below.

Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-ZomnyosL2bmZ79LmErHEhL+1fVaBj9NngvpOK/l4qio='), or a nonce ('nonce-...') is required to enable inline execution.

henrymcbean avatar May 09 '21 20:05 henrymcbean

For me is the same

jcsuazo avatar Jun 27 '21 14:06 jcsuazo

Facing exactly same issue, this need to be solved

saiteja13427 avatar Oct 20 '21 14:10 saiteja13427

I moved inline script to new js file and it worked for me.

VighneshManjrekar avatar Jun 30 '22 18:06 VighneshManjrekar

I moved inline script to new js file and it worked for me.

but how ?

hassanaref avatar Jul 16 '22 22:07 hassanaref

  1. Open index.html file
  2. Grab all functionality from
  3. Create new file FE: js.js near the index.html
  4. Paste functionality from script tag into new js.js file
  5. Connect js file into index.html file ->

tedsemashov avatar Jul 19 '22 16:07 tedsemashov

This also worked for me (i.e. the comments from @VighneshManjrekar )

markCwatson avatar Oct 16 '22 16:10 markCwatson