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
- Specification: https://html.spec.whatwg.org/
- Firefox: Shipped/Shipping
- Safari: Shipped/Shipping
- Web developers: No signals
- Tracking bug: https://bugs.chromium.org/p/chromium/issues/detail?id=1242893
Ecosystem
- Web Platform Tests: https://wpt.fyi/results/?q=onsecuritypolicyviolation-event-handler-idl-attribute
- Chrome Platform Showcase: https://chrome-platform-showcase.paulkinlan-ea.deno.net/features
- GenDN reference: https://gendn.paulkinlan-ea.deno.net/features
- chrome.dev demos search: https://www.google.com/search?q=site%3Achrome.dev+onsecuritypolicyviolation%20event%20handler%20IDL%20attribute
- MDN Web Docs: https://developer.mozilla.org/en-US/search?q=onsecuritypolicyviolation%20event%20handler%20IDL%20attribute
- Baseline status: https://webstatus.dev/?q=onsecuritypolicyviolation%20event%20handler%20IDL%20attribute
Docs: https://html.spec.whatwg.org/#handler-onsecuritypolicyviolation https://github.com/whatwg/html/pull/2651 https://chromium-review.googlesource.com/c/chromium/src/+/3226366