Last active
December 7, 2023 16:38
-
-
Save eligrey/b4530639c3deed04e1b32d7a3cae52cc to your computer and use it in GitHub Desktop.
Execute all scripts in a document. You'll need this if you're inserting external documents.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var doc = (new DOMParser).parseFromString("<html><script>alert(1)</script></html>", "text/html"); | |
document.replaceChild(doc.documentElement, document.documentElement); | |
execute_scripts(); // alert(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var execute_scripts = function() { | |
for (let script of Array.from(document.scripts)) { | |
script.replaceWith(document.importNode(script, true), script); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment