mrkeyoor.comAsk

jsdom/jsdomtested 25 Oct 2026commit 7b741bb

jsdom review

Use jsdom for supported DOM logic inside Node with explicit URLs and resource policies.

  • README install 4 s
  • README snippet failed
650/652passed, run exited non-zero
  • 34.4 MB on disk
  • 1 dependency
Webevaluationupdated 04 Dec 2026
+0stars / 7d

jsdom gives Node.js programs browser-style document APIs for parsing HTML, changing elements and testing code that uses the DOM. It implements part of the web platform without rendering pages or calculating layout.

Verdict

Use jsdom for supported DOM logic inside Node with explicit URLs and resource policies. Choose a real browser when layout or navigation determines correctness, and do not treat jsdom as a secure sandbox for hostile scripts. Our October checkout installed dependencies in 9 seconds, but its test command exited 1 after 49 seconds.

jsdom infographic: parse and manipulate documents inside Node.js, plus its uses, our test result, pitfalls and who it suits
Tested 4 December 2026: the README snippet failed with "Cannot find module 'jsdom'". Before that: 25 Oct: 650 of 652 source tests passed; npm install took 4 s.

We ran it

Lab card: what happened when we ran jsdom
Lab card from our sandbox run
Screenshot of jsdom (github.com/jsdom/jsdom)
github.com/jsdom/jsdom
Install✓ · 9s218 packages · 72 MB
Buildn/ano build script
Tests✗ · 49s650 passed · 2 failed of 652 (mocha)
Known vulns20 critical · 1 high · 0 moderate · 1 low (npm audit)
Repo164552 files~4,223,510 lines of source · 549.5 MB · 2 CI workflows · tests dir

Answers from our run

Does jsdom build from source?

Dependencies installed in 9 seconds (218 packages), and the project has no separate build step. We cloned commit 7b741bb into a clean Debian container with 3 CPUs and no project-specific setup.

Do jsdom's tests pass?

No. The project's own test command finished in 49 seconds and reported 650 passed, 2 failed (mocha).

Does jsdom have known vulnerabilities in its dependencies?

npm audit flagged 2 known advisories in the dependency tree at the time of our run.

Who should not use jsdom?

Tests that require real navigation or rendered layout.

What are the alternatives to jsdom?

happy-dom, Playwright, Cheerio. Use jsdom for supported DOM logic inside Node with explicit URLs and resource policies.

Setup3/5In our 2026-12-04 run it installed as the README says in 4 s, but the README’s “Basic usage” example failed as written with “Cannot find module 'jsdom'”.Editor’s note: Dependency installation succeeded, but the quickstart installed canvas instead of jsdom and exact sandbox runtime compatibility is unknown.
Docs2/5The 14,740-character README has no install instructions, and its example failed as written in our 2026-12-04 run.Editor’s note: The README explains execution defaults and configuration; the evidence does not establish a numerical documentation-quality judgment.
Community5/5Last push on 2026-11-26, 21,769 stars and maintainers answered or closed 10 of the 10 most-discussed issues we sampled.Editor’s note: Sampled issues and a maintainer account document discussion, but do not measure representative adoption or support responsiveness.
Maturity4/5Latest release v31.0.1 on 2026-11-13, repository created 2010-01-19 and its test suite did not pass in our sandbox (650 of 652 passed).Editor’s note: Recent releases coexist with explicit browser-scope limits and a failed older source test command; no numerical maturity rubric was measured.

How we score

Discussed on

  1. hnScraping Web Pages With jQuery, Node.js and Jsdom88 points
  2. hnFrom Karma to Mocha, with a taste of jsdom31 points
  3. hnJsdom 4.0 – JavaScript standards-compliant DOM for io.js18 points
  4. hnHappy-DOM: a jsdom alternative that can server side render web components17 points
  5. hnServer-side DOM manipulation in Node.js with JSDOM, JQuery, and Mustache10 points

Who it’s for

