CSPViolationReportBody: statusCode property

The statusCode read-only property of the CSPViolationReportBody interface 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.

js
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

Specification
Content Security Policy Level 3
# dom-cspviolationreportbody-statuscode

Browser compatibility

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
statusCode

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
In development. Supported in a pre-release version.
In development. Supported in a pre-release version.
No support
No support

See also