I am trying to get jsdom to work :)
Here's the code:
var jsdom = require("jsdom");
var request = require("request");
var fs = require('fs');
var jquery = fs.readFileSync("./jquery-1.7.2.js", 'utf-8');
request({ uri:'http://nodejs.org/dist/' }, function (error, response, body) {
if (error && response.statusCode !== 200) {
console.log('HTTP request error... '+error);
}
jsdom.env({
html: body,
scripts: [
jquery
],
done: function(errors, window) {
console.log('done');
}
});
});
And here's the error:
jsdom.js:171
features = JSON.parse(JSON.stringify(window.document.implementation._fea
^
TypeError: Cannot read property 'implementation' of undefined
I have checked if the page is fetched and if the jquery lib is parsed - they are.
We could look at the implementation of jsdom.js:
[snip]
exports.env = exports.jsdom.env = function() {
[snip]
window = exports.html(html, null, options).createWindow(),
features = JSON.parse(JSON.stringify(window.document.implementation._features)),
docsLoaded = 0,
[snip]
It seems that the .createWindow() is not successful...
And I am running it on Cloud9.
Any help is welcome.
jsdom is a pure-JavaScript implementation of many web standards, notably the WHATWG DOM and HTML Standards, for use with Node. js. In general, the goal of the project is to emulate enough of a subset of a web browser to be useful for testing and scraping real-world web applications.
JSDOM is a library which parses and interacts with assembled HTML just like a browser. The benefit is that it isn't actually a browser. Instead, it implements web standards like browsers do. You can feed it some HTML, and it will parse that HTML.
jsdom is a JavaScript based headless browser that can be used to create a realistic testing environment.
With the HTML DOM, all nodes in the node tree can be accessed by JavaScript. New nodes can be created, and all nodes can be modified or deleted.
As reported at https://github.com/tmpvar/jsdom/issues/436, this can be caused by contextify not being installed. In theory jsdom has a shim that allows it to work without having contextify which is why it has it listed as a optional rather than required module, but this shim seems to be broken (see https://github.com/tmpvar/jsdom/issues/456).
So as of right now you need to get contextify installed to use the latest jsdom. Depending on your OS and environment there are several reasons that could be a problem. Run npm install contextify and then track down that issue.
Things to try depending on what your root issue is: - Verify you have Python 2.7 or greater and optimally 2.7.3 installed. Also verify its the one that gets run when you type python --version and that your PYTHONPATH is correct. - sudo npm install contextify - npm cache clean; npm install contextify --force
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With