Developers testing DOM logic inside Node.js with explicit control over page URLs and network behavior.
HTML-processing tools that need browser-style document APIs.
Vitest teams choosing environments per file according to the APIs each test needs.

Who it’s NOT for

Tests that require real navigation or rendered layout.
Text extraction that depends on layout-sensitive innerText behavior.
Services treating script execution in jsdom as a secure boundary for arbitrary downloaded code.

Setup reality

Our October 25, 2026 run at commit 7b741bb installed dependencies in 9 seconds, recording 218 dependencies and 72 MB on disk. No build target existed. Tests exited 1 after 49 seconds: the parser reported 650 passed and 2 failed out of 652, while the log tail contains additional passing-group summaries. npm audit reported 2 known vulnerabilities, 1 high and 1 low.

The December 4 quickstart targeted commit a9029cfca467. Cloning took 3 seconds. The recipe installed @napi-rs/canvas 1.2.1 in 4 seconds, recorded 34.4 MB of node_modules and 1 package besides @napi-rs/canvas, then failed in 0.1 seconds with Cannot find module 'jsdom'. Teardown succeeded. This was an incomplete package-setup reproduction.

The October sandbox configuration was 3 CPUs, 8 GB RAM and image lab-node:22. The December configuration was 2 CPUs and 4 GB RAM. The jsdom 31.0.1 manifest requires Node ^22.22.2 || ^24.15.0 || >=26.0.0.

Use jsdom for DOM logic; use a browser for page behavior

Use jsdom for supported document APIs inside Node.js; choose a real browser when layout or navigation determines correctness. In our October source run, installation succeeded in 9 seconds and the test command exited 1 after 49 seconds. Those results describe contributor setup at commit 7b741bb. The tool-choice distinction comes from the project's scope: jsdom implements a subset of the web platform rather than the browser that displays and navigates a document.

The library creates a window and document that a Node program can inspect and modify. That supports checking generated markup, exercising DOM-dependent code and processing HTML through familiar interfaces. The package documentation describes testing and scraping as intended uses. A document-tree assertion and a rendered-page assertion ask different questions. An element's text or attributes, a redirect decision and the page reached after navigation each call for an environment that implements the relevant behavior.

What people use jsdom for

Giuseppe Cunsolo used jsdom for React 19 component and page tests in Salade Tomate Oignon, while issue reporters used it for text conversion and graphics-library integration. These examples show why describing jsdom only as an HTML parser misses part of the decision. The same document interfaces can support application tests, extraction and library integration, but each task depends on a different set of APIs.

Who used it Task and outcome Decision it informs
Giuseppe Cunsolo, Salade Tomate Oignon React and Vitest tests were green under jsdom. Moving to happy-dom exposed unmocked fetch calls and changed animation timing. Environment behavior can affect what a passing test means.
The html2text reporter in issue #1245 Requested innerText because textContent was inconvenient for readable-text conversion. Text nodes and displayed text are different requirements.
lehni, discussing paper.js in issue #1368 Used parsing and serialization shims, including an SVG tag-name workaround. List the exact parsing and serialization interfaces your integration calls.
Haz, @diegohaz Recommended happy-dom by default with jsdom selected for particular files. Environment selection can happen per test file.

The historical React core request in issue #1030 concerned Web Components and an incompatible webcomponents.js polyfill; that issue is closed. In issue #1368, ianks also reported undefined Document properties while parsing a SOAP response, and a maintainer later reported implementing DOMParser. These are separate integration histories: one concerns component APIs, another parsing and serialization, and another the properties returned for a particular XML input.

What happened when we ran it

Our December 4 quickstart failed with Error: Cannot find module 'jsdom' after the recipe installed canvas instead of jsdom. The run targeted commit a9029cfca467 in a fresh unprivileged lab-node:22 container with 2 CPUs, 4 GB RAM, no published ports and no secrets. It selected the README's two-line Basic usage block and ran it unedited with Node.

