{
 "kind": "tool",
 "slug": "jsdom",
 "path": "tools/jsdom/",
 "name": "jsdom",
 "maker": null,
 "density": "full",
 "crumbs": [
  [
   "Tools",
   "tools/"
  ],
  [
   "Testing",
   "tools/testing/"
  ]
 ],
 "lead": "A browser page inside Node.js, for tests.",
 "chips": [
  {
   "label": "Testing",
   "path": "tools/testing/"
  },
  {
   "label": "NPM"
  }
 ],
 "primary": {
  "label": "Copy install command",
  "copy": "npm install jsdom"
 },
 "links": [
  {
   "label": "GitHub",
   "href": "https://github.com/jsdom/jsdom"
  },
  {
   "label": "Website",
   "href": "https://github.com/jsdom/jsdom#readme"
  }
 ],
 "track": "New versions, deprecation and license changes on your dashboard",
 "verdicts": [
  {
   "key": "license",
   "label": "License",
   "value": "MIT",
   "status": "yes",
   "sub": "Use it in paid apps",
   "quote": "The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.",
   "note": "Keep the MIT copyright and license notice with the package files you ship.",
   "src": "https://github.com/jsdom/jsdom/blob/main/LICENSE.txt"
  },
  {
   "key": "maint",
   "label": "Maintained",
   "value": "Maintained",
   "status": "yes",
   "sub": "Last change Nov 21, 2026",
   "note": "Latest GitHub release Nov 13, 2026. ",
   "src": "https://github.com/jsdom/jsdom"
  },
  {
   "key": "pop",
   "label": "Used by agents' projects",
   "value": "615 projects",
   "status": "info",
   "sub": "#4 of 122 in its category",
   "note": "Dependency in 615 public GitHub projects set up for AI coding agents that we scanned (9.8%).",
   "src": null
  },
  {
   "key": "agent",
   "label": "Agent access",
   "value": "Install only",
   "status": "info",
   "sub": null,
   "note": "Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.",
   "src": null
  }
 ],
 "vfoot": "From the package registry and GitHub, checked daily; card checked Nov 11, 2026.",
 "blocks": [
  {
   "id": "overview",
   "nav": "Overview",
   "h2": "What jsdom does",
   "parts": [
    {
     "t": "prose",
     "text": "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."
    },
    {
     "t": "h3",
     "text": "What people build with it"
    },
    {
     "t": "uses",
     "items": [
      {
       "title": "Front-end tests without a browser",
       "text": "Your test runner checks that a sign-up form shows \"Thanks!\" after a valid email, in a fake page that starts in milliseconds.",
       "idea": false
      },
      {
       "title": "Pull data out of saved web pages",
       "text": "A script reads product names and prices from HTML files you downloaded, using the same selectors as in a browser.",
       "idea": false
      },
      {
       "title": "Clean HTML from users on the server",
       "text": "Comments or posts with formatting go through DOMPurify on your server, which needs a page object that jsdom provides.",
       "idea": false
      },
      {
       "title": "Edit a piece of HTML in code",
       "text": "Your build step adds attributes to links or removes empty paragraphs in an HTML snippet before saving it.",
       "idea": false
      },
      {
       "title": "Check generated emails before sending",
       "text": "A test opens each HTML email your app builds and checks that the unsubscribe link and the right name are there.",
       "idea": true
      },
      {
       "title": "Test widgets for the page title or focus",
       "text": "Code that changes the page title, focus or stored settings is checked in automated runs without a real window.",
       "idea": true
      }
     ]
    }
   ]
  },
  {
   "id": "popularity",
   "nav": "Popularity",
   "h2": "jsdom popularity",
   "parts": [
    {
     "t": "stats",
     "items": [
      {
       "n": "83",
       "of": "/ 100",
       "l": "Gid Score, #51 overall"
      },
      {
       "n": "167M",
       "l": "downloads a week, npm"
      },
      {
       "n": "21.8K",
       "l": "GitHub stars"
      },
      {
       "n": "615",
       "l": "agent projects use it"
      }
     ]
    },
    {
     "t": "small",
     "text": "Gid Score measures public popularity and activity, not quality.",
     "link": "How the Gid Score is calculated",
     "path": "tools/top/"
    }
   ]
  },
  {
   "id": "usage",
   "nav": "How it is used",
   "h2": "How jsdom is used",
   "parts": [
    {
     "t": "list",
     "items": [
      "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%)."
     ]
    },
    {
     "t": "h3",
     "text": "By coding agent"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "369 projects, 11.3%",
       "v": "Claude Code",
       "path": "agents/claude-code/"
      },
      {
       "l": "323 projects, 10.6%",
       "v": "GitHub Copilot",
       "path": "agents/github-copilot/"
      },
      {
       "l": "246 projects, 10.1%",
       "v": "Cursor",
       "path": "agents/cursor/"
      },
      {
       "l": "77 projects, 16.2%",
       "v": "Gemini CLI",
       "path": "agents/gemini-cli/"
      },
      {
       "l": "70 projects, 14.9%",
       "v": "OpenAI Codex",
       "path": "agents/openai-codex/"
      },
      {
       "l": "42 projects, 12.2%",
       "v": "OpenCode",
       "path": "agents/opencode/"
      },
      {
       "l": "34 projects, 12.2%",
       "v": "Devin Desktop",
       "path": "agents/devin-desktop/"
      },
      {
       "l": "30 projects, 9.0%",
       "v": "OpenClaw",
       "path": "agents/openclaw/"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Often used with"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "In 88.3% of its projects",
       "v": "Vitest",
       "path": "tools/vitest/"
      },
      {
       "l": "In 67.5% of its projects",
       "v": "Testing Library",
       "path": "tools/testing-library/"
      },
      {
       "l": "In 68.6% of its projects",
       "v": "Vite",
       "path": "tools/vite/"
      },
      {
       "l": "In 89.3% of its projects",
       "v": "TypeScript",
       "path": "tools/typescript/"
      },
      {
       "l": "In 68.0% of its projects",
       "v": "React",
       "path": "tools/react/"
      },
      {
       "l": "In 66.8% of its projects",
       "v": "Tailwind CSS",
       "path": "tools/tailwindcss/"
      },
      {
       "l": "In 49.6% of its projects",
       "v": "Playwright (JavaScript)",
       "path": "tools/playwright-test/"
      },
      {
       "l": "In 71.1% of its projects",
       "v": "ESLint",
       "path": "tools/eslint/"
      }
     ]
    }
   ]
  },
  {
   "id": "profile",
   "nav": "Profile",
   "h2": "jsdom in practice",
   "parts": [
    {
     "t": "h3",
     "text": "Strengths"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "HTML is parsed the way a browser parses it",
       "v": "The README says jsdom parses the HTML you give it just like a browser does. That includes the implied <code>&lt;html&gt;</code>, <code>&lt;head&gt;</code> and <code>&lt;body&gt;</code> tags, so a fragment ends up as a full document."
      },
      {
       "l": "Three levels of script execution",
       "v": "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>&lt;script&gt;</code> elements."
      },
      {
       "l": "Network requests can be intercepted",
       "v": "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."
      },
      {
       "l": "Console output you can capture",
       "v": "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."
      }
     ]
    },
    {
     "t": "h3",
     "text": "Watch out for"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "The sandbox is not a security boundary",
       "v": "The maintainers write that code inside a page's <code>&lt;script&gt;</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."
      },
      {
       "l": "No layout or rendering",
       "v": "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."
      },
      {
       "l": "Subresources are off, and the default URL breaks relative paths",
       "v": "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."
      }
     ]
    },
    {
     "t": "h3",
     "text": "Opting in to running page scripts"
    },
    {
     "t": "tabs",
     "label": "Example",
     "items": [
      {
       "tab": "Js",
       "code": "const dom = new JSDOM(`<body>\n  <div id=\"content\"></div>\n  <script>document.getElementById(\"content\").append(document.createElement(\"hr\"));</script>\n</body>`, { runScripts: \"dangerously\" });\n\n// The script will be executed and modify the DOM:\nconsole.log(dom.window.document.getElementById(\"content\").children.length); // 1"
      }
     ]
    }
   ]
  },
  {
   "id": "more",
   "nav": null,
   "spy_as": "profile",
   "h2": "More about jsdom",
   "parts": [
    {
     "t": "more",
     "items": [
      {
       "title": "Funding",
       "path": "tools/funding/",
       "items": [
        "Tidelift: https://tidelift.com/funding/github/npm/jsdom"
       ]
      },
      {
       "title": "Head to head",
       "items": [
        {
         "text": "jsdom vs Happy DOM",
         "note": "used together in 37 projects",
         "path": "tools/compare/jsdom-vs-happy-dom/"
        }
       ]
      },
      {
       "title": "Packages around it",
       "items": [
        "vitest: Test runner",
        "@testing-library: DOM testing queries",
        "vite: Build tool",
        "@playwright/test: Real-browser tests",
        "typescript: Typed JavaScript",
        "eslint: Linter"
       ]
      },
      {
       "title": "More in Testing",
       "path": "tools/testing/",
       "items": [
        {
         "text": "Vitest",
         "path": "tools/vitest/"
        },
        {
         "text": "Playwright (JavaScript)",
         "path": "tools/playwright-test/"
        },
        {
         "text": "Testing Library",
         "path": "tools/testing-library/"
        },
        {
         "text": "Jest",
         "path": "tools/jest/"
        },
        {
         "text": "pytest",
         "path": "tools/pytest/"
        },
        {
         "text": "axe-core Playwright",
         "path": "tools/axe-core-playwright/"
        },
        {
         "text": "SuperTest",
         "path": "tools/supertest/"
        },
        {
         "text": "Mock Service Worker",
         "path": "tools/msw/"
        }
       ]
      }
     ]
    }
   ]
  },
  {
   "id": "alternatives",
   "nav": "Alternatives",
   "h2": "Alternatives",
   "parts": [
    {
     "t": "alts",
     "items": [
      {
       "name": "jsdom",
       "me": true,
       "facts": [
        "MIT",
        "Gid 83",
        "167M/wk"
       ]
      },
      {
       "name": "Happy DOM",
       "why": "Pick Happy DOM when test speed matters more than full browser coverage; Vitest calls it faster but missing some APIs.",
       "path": "tools/happy-dom/",
       "facts": [
        "MIT",
        "Gid 71",
        "37.8M/wk"
       ]
      },
      {
       "name": "Cheerio",
       "why": "Pick Cheerio when you only need to read or change HTML with selectors and never run page scripts or events.",
       "path": "tools/cheerio/",
       "facts": []
      },
      {
       "name": "Playwright (JavaScript)",
       "why": "Pick Playwright when the test needs a real browser with layout, screenshots or page navigation.",
       "path": "tools/playwright-test/",
       "facts": []
      }
     ],
     "more": "Compare jsdom with another tool",
     "more_path": "tools/compare/"
    }
   ]
  },
  {
   "id": "start",
   "nav": "Get started",
   "h2": "Get started",
   "parts": [
    {
     "t": "prompt",
     "text": "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."
    },
    {
     "t": "steps",
     "items": [
      {
       "text": "Add jsdom to your project (it needs Node.js 22.22.2+, 24.15.0+ or 26+).",
       "code": "npm install jsdom",
       "src": "https://github.com/jsdom/jsdom/blob/main/README.md"
      },
      {
       "text": "Create a page from an HTML string and use window.document like in a browser.",
       "code": "const jsdom = require(\"jsdom\");\nconst { JSDOM } = jsdom;\n\nconst dom = new JSDOM(`<!DOCTYPE html><p>Hello world</p>`);\nconsole.log(dom.window.document.querySelector(\"p\").textContent); // \"Hello world\"\n",
       "src": "https://github.com/jsdom/jsdom/blob/main/README.md"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Rules for your agent"
    },
    {
     "t": "rules",
     "label": "Paste into AGENTS.md or CLAUDE.md",
     "text": "## jsdom\n- Create documents with `new JSDOM(html, options)` and work through `dom.window` / `dom.window.document`.\n- 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.\n- Do not mash jsdom into Node globals (e.g. `global.window = dom.window`). Run DOM-dependent scripts and tests inside the jsdom environment.\n- 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\"`.\n- Do not rely on layout or rendering. Use `pretendToBeVisual: true` only when code needs `requestAnimationFrame` or a visible `document.visibilityState`.\n- Set up `VirtualConsole` listeners before calling `new JSDOM()`, because errors can occur during parsing.\n- Interceptors and dispatchers are ignored for synchronous `XMLHttpRequest` inside the page.\n"
    },
    {
     "t": "h3",
     "text": "Mistakes to avoid"
    },
    {
     "t": "mistakes",
     "items": [
      {
       "dont": "new JSDOM(htmlFromTheInternet, { runScripts: 'dangerously' })",
       "fix": "Keep the default (no scripts) for HTML you did not write; use a real browser in a sandbox if page scripts must run",
       "why": "Page scripts can escape jsdom and run code on your machine."
      },
      {
       "dont": "global.window = dom.window; global.document = dom.window.document; then running tests in Node's global scope",
       "fix": "Use the test runner's jsdom environment (Vitest environment 'jsdom', Jest jest-environment-jsdom) or run code inside the jsdom window",
       "why": "The jsdom docs advise against mixing jsdom and Node.js globals."
      },
      {
       "dont": "Asserting on getBoundingClientRect(), offsetTop or visibility in jsdom tests",
       "fix": "Test layout and visual results with a real browser (Playwright); keep jsdom tests to content and behavior",
       "why": "jsdom does no layout; in our run getBoundingClientRect().width was 0."
      },
      {
       "dont": "npm install canvas to get canvas and image support with jsdom 31",
       "fix": "npm install @napi-rs/canvas@^1.0.13 next to jsdom",
       "why": "jsdom 31 switched the optional backend; the old canvas package alone no longer enables it."
      },
      {
       "dont": "Reading the document right after new JSDOM(html) when it has scripts that load files",
       "fix": "Wait for DOMContentLoaded (or load), checking document.readyState first",
       "why": "Since version 31, parsing pauses at blocking scripts, so the constructor can return a partly built document."
      }
     ]
    }
   ]
  },
  {
   "id": "faq",
   "nav": "Questions",
   "h2": "Questions",
   "parts": [
    {
     "t": "faq",
     "items": [
      {
       "q": "Will scripts inside my HTML run?",
       "a": "Not by default. Pass runScripts 'dangerously' to run them, and only for HTML you trust.",
       "evidence": {
        "url": "https://github.com/jsdom/jsdom",
        "quote": "As such, the ability to execute scripts embedded in the HTML is disabled by default"
       }
      },
      {
       "q": "Can it take screenshots or measure element sizes?",
       "a": "No. It does no layout or drawing; use a real browser such as Playwright for that.",
       "evidence": {
        "url": "https://github.com/jsdom/jsdom/blob/main/README.md",
        "quote": "Layout: the ability to calculate where elements will be visually laid out as a result of CSS, which impacts methods like getBoundingClientRects() or properties like offsetTop."
       }
      },
      {
       "q": "Can it open a live web address?",
       "a": "Yes, JSDOM.fromURL() fetches the page and follows redirects; cookies from the response go into its cookie jar.",
       "evidence": {
        "url": "https://github.com/jsdom/jsdom/blob/main/README.md",
        "quote": "In addition to the JSDOM constructor itself, jsdom provides a promise-returning factory method for constructing a jsdom from a URL"
       }
      },
      {
       "q": "Why does my Node.js process not exit after the test?",
       "a": "Timers started inside the page keep it running. Call window.close() to stop them.",
       "evidence": {
        "url": "https://github.com/jsdom/jsdom",
        "quote": "If you want to be sure to shut down a jsdom window, use window.close() , which will terminate all running timers"
       }
      },
      {
       "q": "Does it work with Vitest and Jest?",
       "a": "Yes. Vitest has a built-in jsdom environment, and Jest ships it in the jest-environment-jsdom package.",
       "evidence": {
        "url": "https://jestjs.io/docs/configuration",
        "quote": "Jest also exposes builtinEnvironments through jest-environment-node and jest-environment-jsdom packages, in case you just want to extend it."
       }
      }
     ]
    }
   ]
  }
 ],
 "glance": [
  [
   "Package",
   "npm jsdom"
  ],
  [
   "Category",
   "Testing"
  ],
  [
   "License",
   "MIT"
  ],
  [
   "Latest version",
   "v30.1.2, October 4, 2026"
  ],
  [
   "On GitHub since",
   "January 2010"
  ],
  [
   "Gid Score",
   "83.4"
  ],
  [
   "Rank in category",
   "#4 of 122"
  ],
  [
   "GitHub",
   "jsdom/jsdom"
  ],
  [
   "Last change",
   "Nov 21, 2026"
  ]
 ],
 "good": [
  "It runs in Node.js only, and recent versions need Node.js 22.22.2, 24.15.0, 26 or newer.",
  "It has no layout. Sizes and positions such as width or offsetTop come back as zero, and clicking a link does not open a new page.",
  "Scripts inside the HTML do not run unless you turn them on. Turned on for pages from strangers, they can reach your machine."
 ],
 "checked_line": "Read by AgentGid from 9 official pages, card checked Nov 11, 2026; numbers update daily.",
 "logo": "https://agentgid.com/media/avatars/jsdom.png"
}