SecurityPolicyViolationEvent: sourceFile property

Baseline 已广泛支持

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

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

sourceFileSecurityPolicyViolationEvent 接口的一个只读属性,它是一个字符串,表示发生 内容安全策略 (CSP) 违规的脚本的 URL。

一个字符串,表示发生违规的脚本的 URL;如果违规不在脚本中,则为 null

注意,如果此属性不为 null,则 columnNumberlineNumber 都应具有非空值。

示例

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

规范

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

浏览器兼容性

另见