December quickstart step Recorded answer Verdict Why
Did cloning finish? Clone completed in 3 seconds. Completed The recipe reached installation.
What did installation install? npm install @napi-rs/canvas@latest installed version 1.2.1 in 4 seconds; the README command named @napi-rs/canvas@^1.0.13. Wrong package for the import The next snippet required jsdom.
What occupied node_modules? 34.4 MB after installation. Recorded This size belongs to that installation.
How many other packages were recorded? 1 package besides @napi-rs/canvas. Recorded This is the recipe's dependency count.
Did the snippet execute? Failed in 0.1 seconds with exit 1 and Error: Cannot find module 'jsdom'. Failed at module loading The recipe had installed canvas.
What did the automated finding say? It labeled the result snippet-failed and said the README snippet did not run as written. Diagnosis narrowed The command history identifies an incomplete package setup.
Did teardown finish? Teardown: ok. Completed Cleanup was recorded separately.

The automated snippet label overstates what the command history shows. The failure happened while Node tried to resolve the imported package, after the recipe installed @napi-rs/canvas. The useful finding is an incomplete quickstart reproduction, with the failed step retained above. The constructor example later on this page follows the README's import and Basic usage patterns rather than correcting a demonstrated constructor failure.

Our separate October 25, 2026 source run used commit 7b741bb, with 3 CPUs, 8 GB RAM and the image label lab-node:22. We measured dependency installation, the available build step and the repository test command. The checkout scan counted 164,552 files, approximately 4,223,510 source lines and 549.5 MB, plus two CI workflow files and a tests directory. It found no Dockerfile.

October source-check step Recorded result Meaning
npm installation Succeeded in 9 seconds; 218 dependencies recorded; 72 MB on disk Dependency installation completed.
Build No build script or target; skipped The harness had no build target to run.
Test command Exit 1 after 49 seconds; parser summary: 650 passed, 2 failed out of 652 The command failed.
npm audit 2 known vulnerabilities: 1 high, 1 low, 0 critical, 0 moderate These findings belong to that dependency snapshot.

The log tail contains 650 passing (18s), followed by 186 passing (3s), 557 passing (4s), 876 passing (7s), 162 passing (810ms), 0 passing (58ms) and finally 2 failing. The parser's 652 therefore differs from the wider set of group summaries visible in the tail. The outcome to carry into a setup decision is straightforward: installation finished, the build stage was skipped, and the test command failed.

Where people get stuck: origins, navigation and text extraction

An explicit page URL addresses the opaque-origin storage error in issue #2304; navigation and readable-text extraction involve different behavior. Grouping these reports under one list of missing browser APIs would hide the configuration fix for storage. The issue discussions also distinguish jsdom's window from Node globals and the test runner that connects them, which matters when a dependency receives a different implementation of an API.

Symptom Report or explanation Next choice
Issue #2304: SecurityError: localStorage is not available for opaque origins Domenic identifies the default about:blank URL and tooling that copies window properties. Set an explicit URL through jsdom or the test environment.
Issue #2112: Not implemented: navigation Domenic says setting window.location.href produces this message because jsdom does not support navigation. Isolate redirect decisions with an injected window; use a browser for the page change.
Issue #1245: missing innerText The open request concerns readable text and its dependence on layout. Choose an extraction method according to whether displayed text matters.
Issue #2524: TextEncoder and TextDecoder Historical Jest users supplied Node util implementations through setup or a custom environment. Identify which environment supplies the missing global.

Epic Web's Why I Won't Use JSDOM demonstrates a jsdom-created event rejected by Node's EventTarget with ERR_INVALID_ARG_TYPE. It also criticizes browser export conditions selecting browser dependency bundles while execution happens in Node. That second complaint concerns test-environment integration. For environment annotations, the historical Jest discussion says the docblock belongs at the beginning of the file and applies to the whole suite; placing it inside an individual test was the reported mistake.

For extraction, reading text nodes may fit indexing or a transformation with a known input format. Reproducing line breaks, hidden content and text as displayed asks for layout-dependent behavior. The innerText discussion gives that distinction a concrete API name. Both innerText and textContent concern text, but the requested html2text conversion concerns readable output rather than simply retrieving the text nodes present in the document.

