jsdom: JavaScript web standards implementation for Node.js
Pure JavaScript implementation of web standards for Node.js.
Learn more about jsdom
jsdom is a pure JavaScript implementation of web standards that provides a DOM and HTML parser for Node.js environments. It recreates browser APIs including the Document Object Model, HTML5 Canvas, and Web Storage by implementing WHATWG standards entirely in JavaScript without requiring a headless browser. The library parses HTML markup into a traversable and manipulable document object model, exposing the same APIs that browsers provide such as querySelector, innerHTML manipulation, and event handling. It supports configurable resource loading, script execution contexts, and can simulate various browser behaviors including cookie management and navigation. The implementation prioritizes standards compliance and API compatibility over rendering performance, making it suitable for server-side DOM manipulation, testing, and web scraping scenarios.
Pure JavaScript Implementation
Built entirely in JavaScript with zero native dependencies or binary compilation. Installs consistently across all platforms and Node.js versions without build toolchains or platform-specific complications.
Sandboxed Script Execution
Executes embedded JavaScript in isolated contexts where scripts interact with the simulated DOM. Enables testing of client-side behavior in Node.js environments without spawning browser processes.
WHATWG Standards Compliance
Implements official DOM and HTML specifications with familiar browser APIs like querySelector and addEventListener. Browser code runs in Node.js without rewriting, enabling consistent testing and server-side rendering.
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);
// Extract window and document for easier access
const { window } = new JSDOM(`<html><body><div id="content">Original content</div></body></html>`);
const { document } = window;
// Manipulate the DOM
const contentDiv = document.getElementById("content");
contentDiv.textContent = "Modified content";
const newElement = document.createElement("span");
newElement.textContent = " - Added element";
contentDiv.appendChild(newElement);
console.log(document.body.innerHTML);jsdom 28.0.0 overhauls resource loading customization with a new API and fixes numerous bugs in XMLHttpRequest, WebSocket, and iframe handling.
- –Overhauled resource loading customization. See the new README for details on the new API.
- –Added MIME type sniffing to iframe and frame loads.
- –Fixed XMLHttpRequest fetches and WebSocket upgrade requests to be interceptable by the new customizable resource loading.
- –Fixed the referrer of a document to be set correctly when redirects are involved; it is now the initiating page, not the last hop in the redirect chain.
This release adds TextEncoder/TextDecoder support, significantly improves HTML and XML byte decoding accuracy, and fixes a memory leak with Range objects.
- –Added TextEncoder and TextDecoder.
- –Improved decoding of HTML bytes by using the new @exodus/bytes package; it is now much more correct.
- –Improved decoding of XML bytes to use UTF-8 more often, instead of sniffing for meta charset or using the parent frame's encoding.
- –Fixed a memory leak when Ranges were used and then the elements referred to by those ranges were removed.
This release improves CSS parsing capabilities and CSSOM object APIs through dependency updates.
- –Improved CSS parsing and CSSOM object APIs via updates to @acemir/cssom.
Top in Developer Tools
Related Repositories
Discover similar tools and frameworks used by developers
Nano ID
Compact 21-character cryptographic IDs with URL-safe encoding.
Go
Statically typed, compiled language by Google focused on simplicity, concurrency, and fast compilation.
Babel
JavaScript compiler transforming modern code into browser-compatible versions via AST.
Corepack
Enforces package manager versions specified in package.json.
yay
Go-based AUR helper for Arch Linux that manages packages with dependency resolution and PKGBUILD support.