Skip to content

Instantly share code, notes, and snippets.

@jeremys
Created April 4, 2011 14:18
Show Gist options
  • Save jeremys/901709 to your computer and use it in GitHub Desktop.
Save jeremys/901709 to your computer and use it in GitHub Desktop.
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.');
});
}
@jeremys
Copy link
Author

jeremys commented Apr 4, 2011

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment