Firefox Tomorrow

web api instance property

SecurityPolicyViolationEvent: sample property

View on MDN ↗

Available in workers

The sample read-only property of the SecurityPolicyViolationEvent interface is a string representing a sample of the resource that caused the Content Security Policy (CSP) violation.

This is only for script-src* and style-src* violations, when the corresponding Content-Security-Policy directive contains the 'report-sample' keyword. In addition, this will only be populated if the resource is an inline script, event handler, or style — external resources causing a violation will not generate a sample.

[!NOTE] Violation reports should be considered attacker-controlled data. The content of this field should be sanitized before storing or rendering.

Value

A string containing a sample of the resource that caused the violation, usually the first 40 characters, or the empty string.

Examples

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

Specifications

SpecificationsStandards references are available on the canonical MDN page.

Browser compatibility

Browser compatibilityCompatibility data is available on the canonical MDN page.

See also