/
index.md
57 lines (37 loc) · 1.74 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
---
title: "WorkerGlobalScope: securitypolicyviolation event"
short-title: securitypolicyviolation
slug: Web/API/WorkerGlobalScope/securitypolicyviolation_event
page-type: web-api-event
browser-compat: api.WorkerGlobalScope.securitypolicyviolation_event
---
{{APIRef}}
The **`securitypolicyviolation`** event is fired when a [Content Security Policy](/en-US/docs/Web/HTTP/CSP) is violated in a worker.
The handler can be assigned using the `onsecuritypolicyviolation` event handler property or using {{domxref("EventTarget.addEventListener()")}}.
## Syntax
Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.
```js
addEventListener("securitypolicyviolation", (event) => {});
onsecuritypolicyviolation = (event) => {};
```
## Event type
A {{domxref("SecurityPolicyViolationEvent")}}. Inherits from {{domxref("Event")}}.
{{InheritanceDiagram("SecurityPolicyViolationEvent")}}
## Examples
The code below shows how you might add an event handler function using the `onsecuritypolicyviolation` event handler property or call `addEventListener()` method.
```js
self.onsecuritypolicyviolation = (e) => {
// Handle SecurityPolicyViolationEvent e here
};
self.addEventListener("securitypolicyviolation", (e) => {
// Handle SecurityPolicyViolationEvent e here
});
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- The {{domxref("Document/securitypolicyviolation_event", "securitypolicyviolation")}} event of the {{domxref("Document")}} interface
- The {{domxref("Element/securitypolicyviolation_event", "securitypolicyviolation")}} event of the {{domxref("Element")}} interface
- [HTTP > Content Security Policy](/en-US/docs/Web/HTTP/CSP)