SecurityPolicyViolationEvent: SecurityPolicyViolationEvent() constructor

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since October 2018.

Note: This feature is available in Web Workers.

The SecurityPolicyViolationEvent() constructor creates a new SecurityPolicyViolationEvent object.

Syntax

js
new SecurityPolicyViolationEvent(type)
new SecurityPolicyViolationEvent(type, options)

Parameters

type

A string with the name of the event. It is case-sensitive and browsers always set it to securitypolicyviolation.

options Optional

An object that, in addition of the properties defined in Event(), can have the following properties:

blockedURI Optional

The blockedURI of the SecurityPolicyViolationEvent. If not included, the default value is "".

columnNumber Optional

The columnNumber of the SecurityPolicyViolationEvent. If not included, the default value is 0.

disposition

The disposition of the SecurityPolicyViolationEvent.

documentURI

The documentURI of the SecurityPolicyViolationEvent.

effectiveDirective

The effectiveDirective of the SecurityPolicyViolationEvent.

lineNumber Optional

The lineNumber of the SecurityPolicyViolationEvent. If not included, the default value is 0.

originalPolicy

The originalPolicy of the SecurityPolicyViolationEvent.

referrer Optional

The referrer of the SecurityPolicyViolationEvent. If not included, the default value is "".

sample Optional

The sample of the SecurityPolicyViolationEvent. If not included, the default value is "".

sourceFile Optional

The sourceFile of the SecurityPolicyViolationEvent. If not included, the default value is "".

statusCode

The statusCode of the SecurityPolicyViolationEvent.

violatedDirective

The violatedDirective of the SecurityPolicyViolationEvent.

Return value

A new SecurityPolicyViolationEvent object.

Examples

js
let SPVEvt = new SecurityPolicyViolationEvent("foo", {
  /* ... */
});

Specifications

Specification
Content Security Policy Level 3
# dom-securitypolicyviolationevent-securitypolicyviolationevent

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
SecurityPolicyViolationEvent() constructor
Chrome – Full support
Chrome 41 (Release date: 2015-03-03)
footnote Full support
Edge – Full support
Edge 15 (Release date: 2017-04-05)
footnote Full support
Firefox – Full support
Firefox 63 (Release date: 2018-10-23)
footnote Full support
Opera – Full support
Opera 28 (Release date: 2015-03-10)
footnote Full support
Safari – Full support
Safari 10 (Release date: 2016-09-20)
footnote Full support
Chrome Android – Full support
Chrome Android 41 (Release date: 2015-03-11)
footnote Full support
Firefox for Android – Full support
Firefox for Android 63 (Release date: 2018-10-23)
footnote Full support
Opera Android – Full support
Opera Android 28 (Release date: 2015-03-10)
footnote Full support
Safari on iOS – Full support
Safari on iOS 10 (Release date: 2016-09-13)
footnote Full support
Samsung Internet – Full support
Samsung Internet 4 (Release date: 2016-03-11)
footnote Full support
WebView Android – Full support
WebView Android 41 (Release date: 2015-03-11)
footnote Full support
WebView on iOS – Full support
WebView on iOS 10 (Release date: 2016-09-13)
footnote Full support

Legend

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

Full support
Full support

See also