← Back to release summary

onsecuritypolicyviolation event handler IDL attribute

Category
DOM
Type
Chromium catches up
Status
No active development (Chrome No active development)
Intent stage
Dev trials

WPT details: 1. w3c/web-platform-tests/dom/idlharness.window.html 2. w3c/web-platform-tests/html/webappapis/scripting/events/event-handler-all-global-events.html 3. w3c/web-platform-tests/html/webappapis/scripting/events/event-handler-attributes-body-window-expected.txt 4. w3c/web-platform-tests/mathml/relations/html5-tree/math-global-event-handlers.tentative.html

Summary

The securitypolicyviolation event is fired when a Content Security Policy is violated.One can listen to that event via the EventTarget.addEventListener() API. The goal is now to expose the onsecuritypolicyviolation IDL attribute from the GlobalEventHandlers interface, so that one can register a listener by attaching this attribute to target elements.

Motivation

The event is fired on the element that violates the policy and bubbles. It is normally handled by an event handler on the Window or Document object. One can naturally listen to that event via the EventTarget.addEventListener() API. However, web developers are also familiar with the alternative attribute-based form (e.g. element.addEventListener("securitypolicyviolation", ...) Vs on <element.onsecuritypolicyviolation="...">) which is sometimes convenient for quick testing. For consistency with other events, an attribute onsecuritypolicyviolation is thus added.

Standards & signals

Ecosystem

Docs: https://html.spec.whatwg.org/#handler-onsecuritypolicyviolation https://github.com/whatwg/html/pull/2651 https://chromium-review.googlesource.com/c/chromium/src/+/3226366

View on chromestatus.com