SecurityPolicyViolationEvent: violatedDirective 属性

Baseline 已广泛支持

此特性已成熟稳定,适用于多种设备和浏览器版本。自 2018 年 10 月起,它已在各浏览器中可用。

注意:此功能在 Web Workers 中可用。

violatedDirectiveSecurityPolicyViolationEvent 接口的一个只读属性,它是一个字符串,表示被违反的 内容安全策略(CSP) 指令。

它是 SecurityPolicyViolationEvent.effectiveDirective 的历史别名,具有相同的值。

一个字符串,表示被违反的 Content-Security-Policy 指令

示例

js
document.addEventListener("securitypolicyviolation", (e) => {
  console.log(e.violatedDirective);
});

规范

规范
内容安全策略级别 3
# dom-securitypolicyviolationevent-violateddirective

浏览器兼容性