Error: UnhandledPromiseRejectionWarning: Error: Invalid character entity

43 views
Skip to first unread message

Marcel

unread,
May 5, 2018, 7:30:18 AM5/5/18
to jsdom
Hi,

first of all I am new to jsdom. I want to write a test for a specific website.

My Code Looks like this:


const jsdom = require("jsdom");
const {JSDOM} = jsdom;
JSDOM.fromURL("https://google.com/").then(dom => {
    console.log(dom.serialize())
});

my expactation is that with this code I get the DOM of the Google website.

But after executing this script the following error message appears:

 node jsdomtest.js
(node:392) UnhandledPromiseRejectionWarning: Error: Invalid character entity
Line: 0
Column: 561
Char: ;
    at error (C:\Users\XXX XXX\node_modules\sax\lib\sax.js:651:10)
    at strictFail (C:\Users\XXX XXX\node_modules\sax\lib\sax.js:677:7)
    at parseEntity (C:\Users\XXX XXX\node_modules\sax\lib\sax.js:937:7)
    at SAXParser.write (C:\Users\XXX XXX\node_modules\sax\lib\sax.js:1485:31)
    at HTMLToDOM._parseWithSax (C:\Users\XXX XXX\node_modules\jsdom\lib\jsdom\browser\htmltodom.js:167:12)
    at HTMLToDOM._doParse (C:\Users\XXX XXX\node_modules\jsdom\lib\jsdom\browser\htmltodom.js:47:75)
    at HTMLToDOM.appendToDocument (C:\Users\XXX XXX\node_modules\jsdom\lib\jsdom\browser\htmltodom.js:43:17)
    at new JSDOM (C:\Users\XXX XXX\node_modules\jsdom\lib\api.js:67:29)
    at request.then.res (C:\Users\XXX XXX\node_modules\jsdom\lib\api.js:168:16)
    at <anonymous>
(node:392) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:392) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Thanks in advance.

stefan.sassenberg

unread,
May 5, 2018, 10:40:20 AM5/5/18
to js...@googlegroups.com


-------- Ursprüngliche Nachricht --------
Von: Marcel <marc...@gmail.com>
Datum: 05.05.18 13:30 (GMT+01:00)
Betreff: Error: UnhandledPromiseRejectionWarning: Error: Invalid character entity

Hi,

please append a catch function applied to the return value of then.

JSDOM.fromURL("https://google.com/").then(dom => {
    console.log(dom.serialize())
}).catch(function(error) {
    console.log(error);
});

Regards

Stefan

Marcel

unread,
May 5, 2018, 1:47:15 PM5/5/18
to jsdom
Thanks for your Reply.
I changed the Code to the following:

const jsdom = require("jsdom");
const {JSDOM} = jsdom;
JSDOM
.fromURL("https://google.com/").then(dom => {
    console
.log(dom.serialize())
}).catch(function (error) {
    console
.log(error);
});


I don't know why this error appears..
Reply all
Reply to author
Forward
0 new messages