WorkerGlobalScope: securitypolicyviolation event
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 only available inWeb Workers.
Thesecuritypolicyviolation event is fired when aContent Security Policy is violated in a worker.
The handler can be assigned using theonsecuritypolicyviolation event handler property or usingEventTarget.addEventListener().
In this article
Syntax
Use the event name in methods likeaddEventListener(), or set an event handler property.
js
addEventListener("securitypolicyviolation", (event) => { })onsecuritypolicyviolation = (event) => { }Event type
ASecurityPolicyViolationEvent. Inherits fromEvent.
Examples
The code below shows how you might add an event handler function using theonsecuritypolicyviolation event handler property or calladdEventListener() method.
js
self.onsecuritypolicyviolation = (e) => { // Handle SecurityPolicyViolationEvent e here};self.addEventListener("securitypolicyviolation", (e) => { // Handle SecurityPolicyViolationEvent e here});Specifications
| Specification |
|---|
| Content Security Policy Level 3> # eventdef-globaleventhandlers-securitypolicyviolation> |
Browser compatibility
See also
- The
securitypolicyviolationevent of theDocumentinterface - The
securitypolicyviolationevent of theElementinterface - HTTP > Content Security Policy