SecurityPolicyViolationEvent
The SecurityPolicyViolationEvent
interface inherits from Event
, and represents the event object of an event sent on a document or worker when its content security policy is violated.
Constructor
SecurityPolicyViolationEvent()
- Creates a new
SecurityPolicyViolationEvent
object instance.
Properties
-
SecurityPolicyViolationEvent.blockedURI
Read only
- A
USVString
representing the URI of the resource that was blocked because it violates a policy. -
SecurityPolicyViolationEvent.columnNumber
Read only
- The column number in the document or worker at which the violation occurred.
-
SecurityPolicyViolationEvent.disposition
Read only
- Indicates how the violated policy is configured to be treated by the user agent. This will be
"enforce"
or "report"
. -
SecurityPolicyViolationEvent.documentURI
Read only
- A
USVString
representing the URI of the document or worker in which the violation was found. -
SecurityPolicyViolationEvent.effectiveDirective
Read only
- A
DOMString
representing the directive whose enforcement uncovered the violation. -
SecurityPolicyViolationEvent.lineNumber
Read only
- The line number in the document or worker at which the violation occurred.
-
SecurityPolicyViolationEvent.originalPolicy
Read only
- A
DOMString
containing the policy whose enforcement uncovered the violation. -
SecurityPolicyViolationEvent.referrer
Read only
- A
USVString
representing the referrer of the resources whose policy was violated. This will be a URL or null
. -
SecurityPolicyViolationEvent.sample
Read only
- A
DOMString
representing a sample of the resource that caused the violation, usually the first 40 characters. This will only be populated if the resource is an inline script, event handler, or style — external resources causing a violation will not generate a sample. -
SecurityPolicyViolationEvent.sourceFile
Read only
- A
USVString
representing the URI of the document or worker in which the violation was found. -
SecurityPolicyViolationEvent.statusCode
Read only
- A number representing the HTTP status code of the document or worker in which the violation occurred.
-
SecurityPolicyViolationEvent.violatedDirective
Read only
- A
DOMString
representing the directive whose enforcement uncovered the violation.
Examples
document.addEventListener("securitypolicyviolation", (e) => {
console.log(e.blockedURI);
console.log(e.violatedDirective);
console.log(e.originalPolicy);
});
Specifications
|
Desktop |
|
Chrome |
Edge |
Firefox |
Internet Explorer |
Opera |
Safari |
Basic support
|
Yes |
Yes |
63
- 63
- 59
Disabled
- Disabled From version 59: this feature is behind the
security.csp.enable_violation_events preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
|
No |
Yes |
Yes |
SecurityPolicyViolationEvent support in workers |
56 |
Yes |
63
- 63
- 59
Disabled
- Disabled From version 59: this feature is behind the
security.csp.enable_violation_events preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
|
No |
43 |
Yes |
SecurityPolicyViolationEvent() constructor |
Yes |
Yes |
63
- 63
- 59
Disabled
- Disabled From version 59: this feature is behind the
security.csp.enable_violation_events preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
|
No |
Yes |
Yes |
blockedURI |
Yes |
15 |
63
- 63
- 59
Disabled
- Disabled From version 59: this feature is behind the
security.csp.enable_violation_events preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
|
No |
Yes |
Yes |
columnNumber |
Yes |
15 |
63
- 63
- 59
Disabled
- Disabled From version 59: this feature is behind the
security.csp.enable_violation_events preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
|
No |
Yes |
Yes |
disposition |
Yes |
Yes |
63
- 63
- 59
Disabled
- Disabled From version 59: this feature is behind the
security.csp.enable_violation_events preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
|
No |
Yes |
Yes |
documentURI |
Yes |
15 |
63
- 63
- 59
Disabled
- Disabled From version 59: this feature is behind the
security.csp.enable_violation_events preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
|
No |
Yes |
Yes |
effectiveDirective |
Yes |
15 |
63
- 63
- 59
Disabled
- Disabled From version 59: this feature is behind the
security.csp.enable_violation_events preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
|
No |
Yes |
Yes |
lineNumber |
Yes |
15 |
63
- 63
- 59
Disabled
- Disabled From version 59: this feature is behind the
security.csp.enable_violation_events preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
|
No |
Yes |
Yes |
originalPolicy |
Yes |
15 |
63
- 63
- 59
Disabled
- Disabled From version 59: this feature is behind the
security.csp.enable_violation_events preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
|
No |
Yes |
Yes |
referrer |
Yes |
15 |
63
- 63
- 59
Disabled
- Disabled From version 59: this feature is behind the
security.csp.enable_violation_events preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
|
No |
Yes |
Yes |
sample |
59 |
Yes |
63
- 63
- 59
Disabled
- Disabled From version 59: this feature is behind the
security.csp.enable_violation_events preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
|
No |
46 |
Yes |
sourceFile |
Yes |
15 |
63
- 63
- 59
Disabled
- Disabled From version 59: this feature is behind the
security.csp.enable_violation_events preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
|
No |
Yes |
Yes |
statusCode |
Yes |
15 |
63
- 63
- 59
Disabled
- Disabled From version 59: this feature is behind the
security.csp.enable_violation_events preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
|
No |
Yes |
Yes |
violatedDirective |
Yes |
15 |
63
- 63
- 59
Disabled
- Disabled From version 59: this feature is behind the
security.csp.enable_violation_events preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
|
No |
Yes |
Yes |
|
Mobile |
|
Android webview |
Chrome for Android |
Edge Mobile |
Firefox for Android |
Opera for Android |
iOS Safari |
Samsung Internet |
Basic support
|
Yes |
Yes |
Yes |
63
- 63
- 59
Disabled
- Disabled From version 59: this feature is behind the
security.csp.enable_violation_events preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
|
Yes |
Yes |
Yes |
SecurityPolicyViolationEvent support in workers |
56 |
56 |
Yes |
63
- 63
- 59
Disabled
- Disabled From version 59: this feature is behind the
security.csp.enable_violation_events preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
|
43 |
Yes |
6.0 |
SecurityPolicyViolationEvent() constructor |
Yes |
Yes |
Yes |
63
- 63
- 59
Disabled
- Disabled From version 59: this feature is behind the
security.csp.enable_violation_events preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
|
Yes |
Yes |
Yes |
blockedURI |
Yes |
Yes |
Yes |
63
- 63
- 59
Disabled
- Disabled From version 59: this feature is behind the
security.csp.enable_violation_events preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
|
Yes |
Yes |
Yes |
columnNumber |
Yes |
Yes |
Yes |
63
- 63
- 59
Disabled
- Disabled From version 59: this feature is behind the
security.csp.enable_violation_events preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
|
Yes |
Yes |
Yes |
disposition |
Yes |
Yes |
Yes |
63
- 63
- 59
Disabled
- Disabled From version 59: this feature is behind the
security.csp.enable_violation_events preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
|
Yes |
Yes |
Yes |
documentURI |
Yes |
Yes |
Yes |
63
- 63
- 59
Disabled
- Disabled From version 59: this feature is behind the
security.csp.enable_violation_events preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
|
Yes |
Yes |
Yes |
effectiveDirective |
Yes |
Yes |
Yes |
63
- 63
- 59
Disabled
- Disabled From version 59: this feature is behind the
security.csp.enable_violation_events preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
|
Yes |
Yes |
Yes |
lineNumber |
Yes |
Yes |
Yes |
63
- 63
- 59
Disabled
- Disabled From version 59: this feature is behind the
security.csp.enable_violation_events preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
|
Yes |
Yes |
Yes |
originalPolicy |
Yes |
Yes |
Yes |
63
- 63
- 59
Disabled
- Disabled From version 59: this feature is behind the
security.csp.enable_violation_events preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
|
Yes |
Yes |
Yes |
referrer |
Yes |
Yes |
Yes |
63
- 63
- 59
Disabled
- Disabled From version 59: this feature is behind the
security.csp.enable_violation_events preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
|
Yes |
Yes |
Yes |
sample |
59 |
59 |
Yes |
63
- 63
- 59
Disabled
- Disabled From version 59: this feature is behind the
security.csp.enable_violation_events preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
|
46 |
Yes |
7.0 |
sourceFile |
Yes |
Yes |
Yes |
63
- 63
- 59
Disabled
- Disabled From version 59: this feature is behind the
security.csp.enable_violation_events preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
|
Yes |
Yes |
Yes |
statusCode |
Yes |
Yes |
Yes |
63
- 63
- 59
Disabled
- Disabled From version 59: this feature is behind the
security.csp.enable_violation_events preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
|
Yes |
Yes |
Yes |
violatedDirective |
Yes |
Yes |
Yes |
63
- 63
- 59
Disabled
- Disabled From version 59: this feature is behind the
security.csp.enable_violation_events preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
|
Yes |
Yes |
Yes |
See also