Script execution is disabled by default and needs a trust decision

Embedded scripts are disabled by default, and the README warns that enabled page scripts can reach Node.js and the host machine. The package documentation makes that trust decision explicit. A document-inspection tool can leave embedded scripts off. A controlled fixture that needs page execution must deliberately enable it, rather than inheriting a tutorial's assurance that a simulated browser provides a secure execution boundary.

runScripts: "dangerously" enables embedded scripts. External script elements additionally need resource loading, such as resources: "usable". Set a meaningful url for relative addresses: the default about:blank fails as a base for relative resources. These options control separate things: code execution, resource fetching and URL resolution. The outside-only mode instead installs fresh JavaScript globals on the window and supports code executed from the surrounding Node program.

Document readiness also changes what an assertion sees. The README says parsing pauses when a blocking script waits for a resource, so the constructor can return with a partially built document. It directs callers to wait for DOMContentLoaded for the finished tree, or load when load-delaying resources matter, checking document.readyState before subscribing. A missing later element can therefore be a timing problem rather than a parsing failure.

Switching to happy-dom can change more than speed

Cunsolo's migration exposed fetch and computed-style differences, including 3 failing tests and 406 ECONNREFUSED 127.0.0.1:3000 errors on the first run. His migration account separates narrowing coverage from changing the DOM environment. He reports local DOM-spec time falling from 67 to 47 seconds after that separation, and attributes 24% of CI test time to building the jsdom environment.

The network difference explains more than the headline timing. In his jsdom setup, Node's fetch rejected relative URLs, and the game treated the result as offline. Happy-dom resolved those paths and attempted network requests. Cunsolo blocked fetch in test setup, then allowed individual tests to stub the responses they needed. An API's rejection of a relative URL had been acting as the suite's network-isolation policy.

For the opacity comparison, Cunsolo names jsdom 30.1.3, happy-dom 21.0.4, Vitest 5.0.5 and Motion 14.12.0 as the examined versions on November 16. An unstyled element returned "1" under jsdom and an empty string under happy-dom. Motion interpreted the empty value as zero and finished an exit immediately. He changed two transient-state tests to synchronous fireEvent.click, retaining userEvent elsewhere.

A migration checklist follows directly from those failures: identify which fetch implementation each test calls, block unintended network traffic explicitly, compare computed-style values consumed by animation code, and inspect assertions about short-lived states. Keep coverage settings constant during the environment comparison. Otherwise a faster run can combine changes to instrumentation, environment construction and application behavior, leaving the team unable to connect a timing change to the relevant cause.

Maintenance includes delivered work, not just a label

Domenic calls jsdom a maintenance-mode project while also reporting a v28 resource-loading rewrite and five difficult issue closures. His maintenance account provides both parts of that picture. The GitHub metadata checked on December 4 lists the last push as November 26, 2026, and the latest-release response identifies v31.0.1, published November 13. Maintenance mode and delivered changes coexist here.

The historical memory/resource issue #154 describes repeated document creation and script execution, including a loop of 10,000 iterations. A maintainer confirmed that contexts were not being freed, and participants reported unsuccessful patch attempts. Its closed status records the tracker outcome. For a reader considering repeated document creation, the useful distinction is between that historical report, Domenic's account of later maintenance work and the date of the latest checked release.

jsdom vs happy-dom, Playwright and Cheerio

jsdom supplies DOM APIs inside Node, while the cited alternatives cover DOM emulation, actual-browser testing and simpler HTML manipulation. Cunsolo's migration, Epic Web's testing choices and Domenic's recommendations offer decision points without turning these tools into a single ranking. Choose according to the behavior that decides correctness, then keep assertions and environment configuration aligned with that choice.

