Reporting API
The statusCode property of the CSPViolationReport dictionary is a number representing the HTTP status code of the response to the request that triggered a Content Security Policy (CSP) violation (when loading a window or worker).
Value
A number representing the HTTP status code of the response to the request that triggered the CSP violation.
Examples
In this example we create a new ReportingObserver to observe content violation reports of type "csp-violation".
Each time the callback function is invoked, we log the status code for the first entry of the reports array.
const observer = new ReportingObserver(
(reports, observer) => {
console.log(`statusCode: ${reports[0].body.statusCode}`);
// For example: 200
},
{
types: ["csp-violation"],
buffered: true,
},
);
observer.observe();
Note that while there might be multiple reports in the returned array, for brevity we only log the status code of the first report.
Specifications
Browser compatibility
See also
- SecurityPolicyViolationEvent.statusCode
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
