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 in Web Workers.

The securitypolicyviolation event is fired when a Content Security Policy is violated in a worker.

The handler can be assigned using the onsecuritypolicyviolation event handler property or using EventTarget.addEventListener().

Syntax

Use the event name in methods like addEventListener(), or set an event handler property.

js
addEventListener("securitypolicyviolation", (event) => { })

onsecuritypolicyviolation = (event) => { }

Event type

A SecurityPolicyViolationEvent. Inherits from Event.

Event 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

Specification
Content Security Policy Level 3
# eventdef-globaleventhandlers-securitypolicyviolation

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
securitypolicyviolation event
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