基本操作的麻烦。jsdom.jsdom在createWindow上返回500个错误。
样本代码:
var getaPage=function (req, res, callback) {
jsdom.defaultDocumentFeatures={
FetchExternalResources : ['script'],
ProcessExternalResources : ['script'],
MutationEvents : '2.0',
QuerySelector : false
};
//This is someone's sample, my real code is more complex, but this shows the error
var htmlDoc = '<html lang="en-US">' +
'<head>' +
'<title>Test document</title>' +
'<script>' +
'var testVar = true;' +
'</script>' +
'<script src=\'http://code.jquery.com/jquery-latest.js\'></script>' +
'<script>' +
'</script>' +
'</head>' +
'<body id="mainPage">' +
'</body>' +
'</html>';
var tstDocument=jsdom.jsdom(htmlDoc);
var tstWindow=tstDocument.createWindow();
//yeah, I am just trhowing this out for the moment
var contents=[{label:'a label', value:'a value'}];
//real values after I get this thing working
callback(contents);
};我得到了一个500个错误(在nodeJS控制台*).if,我包含了createWindow行。如果我将其注释掉,代码就会运行到完成,并将“内容”返回给调用应用程序。(对此函数的ajax调用只会得到一个".fail“状态,其中包含一个”内部服务器错误“)
*GET /sample/getaPage 500 112 GET 1.49 GET
当我检查tstDocument对象时,没有看到"createWindow“方法。为什么jsdom要创建一个没有"createWindow“方法的对象?
我错过了什么?
发布于 2014-10-22 18:14:43
好了找到我的解决方案了。createWindow不再存在于jsDom中。在defaultView属性中提供了等效函数。如果反对意见比放弃方法更干净,那就太好了。
https://stackoverflow.com/questions/26464893
复制相似问题