Choice Evidence-backed reason to consider it Decision point
jsdom Browser-style document APIs inside Node; Haz values its specification coverage. Does the assertion concern supported document behavior?
happy-dom Cunsolo reports a 67-to-47-second local DOM-spec change. Compare fetch, styles and transient states during migration.
Vitest Browser Mode with Playwright Epic Web chooses browser component integration tests. Vitest documents browser initialization costs and a continuing role for end-to-end runners.
Playwright Epic Web retains it for end-to-end tests. Does the test exercise a browser workflow?
Cheerio Domenic recommends it for minimal scraping or DOM manipulation in Node. Is simpler HTML processing enough?

Vitest Browser Mode does not completely replace standalone end-to-end runners. Its documentation recommends supplementing it with a runner such as Playwright. A mixed DOM setup is another option: Haz recommends happy-dom by default and jsdom overrides for files needing its coverage. These choices divide a suite according to its assertions instead of requiring every test to use the same environment.

Outdated claims, corrected

The jsdom.org guides and Testim's getting-started article contain execution claims or examples that conflict with the package documentation. The corrections concern script defaults, resource loading, the constructor import and release requirements. They change how a reader would configure or start a program, so the repository documentation and the selected release's manifest should take precedence over an older search result.

The jsdom.org guides A Complete Guide, the Node.js guide, Server-Side DOM Manipulation and Testing, and Advanced Applications and Best Practices state or imply that inline scripts execute automatically. The package documentation says embedded execution is disabled by default. Their manual-loading advice also omits the combination of usable resources and enabled script execution for external scripts. Manual fetching is an option, rather than a universal requirement.

The jsdom.org homepage describes secure execution, Node 12 compatibility and no additional dependencies. The package warning contradicts the unqualified security assurance. The jsdom 31.0.1 manifest requires Node ^22.22.2 || ^24.15.0 || >=26.0.0 and declares runtime dependencies. npm resolving dependencies automatically does not make the package dependency-free, and a major Node version alone does not capture that patch-level requirement.

Testim's first example assigns require("jsdom") to jsdom but then uses an undeclared JSDOM. Extract the named constructor as the README does. The vendored historical README instead documents older jsdom.env and jsdom.jsdom APIs. Separately, Advanced Techniques and Practical Use Cases overstates the network restriction: the package docs describe subresources, XMLHttpRequest and WebSocket, while Cunsolo identifies missing fetch as the narrower issue. Promises of identical browser-script behavior also conflict with the navigation and cross-implementation event reports.

Questions people ask

jsdom implements DOM and HTML APIs for Node.js so programs can parse and manipulate documents without a rendered page. The README describes its goal as a useful subset of a browser for testing and scraping. That distinction answers the basic usage question and connects the installation, release and environment choices below: Node runs the program, while jsdom supplies the document interfaces.

What is jsdom, and what is it used for?

jsdom is a JavaScript implementation of DOM and HTML standards for Node.js. Programs use it to parse markup, query elements and modify documents through browser-style interfaces. The package documentation names testing and scraping as its goals. A first document test can assert an element's text or attributes, using the window and document returned by the constructor.

How do I install jsdom from npm and create my first DOM?

The jsdom package exposes the JSDOM named constructor, and the README demonstrates a string passed to it and a paragraph query. Install with npm install jsdom; the dependency named by the import must be present before Node can construct the document. This example follows the README's import and Basic usage patterns and includes its documented text output:

const jsdom = require("jsdom");
const { JSDOM } = jsdom;

const dom = new JSDOM(`<!DOCTYPE html><p>Hello world</p>`);
console.log(dom.window.document.querySelector("p").textContent); // "Hello world"

What is the latest jsdom version, and what changed in versions 30 and 31?

GitHub's latest-release response checked on December 4, 2026 identified v31.0.1, published November 13. The dated metadata identifies the release tag and publication time. For the historical opacity comparison discussed here, Cunsolo names jsdom 30.1.3, happy-dom 21.0.4, Vitest 5.0.5 and Motion 14.12.0; those are the versions attached to that specific computed-style observation, rather than a change list for either major release.

Which Node.js versions does my jsdom release support?

