Skip to content

Instantly share code, notes, and snippets.

@nym
Created June 12, 2012 17:40
Show Gist options
  • Save nym/2918959 to your computer and use it in GitHub Desktop.
Save nym/2918959 to your computer and use it in GitHub Desktop.
Script tag not loading
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);
console.log("Window.testVar:", document.body.innerHTML);
window.addEventListener('load', function () {
console.log("Jquery:", typeof window.$ == 'function');
window.close();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment