Skip to content

Instantly share code, notes, and snippets.

@jimmywarting
Last active March 23, 2025 07:57
Show Gist options
  • Save jimmywarting/0dfe134f82353ecea8d32b9667d91f7c to your computer and use it in GitHub Desktop.
Save jimmywarting/0dfe134f82353ecea8d32b9667d91f7c to your computer and use it in GitHub Desktop.
html to safe node (document)

This is for when you are building a library and csp are in the way and require you to use trustedTypes html

var toSafeNode=(h,x=new XMLHttpRequest)=>(x.send(x.open('GET',URL.createObjectURL(new Blob([h])),0)),x.responseXML)
var fragment = toSafeNode('<div>hej</div>')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment