jsdom.jsdom missing a “createWindow” method

北城以北 提交于 2019-12-12 11:34:35

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/26492552/jsdom-jsdom-missing-a-createwindow-method

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!