Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jsdom.jsdom missing a "createWindow" method

Tags:

node.js

jsdom

I am trying to use jsdom to analyze some html content. Examples that i have seen use the .createWindow() method of a jsdom.jsdom document based on html content.

But when I try to follow these examples, my document does not have a .createWindow() method.

var getaPage=function (req, res, callback) {
    jsdom.defaultDocumentFeatures={
        FetchExternalResources      : ['script'],
        ProcessExternalResources    : ['script'],
        MutationEvents              : '2.0',
        QuerySelector               : false
    };

    var htmlDoc = '<html lang="en-US">' +
        '</html>';

    var tstDocument=jsdom.jsdom(htmlDoc);
    for (var attr in tstDocument){
        if (attr == 'createWindow') {
            console.log('Found it');
        }else{
            console.log('not it');
        };
    };

};

When I run this, I get a bunch of 'not it' and no 'Found it'.

Why do I not have a .createWindow() method?

like image 987
Skip Huffman Avatar asked Dec 15 '22 19:12

Skip Huffman


1 Answers

jsdom's API changed quite a bit with the 1.0 release. The createWindow() method is from the old API. You should be able to get the document's window just by accessing tstDocument.defaultView, just like you'd do if you were in a browser.

like image 145
Louis Avatar answered Jan 01 '23 19:01

Louis