Reputation: 45
node v8.10.0
Why does new JSdom API throw errors?
"*Error: Not implemented: window.scrollTo*"
"*Error: Uncaught [TypeError: Cannot read property 'origin' of undefined]*"
"*Error: Uncaught [TypeError: Cannot read property 'removeAttribute' of null]*"
etc.
OLD API (works fine); [jsdom v11.3.0]
var jsdom = require("jsdom/lib/old-api.js");
var url = 'https://www.wp.pl';
var requestData = request(url, function(err, resp, HTMLdata) {
if (!err && resp.statusCode === 200) {
console.log('Request success - we render jsdom page \n');
jsdom.env({
html: HTMLdata,
features: {
FetchExternalResources : ['script'],
ProcessExternalResources : ['script'],
SkipExternalResources: false
},
done: function (err, window) {
if (err) {console.log('ERR: ' + err);}
var document = window.document;
window.close();
}
});
}
});
NEW API: [jsdom v15.1.1]
const jsdom = require('jsdom');
const {JSDOM} = jsdom;
var url = 'https://www.wp.pl';
var requestData = request(url, function(err, resp, HTMLdata)
{
if (!err && resp.statusCode === 200){
console.log('Request success - we render jsdom page \n');
var JSdom1 = new JSDOM(HTMLdata,
{
url : url,
referrer : url,
runScripts : 'dangerously',
resources : 'usable'
});
if (JSdom1.onload){}
}
});
for example because of new API:
"*%cWarning! background:red;color:white;font-weight:bold; WPJSlib is embedded incorrectly, probably 'src' is incorrectly extended. Contact ATFD for further information.*"
What I'm doing wrong? Any idea how to fix that?
Upvotes: 1
Views: 1285
Reputation: 569
jsdom's new API automatically creates a virtual console for you that's piped to the real (node's) console. Previous versions of jsdom used to hide those errors.
You can simply provide an empty VirtualConsole
instance in the options which will hide those errors again:
const virtualConsole = new jsdom.VirtualConsole();
const dom = new JSDOM(``, { virtualConsole });
Upvotes: 1