-
-
Save tmpvar/2919673 to your computer and use it in GitHub Desktop.
Script tag not loading
This file contains hidden or 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 jsdom = require('jsdom'); | |
jsdom.defaultDocumentFeatures = { | |
FetchExternalResources : ['script'], | |
ProcessExternalResources : ['script'], | |
MutationEvents : '2.0', | |
QuerySelector : false | |
}; | |
var htmlDoc = '<html lang="en-US">' + | |
'head>' + | |
'<title>Test document</title>' + | |
'<script>' + | |
'var testVar = "foo";' + | |
'</script>' + | |
'<script src=\'http://code.jquery.com/jquery-latest.js\'></script>' + | |
'<script>' + | |
'</script>' + | |
'</head>' + | |
'<body id="mainPage">' + | |
'<script type="text/javascript">document.body.innerHTML = "WOO";</script></body>' + | |
'</html>'; | |
var document = jsdom.jsdom(htmlDoc); | |
var window = document.createWindow(); | |
var elementsArray = window.document.getElementsByTagName('script'); | |
console.log("Elements Arr:", elementsArray.length); | |
console.log("Window.testVar:", window.testVar); | |
window.addEventListener('load', function () { | |
console.log("Window.testVar:", document.body.innerHTML); | |
console.log("Jquery:", typeof window.$ == 'function'); | |
window.close(); | |
}); |
This file contains hidden or 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
tmp‣ node tomlong.js | |
Elements Arr: 4 | |
Window.testVar: foo | |
Window.testVar: WOO | |
Jquery: true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment