<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
</head>
<body>
<ul>
<li><a href="../report_sample/">report sample</a></li>
</ul>
</body>
</html>CSPViolationReport: documentURL property / notebook
CSPViolationReport: documentURL property
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
<!doctype html>
<!-- /report_sample/index.html -->
<html lang="en">
<head>
<meta
http-equiv="Content-Security-Policy"
content="script-src-elem 'self' 'report-sample'" />
<script src="main.js"></script>
</head>
<body>
<script>
const int = 4;
</script>
</body>
</html>// main.js
const observer = new ReportingObserver(
(reports, observer) => {
console.log(`documentURL: ${reports[0].body.documentURL}`);
console.log(`referrer: ${reports[0].body.referrer}`);
console.log(`blockedURL: ${reports[0].body.blockedURL}`);
},
{
types: ["csp-violation"],
buffered: true,
},
);
observer.observe();