1. License
“The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.”
Keep the MIT copyright and license notice with the package files you ship.
github.com/jsdom/jsdom/blob/main/LICENSE.txt3. Used by agents' projects
Dependency in 615 public GitHub projects set up for AI coding agents that we scanned (9.8%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
From the package registry and GitHub, checked daily; card checked Nov 11, 2026. Tap a verdict to see its source.How we checkedReport an error
What jsdom does
jsdom is a free JavaScript library that builds a web page in memory inside Node.js, without opening a browser. Tests can fill forms, click buttons and read the page, and scripts can pull text and links out of HTML. It does not draw anything, so sizes and positions on screen are not real.
What people build with it
Front-end tests without a browser
Your test runner checks that a sign-up form shows "Thanks!" after a valid email, in a fake page that starts in milliseconds.
Pull data out of saved web pages
A script reads product names and prices from HTML files you downloaded, using the same selectors as in a browser.
Clean HTML from users on the server
Comments or posts with formatting go through DOMPurify on your server, which needs a page object that jsdom provides.
Edit a piece of HTML in code
Your build step adds attributes to links or removes empty paragraphs in an HTML snippet before saving it.
Check generated emails before sending Idea
A test opens each HTML email your app builds and checks that the unsubscribe link and the right name are there.
Test widgets for the page title or focus Idea
Code that changes the page title, focus or stored settings is checked in automated runs without a real window.
jsdom popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How jsdom is used
- jsdom is a dependency in 615 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (12.6% of the 4,867 JavaScript/TypeScript ones), #4 of 122 in testing.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 1,293; those are left out of every share on this page.
- The most used alternative in our scan is Happy DOM (122 projects).
- Projects that use it most often also use Vitest (88.3%), Testing Library (67.5%), Vite (68.6%).
- It is more common in projects set up for Gemini CLI (16.2%) than for OpenClaw (9.0%).
By coding agent
Often used with
jsdom in practice
Strengths
The README says jsdom parses the HTML you give it just like a browser does. That includes the implied <code><html></code>, <code><head></code> and <code><body></code> tags, so a fragment ends up as a full document.
By default, scripts in the page do not run. <code>runScripts: "outside-only"</code> installs fresh copies of the JavaScript globals on <code>window</code>, so you can run code against the page through <code>window.eval</code>. The README says this mode is "turned off by default for performance reasons, but is safe to enable." <code>runScripts: "dangerously"</code> also runs the page's own <code><script></code> elements.
The <code>resources</code> option accepts undici interceptors and a custom dispatcher. jsdom's <code>requestInterceptor()</code> helper can inspect a request or return a synthetic <code>Response</code>. The README's example uses it to replace the contents of one specific script.
A virtual console receives both in-page <code>window.console</code> calls and jsdom's own warnings. By default all of it goes to the Node.js console. You can instead attach listeners per console method, or listen for the <code>"jsdomError"</code> event.
Watch out for
The maintainers write that code inside a page's <code><script></code> elements can, if it tries hard enough, reach the Node.js environment and your machine. Use <code>runScripts: "dangerously"</code> only with code you trust.
jsdom acts like a headless browser. <code>pretendToBeVisual: true</code> changes <code>document.hidden</code> and enables <code>requestAnimationFrame</code>. The README stresses that it still does not do any layout or rendering.
Scripts, stylesheets, images and iframes do not load unless you set <code>resources: "usable"</code>. The default <code>url</code> is <code>"about:blank"</code>, so resources with relative URLs fail to load until you set a real URL. Images also require the <code>canvas</code> npm package.
Opting in to running page scripts
const dom = new JSDOM(`<body>
<div id="content"></div>
<script>document.getElementById("content").append(document.createElement("hr"));</script>
</body>`, { runScripts: "dangerously" });
// The script will be executed and modify the DOM:
console.log(dom.window.document.getElementById("content").children.length); // 1More about jsdom
Funding
- Tidelift: https://tidelift.com/funding/github/npm/jsdom
Head to head
- jsdom vs Happy DOM used together in 37 projects
Packages around it
- vitest: Test runner
- @testing-library: DOM testing queries
- vite: Build tool
- @playwright/test: Real-browser tests
- typescript: Typed JavaScript
- eslint: Linter
Alternatives
jsdom This page
Pick Happy DOM when test speed matters more than full browser coverage; Vitest calls it faster but missing some APIs.
Pick Cheerio when you only need to read or change HTML with selectors and never run page scripts or events.
Pick Playwright when the test needs a real browser with layout, screenshots or page navigation.
Get started
Tell your AI assistant
“Use the npm package jsdom (pin jsdom@31.0.0, Node.js 22.22.2+ or 24.15.0+) to load HTML with new JSDOM(html) and query it with window.document; keep runScripts off for HTML you did not write, and call window.close() when done.”
Add jsdom to your project (it needs Node.js 22.22.2+, 24.15.0+ or 26+).
npm install jsdomCreate a page from an HTML string and use window.document like in a browser.
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"
Rules for your agent
## jsdom
- Create documents with `new JSDOM(html, options)` and work through `dom.window` / `dom.window.document`.
- Do not set `runScripts: "dangerously"` for user-supplied or Internet content. The sandbox is not foolproof. Use `runScripts: "outside-only"` with `window.eval` when you only need to run code from outside.
- Do not mash jsdom into Node globals (e.g. `global.window = dom.window`). Run DOM-dependent scripts and tests inside the jsdom environment.
- When loading subresources, set `resources: "usable"` and a real `url`. With the default `about:blank`, relative URLs fail to load. External scripts also need `runScripts: "dangerously"`.
- Do not rely on layout or rendering. Use `pretendToBeVisual: true` only when code needs `requestAnimationFrame` or a visible `document.visibilityState`.
- Set up `VirtualConsole` listeners before calling `new JSDOM()`, because errors can occur during parsing.
- Interceptors and dispatchers are ignored for synchronous `XMLHttpRequest` inside the page.
Mistakes to avoid
Page scripts can escape jsdom and run code on your machine.
The jsdom docs advise against mixing jsdom and Node.js globals.
jsdom does no layout; in our run getBoundingClientRect().width was 0.
jsdom 31 switched the optional backend; the old canvas package alone no longer enables it.
Since version 31, parsing pauses at blocking scripts, so the constructor can return a partly built document.
Questions
Will scripts inside my HTML run?
Not by default. Pass runScripts 'dangerously' to run them, and only for HTML you trust.
Can it take screenshots or measure element sizes?
No. It does no layout or drawing; use a real browser such as Playwright for that.
Can it open a live web address?
Yes, JSDOM.fromURL() fetches the page and follows redirects; cookies from the response go into its cookie jar.
Why does my Node.js process not exit after the test?
Timers started inside the page keep it running. Call window.close() to stop them.
Does it work with Vitest and Jest?
Yes. Vitest has a built-in jsdom environment, and Jest ships it in the jest-environment-jsdom package.