v152 · DOM · Security
XSS Prevention Guide
Side-by-side comparison of every HTML insertion path: innerHTML (executes scripts), setHTMLUnsafe() (no sanitization), setHTML() with the Sanitizer API (safe), appendHTML() (safe positional), and textContent (text-only escape). Fire XSS payloads at each method and see exactly what gets through.
choose a payload
// XSS alert log — any executed <script> or onerror will appear here
summary table
| Method | Scripts | Event handlers | Decl. Shadow DOM | iframes | Safe for untrusted? |
|---|