Friday 25 October 2019

How do I use jsdom with a URL instead of a string containing HTML code?

On the jsdom npm package page, the following example is given:const dom = new JSDOM(`

Hello world

`); console.log(dom.window.document.querySelector("p").textContent); // "Hello world" Another example is given for using a URL instead of a string:const dom = new JSDOM(``, { url: "https://example.org/", referrer: "https://example.com/", contentType: "text/html", includeNodeLocations: true, storageQuota: 10000000 }); However, every other example seems to use the first example as a template instead of the second. Further, when I run console.log(dom) on the first example, I can see that dom contains data. However, when I run console.log(dom) on the second example (using an actual URL), dom is set to null.I'm having trouble finding guides on how to use this package, and the stuff I'm finding appear to be older, referencing jsdom.env and other things that the npm page I linked doesn't do. Could anyone tell me the correct way of using this package with a URL, or point me to a good guide or documentation for this package?

Submitted October 25, 2019 at 03:51PM by Bifrons

No comments:

Post a Comment