Created
April 4, 2011 14:18
-
-
Save jeremys/901709 to your computer and use it in GitHub Desktop.
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 urlToResolve = 'https://github.com/kriskowal/tigerblood/'; | |
var https = require('https'), | |
url = require('url'), | |
jsdom = require('jsdom'); | |
var parsedUrl = url.parse(urlToResolve); | |
var path = parsedUrl.pathname; | |
var options = { | |
host: parsedUrl.hostname, | |
path: path, | |
port: 443 | |
}; | |
https.get(options, function(response) { | |
response.socket.on('error', function(e) { | |
console.log('Error on response socket.'); | |
}); | |
var body = ''; | |
response.on('data', function(chunk) { | |
body += chunk; | |
console.log('Response data.'); | |
}); | |
response.on('end', function() { | |
console.log('Response end.'); | |
// Does not work | |
loadDom(body); | |
// Works | |
setTimeout(function() { | |
loadDom(body); | |
}, 0); | |
}); | |
}).on('error', function(e) { | |
console.log('Error on get.'); | |
}); | |
function loadDom(body) { | |
jsdom.env(body, [], function(errors, window) { | |
console.log('Dom loaded.'); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TypeError: Cannot call method 'emit' of undefined
at CleartextStream. (http.js:1201:9)
at CleartextStream.emit (events.js:81:20)
at Socket.onerror (tls.js:874:17)
at Socket.emit (events.js:64:17)
at Array. (net.js:824:27)
at EventEmitter._tickCallback (node.js:126:26)