jsdom 31.0.1 requires Node ^22.22.2 || ^24.15.0 || >=26.0.0, according to its npm manifest. The README directs readers to the engines field for release requirements. Match that complete range, including patch versions, to the runtime you intend to use; the requirement belongs to this release rather than to every historical jsdom version or every runtime carrying the Node 22 label.

Where are the official jsdom GitHub repository and documentation?

The official repository is jsdom/jsdom, whose README documents the constructor, configuration and project scope. The manifest also points to the repository's issue tracker. Start with that README when a tutorial teaches a different constructor pattern, then use the installed release's metadata for its Node requirement and the issue discussion for the specific behavior under investigation.

Should I use jsdom or Playwright for browser-facing tests?

Use a real browser when navigation or rendered-page behavior decides correctness. Epic Web's author uses Vitest Browser Mode for component integration and Playwright for end-to-end tests. That division can coexist with document tests in jsdom: an assertion about markup and an assertion about a browser journey need different environments because they exercise different behavior.

How do jsdom and happy-dom compare for speed and browser API compatibility?

Cunsolo reports local DOM-spec time falling from 67 to 47 seconds, alongside fetch and computed-style differences that required test changes. His migration account separates the coverage change from the environment change. Its concrete failure cases identify useful comparison fixtures: relative fetch URLs, unstyled opacity values and assertions about screens disappearing during an interaction.

Should I switch Vitest from jsdom to happy-dom or use both per file?

Haz recommends happy-dom by default with jsdom overrides for files needing its broader specification coverage. The recommendation supplies a way to divide tests by their API requirements. Files whose assertions depend on different environment behavior can retain jsdom, while Cunsolo's fetch and animation examples identify behaviors to inspect when moving other files to happy-dom.

What we have not tested yet

The October source test command failed, and the December quickstart stopped before importing jsdom successfully. We have not tested the corrected README example, reconciled all test-group counts, identified the two failing assertions or checked exact sandbox toolchain logs. The lab-node:22 label identifies an image, not an actual runtime or operating-system version. The audit summary names neither affected packages nor exploitability; checkout scan totals are not npm-package size measurements.

The October commit 7b741bb and December commit a9029cfca467 are separate from the v31.0.1 release check. The release metadata establishes v31.0.1 and its publication timestamp, but no version-matched release-note text or checked diff establishes its individual changes here. We have not audited all changes across majors 30 and 31, run controlled comparisons against happy-dom, Cheerio, LinkeDOM or Playwright, or measured long-running memory reclamation. Cunsolo's timing result belongs to his project, and Haz's post supplies a recommendation rather than a measured migration outcome.

The historical Web Components, XML serialization, SOAP, TextEncoder and memory reports do not settle current compatibility for a particular application. The articles contain no substantive LinkeDOM or jest-dom comparison, and video records contain no transcript supporting another walkthrough finding. The cited event and export-condition discussions supply no universal interoperability fix. Rendered layout, resolved links, accessibility, related links, recommendation modules and template content received no execution check in this text revision. A representative application fixture with an explicit URL, network policy and expected document changes would address the next practical question on the release intended for deployment.

Alternatives

ProjectWhat it isPick it when
happy-domAn alternative DOM environment used in Cunsolo's Vitest migration.Consider it when environment overhead matters, and compare fetch, computed-style and transient-state behavior in your tests.
Playwright gh↗Browser automation retained by the Epic Web author for end-to-end tests.Choose a browser path when navigation and rendered-page behavior determine correctness.
CheerioDomenic's recommendation for minimal scraping or DOM manipulation in Node.Consider it when simpler HTML processing covers your task without a script-executing document environment.

Sources

  1. jsdom
  2. registry.npmjs.org/jsdom/31.0.1
  3. The Wrong Work, Done Beautifully
  4. jsdom or happy-dom? What I learned by switching
  5. Why I Won’t Use JSDOM
  6. Haz (@diegohaz) on X
  7. Error: Not implemented: navigation
  8. Implement HTMLElement innerText

More web reviews