Refused to execute inline event handler because it violates the following Content Security Policy

I am working with Coded Components, and when I try to remove any html element in a javascript script the following error shows:

“Refused to execute inline event handler because it violates the following Content Security Policy”

The line of the code that is making the error show is the following one:
ul.querySelectorAll(“li”).forEach(li => li.remove());

Is there any way in which I can remove the Content Security Policy line that is causing this problem?

Thank you.

Hello Marc!

I believe that the problem lies in the external resources that you might be using and referencing in your Coded Component script. Try following the instructions under Content Security Policy in the article here:

1 Like

It is weird because in this coded component I am not using any external resource. I attach some screenshots here so you can see how the coded component looks like:

HTML Content:
Screenshot 2023-03-21 at 17.18.31

Script:

Coded component
Screenshot 2023-03-21 at 17.19.55

I have solved the issue. I think I have identified what was creating the CSP error.

As I have understood, what was triggering the error was setting the event listener onclick to an HTML element in the way that is shown in the screenshot with Javascript.

3 Likes