MDN self-hosted library · e01.org

CSPViolationReport

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

html
<meta http-equiv="Content-Security-Policy" content="default-src 'self'" />
html
<!-- This should generate a CSP violation -->
<script src="https://apis.google.com/js/platform.js"></script>
js
const observer = new ReportingObserver(
  (reports, observer) => {
    reports.forEach((violation) => {
      console.log(violation);
      console.log(JSON.stringify(violation));
    });
  },
  {
    types: ["csp-violation"],
    buffered: true,
  },
);

observer.observe();
html
<!-- This should generate a CSP violation -->
<script src="https://apis.google.com/js/platform.js"></script>