Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
The sanitize()
method of the Sanitizer
interface is used to sanitize a tree of DOM nodes, removing any unwanted elements or attributes.
It should be used when the data to be sanitized is already available as DOM nodes. For example when sanitizing a Document
instance in a frame.
The default Sanitizer()
configuration strips out XSS-relevant input by default, including <script>
tags, custom elements, and comments. The sanitizer configuration may be customized using Sanitizer()
constructor options.
Note: To sanitize strings, instead use Element.setHTML()
or Sanitizer.sanitizeFor()
. See HTML Sanitizer API
for more information.