These days there's almost nothing you can't do in Deno that you can do in Node. If you think there is, please reply here but I think that time has passed.
These days there's almost nothing you can't do in Deno that you can do in Node. If you think there is, please reply here but I think that time has passed.
My use case was trying to run Playwright to scrape a site, copy the resultant HTML into jsdom, then run Mozilla's `readability` module on that to get a summary of the page. I found a replacement for Playwright (astral), and `readability` seems to be runtime agnostic as long as it has access to DOM APIs, but jsdom doesn't work with Deno yet.
I'd love to hear if there's an alternative to jsdom that I could use, because I unfortunately can't switch entirely over to NodeJS in this particular project, so either I find a replacement server-side DOM library, or I need to juggle two runtimes for different parts of the project. :/
// from https://gist.github.com/kt3k/6123515ff5d1e167f82dfe4aa12ee5d9
import { JSDOM } from "https://jspm.dev/jsdom";
const doc = new JSDOM(`<!DOCTYPE html><p>Hello world</p>`);
console.log(doc.window.document.querySelector("p").textContent);
Run it like this: deno run 'https://gist.githubusercontent.com/kt3k/6123515ff5d1e167f82dfe4aa12ee5d9/raw/f27520c629e56ab6e53e411c455ecc289300bb28/jsdom-in-deno.ts'
This returns "Hello world" on my machine, deno 2.3.1I'd need more info about your problem but I'm not convinced that Deno's the problem and if there is one.
All of the simple cases I've tried seem to work fine, e.g:
import { JSDOM } from "npm:jsdom";
const dom = new JSDOM(
`<!DOCTYPE html><p>Hello world <img src="https://example.com/logo.svg" /></p>`,
);
console.log(dom.window.document?.querySelector("p")?.textContent); // "Hello world"
console.log(dom.window.document?.querySelector("img")?.getAttribute("src")); // "https://example.com/logo.svg"I'll try again with a clearer head tomorrow, and maybe if I figure stuff out I can create a proper reproduction, but right now I don't know how to reproduce anything because it doesn't seem like my local environment is consistently reproducible, let alone trying to create something that would work on other machines. I'm surprised at how poor this behaviour is — I thought a big part of Deno@2 was to fix these sorts of dependency issues.