<input>
's selectionStart
, selectionEnd
, and selectionDirection
getters to return null, instead of throwing, for elements that do not allow selection, per a recent spec change.<base>
's href
getter logic to return the attribute value instead of the empty string for unparseable URLs, per a recent spec change.error
events on window
beyond the first one.new URL
to correctly throw for unparseable URLs, and all of URL
's setters to correctly ignore invalid input instead of throwing.StyleSheetList.prototype.item
to return null
instead of undefined
for out-of-bounds indices. (Ginden)cssstyle
minimum version to ensure all jsdom installs (not just fresh ones) get the benefit of cssstyle
's recently-better background
and width
setters.jsdom.changeURL(window, newURL)
for allowing you to override a window's existing URL. (mummybot)proxy
option to be applied to all requests; previously it was not always passed through. (nicolashenry)XMLHttpRequest
response header filtering for cross-origin requests; this also fixes ProgressEvent
s fired from such XHRs. (nicolashenry)FocusEvent
class, and now focus
and blur
events are fired appropriately.tabIndex
now returns 0
by default for focusable elements.navigator
to be to-spec:appCodeName
, product
, productSub
, vendor
, and vendorSub
; also changes userAgent
, appName
, platform
, and version
to be more browser-like instead of based on various Node.js information.language
and languages
.onLine
.javaEnabled()
.noUI
.formEl.action
to return a value resolved relative to the document URL, or to return the document URL if the corresponding attribute is missing or empty.window.close()
not correctly clearing event listeners on the document. (Ojek)"jsdomError"
will now be emitted to the virtual console.This major release removes jsdom's support for mutation events. Mutation events were never well-specified, and the modern DOM Standard omits them in the hopes that they can be removed from browsers (although this has not yet happened in major browser engines). We had hoped to implement their modern alternative, mutation observers, before performing this removal, to give jsdom users the same capabilities.
However, recent performance investigations revealed that mutation events were the major bottleneck in most jsdom operations; tools like ecmarkup which make heavy use of jsdom had their running time halved by removing mutation events, which add serious overhead to every DOM mutation. As such, we are doing a major release with them removed, so that jsdom users can benefit from this massive performance gain.
Mutation observer support is in progress; please use the GitHub reactions feature to vote on that issue if you are impacted by this removal and are hoping for mutation observer support to replace it.
Your normal change log follows:
DOMTokenList.prototype.replace
method. (nicolashenry)DOMTokenList.prototype.contains
to no longer validate its arguments, as per the latest spec. (nicolashenry)responseURL
property.ByteString
algorithm.statusText
to be ""
instead of "OK"
.Blob
constructor's type
validation. (nicolashenry)jsdom.env
, when given a URL or file, will decode the resulting bytes using signals like the Content-Type
header, <meta charset>
declaration, or presence of a BOM, in the same manner as web browsers.<script>
/<link>
/<iframe>
tags, will also account for such signals.jsdom.jsdom()
, which takes a string, still sets a "UTF-8" encoding by default, since there are no bytes or headers for it to sniff an encoding from.iframe.sandbox
property, since it was not implemented and simply crashed when used.element.sourceIndex
property, since it was nonstandard (Internet Explorer only).doc.body
's onload=""
attribute, for documents that do not have a browsing context.selected
on an multi-select would clear all other selectedness.TreeWalker
class (and document.createTreeWalker
). (garycourt)URL
API, by upgrading to whatwg-url
2.0.1.Object.prototype
, spurious attributes would show up on your jsdom nodes. (deckar01)canvas
npm package is installed (lehni). In practice, this means that if you enable fetching "img"
external resources, then:img.naturalWidth
, img.naturalHeight
, img.width
, img.height
, img.complete
, and img.currentSrc
will update themselves correctly as the image loadsload
and error
events will fire on the <img>
element, according to how well image decoding goes.canvasContext.drawImage
API.canvasContext.createPattern
and canvasContext.toBlob
, when the canvas
npm package is installed. (lehni)document.hidden
property that always returns true
, and a document.visibilityState
property that always returns "prerender"
. This is a more standard alternative to our proprietary navigator.noUI
, which will be removed whenever we release 9.0.0. (kapouer)change
and input
events now fire appropriatelystrictSSL
top-level option to govern all requests jsdom makes. (nicolashenry)document.origin
and document.lastModified
. (nicolashenry)scriptEl.text
getter and setter to follow the spec.attr.nodeName
, which was recently re-added to the spec.<label>
s to their labeled form elements. (yaycmyk)element.classList
per recent spec changes (it forwards to element.classList.value
).element.getAttributeNames()
. (spec addition)setAttributeNode
and setAttributeNodeNS
can now replace an attribute node, instead of removing the old one and adding a new one; this avoids changing the order in the attribute list. (spec change)NamedNodeMap
named properties are now lowercase (except in edge cases involving XML documents or non-HTML elements). (spec change)NamedNodeMap
named properties are now non-enumerable."DOMAttrModified"
mutation event's relatedNode
is now the new Attr
object, not the Node
, as per spec.DOMTokenList
to have a value
property per recent spec changes; its toString
serialization also changed slightly.tc.headers
to be a DOMTokenList
that simply reflects the headers
attribute; previously it was a string, with its computation doing some weird stuff.document.implementation.createDocument()
to create a document with its parsing mode set to XML, which affects a variety of DOM APIs in small ways.EventTarget.prototype.constructor
to be correct; it was previously Window
.option.index
for <option>
s not inside a <select>
to no longer error.tc.cellIndex
for <td>
s and <th>
s not inside a <tr>
to no longer error.tr.sectionRowIndex
for <tr>
s not inside a <table>
, <tbody>
, <thead>
, or <tfoot>
to no longer error."keyevents"
alias for "keyboardevent"
when using document.createEvent
, per recent spec changes.this
value when you pass a { handleEvent() { ... } }
object to addEventListener
. (thetalecrafter)HTMLOptionElement.prototype.label
; a typo was causing it to not work at all. (karlhorky)cssstyle
minimum version to ensure all jsdom installs (not just fresh ones) get the benefit of cssstyle
's recently-better padding
and margin
parsing/CSSOM.navigator.userAgent
in frames and iframes.document.activeElement
implementation to be a bit smarter; we still don't have full focus/blur/active element semantics, but at least now it falls back to the <body>
element when the active element is removed from the document or when no element has been focused yet.this
inside event handler callbacks was not equal to the event's current target. (Surprisingly there were no tests for this!)This major release includes a large rewrite of most of the DOM and HTML classes exposed in jsdom. A lot of their behavior is generated from their specs' IDL syntax, taking care of many type conversions, attribute/property reflections, and much more. Many properties that were previously not present are now available, and almost everything behaves in a more spec-compliant way. Additionally, for these classes all of their implementation details are no longer available as underscore-prefixed properties, but instead are hidden behind a single symbol.
Although normally jsdom does not mark a new major release for changes that simply update us to the latest specs or hide internal implementation details better, the magnitude of the changes is so extensive that we want to bump the major version in order to ensure that consumers perform adequate testing before upgrading. But, you should definitely upgrade! The new stuff is really awesome!
Location
, History
, and HTMLHyperlinkElementUtils
(used by both HTMLAnchorElement
and HTMLAreaElement
) according to the latest specs, and using the latest whatwg-url package. This greatly improves our correctness on URL resolution and navigation (to the extent we support navigation, i.e. pushState
and changing the hash). It should also improve parsing speed as we no longer parse and resolve URLs during parsing.Element.prototype.insertAdjacentHTML
. (kasperisager)Node.prototype.adoptNode
, and adopt nodes during insertion instead of throwing "WrongDocumentError"
s. (dmethvin)Element.prototype.getClientRects
to match our stub getBoundingClientRect
.setTimeout
and setInterval
to return numeric IDs, instead of objects. (alvarorahul)setTimeout
and setInterval
to accept string arguments to eval, and to pass along extra arguments after the first two.Event
object creation to always initialize the event objects, unless using document.createEvent
, even for events with name ""
.DOMException
, DOMConfiguration
, and DOMStringList
.canvasEl.toDataURL()
, with the canvas
npm package installed; a recent update to the canvas
package broke how we were passing arguments to do.data:
URL parsing to allow empty contents, e.g. data:text/css;base64,
. (sebmck)<math xmlns="http://www.w3.org/1998/Math/MathML">
).<input>
and <textarea>
! (sjelin and yaycmyk)<canvas>
tag to reset its contents when its width or height changed, including the change from the default 300 × 150 canvas. (Applies only when using the canvas
npm package.)HTMLCollection
s would get confused when they contained elements with numeric id
s or name
s.postMessage
use the inside-jsdom timer queue, instead of the Node.js one. This allows easier mocking. (cpojer)<iframe>
s have unresolvable URLs, jsdom will no longer crash, but will instead just load about:blank
into them. (This is the spec behavior.)document.writeln
to correctly handle multiple arguments; previously it ignored all after the first.FileList
objects to no longer have a property named "undefined"
. (jfremy)This is a rather large release bringing with it several important re-implementations of DOM and HTML APIs.
EventTarget
implementation has been rewritten from scratch to follow the spec exactly. This should improve any edge case misbehaviors.Event
class hierarchy has been rewritten and fleshed out, fixing many gaps in functionality.KeyboardEvent
and TouchEvent
are now implemented.Event
subclasses now have constructors. (TouchEvent
does not yet, and MutationEvent
is specified to not have one.)document.createEvent("customevent", ...)
now correctly creates a CustomEvent
instead of an Event
, and CustomEvent.prototype.initProgressEvent
has been replaced with CustomEvent.prototype.initCustomEvent
.Attr
class and related attribute-manipulating methods has been rewritten to follow the latest specification. In particular, Attr
is no longer a subclass of Node
, and no longer has child text nodes.<template>
element implementation has been greatly improved, now passing most web platform tests. Its .content
property no longer has an extra intermediate document fragment; it no longer has child nodes; and related parts of the parser and serializer have been fixed, including innerHTML
and outerHTML
, to now work as specified.querySelector
, querySelectorAll
, and matches
now correctly throw "SyntaxError"
DOMException
s for invalid selectors, instead of just Error
instances.Node.prototype
's insertBefore
, replaceChild
, and appendChild
methods now check their arguments more correctly.<script>
code, /regexpliteral/ instanceof RegExp
would be false
.Node.prototype.isEqualNode
:true
for comparing any two doctypes.document.implementation.createDocumentType
requires all three of its arguments.This major release has as its headlining feature a completely re-written XMLHttpRequest
implementation, in a heroic effort by @nicolashenry. It includes a number of other smaller improvements and fixes. The breaking changes are highlighted in bold below.
XMLHttpRequest
and related classes (nicolashenry):Blob
, File
, FileList
, FileReader
, FormData
, ProgressEvent
, and the supporting XMLHttpRequestUpload
, and XMLHttpRequestEventTarget
interfaces.pool
, agentOptions
, and userAgent
options are new, and resource loads can now be aborted.document.charset
, an alias for document.characterSet
.HTMLTemplateElement.prototype.content
, for getting the contents of a <template>
element as a document fragment. (rickychien)document.cookie = "foo"
.Event.prototype.stopImmediatePropagation
and the constants NONE
, CAPTURING_PHASE
, AT_TARGET
, and BUBBLING_PHASE
. This accounted for another 15 newly-passing web platform tests. (nicolashenry)document.styleSheets
to correctly track the removal of stylesheets from the document. (AVGP)created
jsdom lifecycle callback receiving a different window
object than the loaded
or done
callbacks when scripting was enabled.{ omitJsdomErrors }
option of the virtual console has moved; it is no longer provided when creating the virtual console, but instead when calling sendTo
.jsdom.jsdom
, you had to pass referrer
and cookie
options as top-level, whereas with jsdom.env
, you had to nest them under a document
option. This was unnecessarily confusing. Now both possibilities are allowed for both functions. (The readme only documents the top-level version, though.)NodeList.prototype[Symbol.iterator]
, so you can now use for
-of
loops with NodeList
s.jsdom.nodeLocation(node)
to get the location within the source text of a given node.jsdom.reconfigureWindow(window, { top })
to allow changing the value of a window's top
property.element
argument to the custom resource loader, so you can customize resource loads depending on which element loaded them.getElementsByClassName
to match the spec. It now correctly splits on whitespace to try to find elements with all the given classes; it returns a HTMLCollection
instead of a NodeList
; and it memoizes the result.NodeList
and HTMLCollection
to match the spec. The most noticable change is that HTMLCollection
no longer inherits from NodeList
.window.atob
and window.btoa
. (jeffcarp)<canvas>
implementation:canvas
npm package installed, <canvas>
elements are now properly instanceof HTMLCanvasElement
and instanceof HTMLElement
.<canvas>
elements now present the same uniform spec-compliant API both with and without the canvas
npm package installed. If the package is not installed, some of the methods will cause not-implemented "jsdomError"
events to be emitted on the virtual console.width
and height
properties now correctly reflect the width
and height
attributes, and have the appropriate default values of 300
and 150
.canvas
npm package installed, <canvas>
elements now generally play better with other parts of jsdom, e.g., document.getElementById
actually works with them.HTMLDataElement
, HTMLSpanElement
, and HTMLTimeElement
.HTMLDataListElement
, HTMLDialogElement
, HTMLEmbedElement
, HTMLMeterElement
, HTMLOutputElement
, HTMLProgressElement
, HTMLSourceElement
, HTMLTemplateElement
, and HTMLTrackElement
.HTMLAudioElement
was implemented in full, although its HTMLMediaElement
base, where most of its functionality is, is still largely a stub.HTMLTableSectionElement
, HTMLTableRowElement
, HTMLTableCellElement
, HTMLTableDataCellElement
, and HTMLTableHeaderCellElement
were updated to the latest spec.HTMLIsIndexElement
was removed; it has never been produced by the parser since 1.0.0-pre.1, and so it has been just a vestigial global property.HTMLMediaElement
.Node.prototype.baseURI
property to get the node's owner document's base URL.HTMLBaseElement
's href
getter now contains appropriate fallbacks and always returns an absolute URL, per spec.base
elements in an "about:blank"
iframe document, the base URL correctly falls back to the parent window's base URL.url: ...
option to jsdom.jsom()
or jsdom.env()
, the given string is now attempted to be resolved as a URL before it is installed as document.URL
.url: "http://example.com"
will mean document.URL
returns "http://example.com/"
, with a trailing slash.Element.prototype.classList
, closing out a three-year old issue! (wacii)virtualConsole.sendTo(console)
forward "jsdomError"
s to console
by calling console.error
. This can be turned off by doing virtualConsole.sendTo(console, { omitJsdomErrors: true })
.<!DOCTYPE>
."jsdomError"
s that were emitted after calling window.close()
."DOMSubtreeModified"
event to fire in more cases. Note that our mutation events implementation remains incomplete, and will eventually be removed (in a major release) once we implement mutation observers. (selam)HTMLMediaElement
and HTMLVideoElement
, back-ported from Facebook's Jest project. (cpojer)XMLHttpRequest.prototype.getAllResponseHeaders
to not crash when used with file:
URLs. (justinmchase)XMLHttpRequest.prototype.response
to correctly return the response text even when responseType
was unset. (justinmchase)This major release is focused on massive improvements in speed, URL parsing, and error handling. The potential breaking changes are highlighted in bold below; the largest ones are around the jsdom.env
error-handling paradigm.
This release also welcomes long-time contributer @Joris-van-der-Wel to the core team. You may recognize him from earlier changelogs. We're very happy to have his help in making jsdom awesome!
id
and name
attributes (including during parsing).node.compareDocumentPosition
and anything that used it (like node.contains
) by doing more intelligent tree traversal instead of directly implementing the specced algorithm.window.onerror
(or window.addEventListener("error", ...)
) now work, and will catch all script errors, similar to in browsers. This also introduces the ErrorEvent
class, incidentally."jsdomError"
. This includes: errors loading external resources; script execution errors unhandled by window.onerror
; and not-implemented warnings resulting from calling methods like window.alert
which jsdom explicitly does not support.window.onerror
and the virtual console, they are no longer included in the initialization process. This results in two changes to jsdom.env
and the initialization lifecycle:load(errors, window)
callback was changed to onload(window)
, to reflect that it is now just sugar for setting a window.onload
handler.done(errors, window)
callback (i.e., the default callback for jsdom.env
) has become done(error, window)
, and like every other io.js callback now simply gives you a single error object, instead of an array of them.errors
array, or a raise
method used to put things in that array.URL
class has been added to window
HTMLAnchorElement.prototype
and document.location
(as well as URL
, of course) are now uniformized to follow the URLUtils
API (minus searchParams
for now).file:
URLs to jsdom.env
where previously you were able to get away with passing in filenames.XMLHttpRequest.prototype.response
getter.StyleSheetList.prototype.item
to actually work. (chad3814)vm
shim to properly add the built-in global properties (Object
, Array
, etc.) to the sandbox. If you were running jsdom inside a web worker and most of your scripts were broken, this should fix that."hashchange"
event to correctly fire HashChangeEvent
instances, with correct properties newURL
and oldURL
(instead of the incorrect newUrl
and oldUrl
used previously).eval
and thus did not work in CSP scenarios.Finally, if you're a loyal jsdom fan whose made it this far into the changelog, I'd urge you to come join us in #1139, where we are brainstorming a modernized jsdom API that could get rid of many of the warts in the current one.
attribute
variable if you ever called createAttributeNS
.url("quoted string")
now works correctly, as of cssstyle
0.2.29.div[title=""]
, now work correctly, as of nwmatcher
1.3.6.virtualConsole.sendTo
now returns this
, allowing for a nice shorthand. (jeffcarp)postMessage
support, for communicating between parent windows, iframes, and combinations thereof. It's missing a few semantics, especially around origins, as well as MessageEvent source. Objects are not yet structured cloned, but instead passed by reference. But it's working, and awesome! (jeffcarp)cloneNode
and importNode
), fixing a number of issues:cloneNode
method for now due to legacy).type
property of <button>
elements to correctly default to submit
, and to stay within the allowed range.<button>
s to submit their containing form; previously only <input type="submit">
worked. (rxgx)document.open()
to return this
, per spec. (ryanseddon)Additionally, Joris-van-der-Wel added a benchmarking framework, and a number of benchmarks, which should help us avoid performance regressions going forward, and also make targeted performance fixes. We're already investigating some real-world issues using this framework. Very exciting!
el.style.cssText
to an invalid value, which should be ignored instead of causing an error to be thrown. This same bug has also caused an error while setting the style attribute to an invalid value, ever since 5.4.0. (Joris-van-der-Wel; chad3814 upstream)This is a pretty exciting release! It includes a couple features I never really anticipated jsdom being awesome enough to have, but our wonderful contributors powered through and made them happen anyway:
window.getComputedStyle
! (akhaku)show()
and hide()
methods now work correctly; see #994.window
: any elements with an id
attribute, or certain elements with a name
attribute, will cause properties to show up on the window
, and thus as global variables within the jsdom. (Joris-van-der-Wel)<iframe>
s, and our implementation was quite buggy: e.g., <iframe name="addEventListener">
would override window.addEventListener
.HTMLFormElement
s as well in the future.We also have a bunch more fixes and additions:
NonDocumentTypeChildNode
mixin. Practically, this means adding nextElementSibling
and previousElementSibling
to Element
and the various types of CharacterData
. (brandon-bethke-neudesic)StyleSheetList
to inherit from Array
, as per the latest CSSOM spec.NamedNodeMap
implementation is up to date, as are the various Element
methods; other places in the code that deal with attributes now all go through a spec-compliant set of helpers.style
attribute were fixed along the way; see e.g. #1109.Attr
objects themselves are not yet spec-compliant (e.g., they still inherit from Node
). That's coming soon.getElementById
would fail to work correctly on <img>
elements whose id
attributes were modified. (Joris-van-der-Wel)virtualConsole
option to work with jsdom.env
, not just jsdom.jsdom
. (jeffcarp)window
: mapper
, mapDOMNodes
, and visitTree
. (Joris-van-der-Wel)virtualConsole
option to the document creation methods, along with the jsdom.createVirtualConsole
factory. (See examples in the readme.) With this option you can install a virtual console before the document is even created, thus allowing you to catch any virtual console events that occur during initialization. (jeffcarp)ParentNode
mixin (Joris-van-der-Wel):children
from Node
to ParentNode
, i.e., made it available on Document
, DocumentFragment
, and Element
, but not other types of nodes.children
a HTMLCollection
instead of a NodeList
.firstElementChild
, lastElementChild
, and childElementCount
.outerHTML
setter. (Joris-van-der-Wel)outerHTML
getter for <select>
and <form>
. (Joris-van-der-Wel)document.implementation.createHTMLDocument()
. (Joris-van-der-Wel)@import
. (dbo)NodeIterator
class from the DOM Standard. (Joris-van-der-Wel)document.cookie
setter to no longer ignore null
; instead it correctly sets a cookie of "null"
. (Chrome is not compliant to the spec in this regard.)parsingMode: "xml"
to no longer get "<html><head></head><body></body></html>"
automatically inserted when calling jsdom.jsdom()
with no arguments.innerHTML
setter to no longer ignore undefined
; instead it correctly sets the innerHTML to "undefined"
.document.write
to throw for XML documents as per the spec.document.write
to accept more than one argument (they get concatenated).document.write("")
to no longer try to write "<html><head></head><body></body></html>"
.This release overhauls how cookies are handled in jsdom to be less fiddly and more like-a-browser. The work for this was done by @inikulin, who is also our beloved parse5 maintainer.
You should only need to worry about upgrading to this release if you use jsdom's cookie handling capabilities beyond the basics of reading and writing to document.cookie
. If that describes you, here's what changed:
options.jar
and options.document.cookieDomain
from the configuration for creating jsdom documents.options.cookieJar
, which accepts cookie jars created by the new jsdom.createCookieJar()
API. You should use this if you intend to share cookie jars among multiple jsdom documents.options.url
when creating a document). This supplants the former options.document.cookieDomain
.In addition to these changes to the public API, the following new cookie-related features came along for the ride:
<iframe>
s. (So, if the iframe is same-domain, it can automatically access the appropriate cookies.)options.document.cookie
accept arrays, instead of just strings, for if you want to set multiple cookies at once.Finally, it's worth noting that we now delegate our cookie handling in general to the tough-cookie package, which should hopefully mean that it now captures many of the behaviors that were previously missing (for example #1027). @inikulin is working on a large pull request to fix tough-cookie to be more spec compliant, which should automatically be picked up by jsdom installs once it is merged.
document.currentScript
. (jeffcarp)jsdom.env
, and not for sub-resources inside the resulting page. (ssesha)el.dispatchEvent(clickEvent)
, not just when doing el.click()
. (brandon-bethke-neudesic)defaultPrevented
property to Event
instances, reflecting whether ev.preventDefault()
has been called. (brandon-bethke-neudesic)click()
method from HTMLInputElement.prototype
to HTMLElement.prototype
, per the latest spec.click()
method trigger a MouseEvent
instead of just an Event
.UIEvent
, MouseEvent
, and MutationEvent
, which for now just behaves the same as that for Event
. (Rich-Harris)Event
constructor, which allows you to set the bubbles
and cancelable
properties. (brandon-bethke-neudesic)HTMLUnknownElement
and fix the parser/document.createElement
to create those instead of HTMLElement
for unknown elements.window
, as well as window.length
, with regard to <frame>
s/<iframe>
s being added and removed from the document.Note: this probably should have been a minor version number increment (i.e. 4.1.0 instead of 4.0.5), since it added HTMLUnknownElement
. We apologize for the deviation from semver.
EventTarget
s to execute their handlers in FIFO order, as per the spec.childNodes
would not be correctly up to date in some cases. (medikoo)jsdom.env
by ~600%, for the special case when no scripts are to be executed.EventTarget
is now correctly in the prototype chain of Window
.EventTarget
argument validation is now correct according to the DOM Standard.DOMException
now behaves more like it should per Web IDL. In particular it has a more comprehensive set of constants, and instances now have name
properties.new Event("click")
can now be dispatched. (lovebear)document.createEvent
now behaves more like it should according to the DOM Standard: it accepts a wider range of arguments, but will throw if an invalid one is given. (lovebear)Node.prototype.contains
to always return a boolean. This was a regression in 3.1.1. (Joris-van-der-Wel)Document.prototype
no longer contains its own ownerDocument
getter, instead correctly delegating to Node.prototype
.<script>
s in browserified jsdom.0
when setting numeric CSS properties and parsing of shorthand font
declarations.<form>
elements inside <template>
elements.This release relies on the newly-overhauled vm
module of io.js to eliminate the Contextify native module dependency. jsdom should now be much easier to use and install, without requiring a C++ compiler toolchain!
Note that as of this release, jsdom no longer works with Node.js™, and instead requires io.js. You are still welcome to install a release in the 3.x series if you are stuck on legacy technology like Node.js™.
In the process of rewriting parts of jsdom to use vm
, a number of related fixes were made regarding the Window
object:
Window
instances—especially parser- and serializer-related state. This is no longer the case, thankfully.Window
were updated for spec compliance: some data properties became accessors, and all methods moved from the prototype to the instance.document.parentWindow
was removed, in favor of the standard document.defaultView
. Our apologies for encouraging use of parentWindow
in our README, tests, and examples.NOT_IMPLEMENTED
internal helper, which should eliminate the cases where calling e.g. window.alert
crashes your application.NOT_IMPLEMENTED
methods, like window.location.reload
.about:blank
properly on all systems (previously it only worked on Windows). This is especially important since as of 3.0.0 the default URL is about:blank
.<script>
s inside a browserified jsdom instance. This is done by dynamically rewriting the source code so that global variable references become explicit references to window.variableName
, so it is not foolproof.Node.prototype.isEqualNode
to the algorithm of the DOM Standard, fixing a bug where it would throw an error along the way.Node.prototype.isSameNode
, which is not present in the DOM Standard (and was just a verbose ===
check anyway).jsdom.env
. However, while doing so discovered that <script>
s in general don't work too well in a browserified jsdom; see #1023.<template>
).jsdom.env
's autodetecting capabilities. (fluffybunnies)jsdom.env
's html
option. (fluffybunnies)This release updates large swathes of the DOM APIs to conform to the standard, mostly by removing old stuff. It also fixes a few bugs, introduces a couple new features, and changes some defaults.
3.0.x will be the last release of jsdom to support Node.js. All future releases (starting with 4.0.0) will require io.js, whose new vm
module will allow us to remove our contextify native-module dependency. (Given that I submitted the relevant patch to joyent/node 1.5 years ago, I'm very excited that we can finally use it!)
about:blank
as their URL, instead of trying to infer some type of file URL from the call site (in Node.js) or using location.href
(in browsers).console.error
will no longer contribute to the (non-standard, and likely dying in the future) window.errors
array. (jeffcarp)new Image(width, height)
constructor. (vinothkr)querySelector
with selectors like div:last-child > span[title]
.DOMImplementation
to mostly work per-spec, including removing addFeature
and removeFeature
methods, the ownerDocument
property, and making hasFeature
always return true
.CharacterData
implementation to follow the algorithms in the DOM Standard; this notably removes a few exceptions that were previously thrown.Comment
, Text
, and ProcessingInstruction
to follow the DOM Standard and derive from CharacterData
.DocumentType
to follow the DOM Standard and be much simpler, notably removing notations, entities, and default attributes.Node
, Element
, Attr
, and Document
; some were removed that were nonstandard (especially setters); others were updated to reflect the spec; etc.document.contentType
now is generally inferred from the parsing mode of the document.Document.prototype
and Window.prototype
instead of setting them as own properties during the document/window creation. This should improve memory usage (as well as spec compliance).This release is largely a refactoring release to remove the defunct concept of "levels" from jsdom, in favor of the living standard model that browsers follow. Although the code is still organized that way, that's now noted as a historical artifact. The public API changes while doing so were fairly minimal, but this sets the stage for a cleaner jsdom code structure going forward.
jsdom.level
, and the level
option from jsdom.jsdom
.Element.prototype.matchesSelector
method was replaced with the standard Element.prototype.matches
. (KenPowers)querySelector
correctly coerces its argument to a string (1.2.2 previously fixed this for querySelectorAll
).window.console
methods, viz. assert
, clear
, count
, debug
, group
, groupCollapse
, groupEnd
, table
, time
, timeEnd
, and trace
. All except assert
do nothing for now, but see #979 for future plans. (jeffcarp)childNodes
, and the many places in jsdom that use it, much faster. (Joris-van-der-Wel)NodeList.prototype.length
, which should speed up common operations like appendChild
and similar. (Joris-van-der-Wel)HTMLInputElement.prototype.checked
and defaultChecked
now behave per the spec. (Joris-van-der-Wel)HTMLOptionElement.prototype.selected
now behaves per the spec. (Joris-van-der-Wel)HTMLInputElement.prototype.value
now behaves per the spec. (Joris-van-der-Wel)HTMLTextAreaElement.prototype.value
and defaultValue
now behave per the spec. (Joris-van-der-Wel)HTMLTextAreaElement.prototype.defaultValue
now has a setter, and HTMLTextAreaElement.prototype.textLength
now exists. (Joris-van-der-Wel)<form>
now behaves per spec for all different types of form elements. (Joris-van-der-Wel)document.cloneNode
now works. (AVGP)hasAttribute
is now case-insensitive, as it should be. (AVGP)div.toString()
now returns [object HTMLDivElement]
. (AVGP)module.parent
exists before using it to construct a document's initial URL. Apparently some testing frameworks like Jest do not correctly emulate the module environment; this compensates. (SegFaultx64)<option>
elements will now have the correct consequences. For example changing the id
attribute now interacts correctly with document.getElementById
. (Joris-van-der-Wel)focus
and blur
methods to HTMLElement.prototype
, instead of having them only be present on certain element prototypes. Our focus story is still not very spec-compliant, but this is a step in the right direction. (vincentsiao)Node.prototype.insertBefore
, Node.prototype.removeChild
, and several AttributeList
methods. (Joris-van-der-Wel)querySelectorAll
correctly coerces its argument to a string; notably this allows you to pass arrays. (jeffcarp)data
setter on text nodes correctly coerces the new value to a string. (medikoo)document.toString()
now returns [object HTMLDocument]
. (jeffcarp)<template>
element parsing and serialization, now that it is supported by parse5. (inikulin)NodeFilter
, in particular its constants. (fhemberger)history.length
should be 1
, not 0
. (rgrove)history.pushState
and history.replaceState
should not fire the popstate
event. (rgrove)document.implementation.createHTMLDocument()
. (fhemberger)localName
was sometimes null
for elements when it should not be. (fhemberger)cssstyle
and cssstyle-browserify
dependencies; now cssstyle
can be used directly. This also un-pins the cssstyle
dependency so that future fixes arrive as they appear upstream.cssstyle
dependency to at most 0.2.18 until chad3814/CSSStyleDeclaration#20 is fixed.dependencies
instead of devDependencies
. (Sebmaster)jsom.env
in a browser environment now correctly defaults options.url
to location.href
instead of trying to infer a reasonable fil://
URL using techniques that fail in the browser. (rattrayalex)EventTarget.prototype.dispatchEvent
should be true
when the default is not prevented; previously it was the opposite. (eventualbuddha)For a consolidated list of changes from 0.11.1 to 1.0.0, see this wiki page.
EventTarget.getListeners
; EventTarget.forwardIterator
; EventTarget.backwardIterator
; EventTarget.singleIterator
.document.innerHTML
. (jorendorff)value
and defaultValue
properties of a HTMLInputElement
are now correctly synced to the value=""
attribute. (Sebmaster)document.write
) and parsing disconnected fragments (for document.innerHTML
). (Sebmaster)parsingMode
configuration, to allow you to manually specify XML or HTML. (Sebmaster)<?xml
or similar to attempt to auto-detect XHTML documents. Instead, it will by default treat them the same as browsers do, with the <?xml
declaration just being a bogus comment. If you need your document interpreted as XHTML instead of HTML, use the parsingMode
option. (Sebmaster)getElementsByTagName
, querySelector
, etc.) to improve performance. (ccarpita)innerHTML
, this time related to disconnected nodes. This was a regression between 0.11.1 and 1.0.0-pre.1. (paton)window.close()
would cause a segfault. (paton)prefix
, localName
, and namespaceURI
properties set correctly in all cases. (Excepting application/xhtml+xml
mode, which jsdom does not support yet.) (Sebmaster)innerHTML
. This was a regression between 0.11.1 and 1.0.0-pre.1. (Sebmaster)x:y
, e.g. xmlns:xlink
or xlink:href
. This was a regression between 0.11.1 and 1.0.0-pre.1. (Sebmaster)This is a prerelease of jsdom's first major version. It incorporates several great additions, as well as a general cleanup of the API surface, which make it more backward-incompatible than usual. Starting with the 1.0.0 release, we will be following semantic versioning, so that you can depend on stability within major version ranges. But we still have a few more issues before we can get there, so I don't want to do 1.0.0 quite yet.
This release owes a special thanks to @Sebmaster, for his amazing work taking on some of the hardest problems in jsdom and solving them with gusto.
<html>
, <head>
, or <body>
in their source. We also use parse5 for serialization, fixing many bugs there. (Sebmaster)jsdom.createWindow
: use document.parentWindow
after creating a documentjsdom.html
: use jsdom.jsdom
jsdom.version
: use require("jsdom/package.json").version
jsdom.level
: levels are deprecated and will probably be removed in 2.0.0jsdom.dom
jsdom.browserAugmentation
jsdom.windowAugmentation
jsdom.jsdom
no longer takes a level as its second argument.jsdom.jQueryify
now requires a jQuery URL, since always picking the latest was a bad idea.document.createWindow
: use document.parentWindow
document.innerHTML
and document.outerHTML
: use the new jsdom.serializeDocument
to include the DOCTYPE, or use document.documentElement.outerHTML
to omit it.jsdom.env
. (michaelmior)EventTarget.prototype.dispatchEvent
. (Joris-van-der-Wel)eventPhase
and currentTarget
on events, before and after a dispatch. (Joris-van-der-Wel)document.cookie = null
to not throw, but instead just do nothing. (kapouer)Node.prototype.parentElement
. (lukasbuenger)''
when not present, instead of null
. (Note that getAttribute
still returns null
for them). (thejameskyle)textContent
now works for nodes that do not have children, like text nodes for example. (hayes)jsdom.jQueryify
was using the wrong URL for jQuery by default. (lukasbuenger)living
, reflecting our focus on the DOM Living Standard and the HTML Living Standard, which are what browsers actually implement. This should open the door for more features of the modern DOM and HTML specs to be implemented in jsdom. (robotlovesyou)Node.prototype.contains
now implemented. (robotlovesyou)navigator.cookieEnabled
now implemented; it always returns true
. (Sebmaster)name
property uppercased during parsing, and appear in the output of document.innerHTML
.Node.prototype.compareDocumentPosition
implemented correctly; various document position constants added to the Node
constructor. (robotlovesyou)DocumentType.prototype.parentNode
now returns the document node, not null
. (robotlovesyou)navigator
properties are now getters, not data properties. (Sebmaster)jsdom.jQueryify
. (Sebmaster)window.location
and HTMLAnchorElement
.String.prototype.normalize
, which is available by default in Node 0.11.13 onwards, caused reflected attributes to break. (brock8503)about:blank
when the src
attribute is empty or missing. (mcmathja)/
: i.e. the result is now <br>
instead of <br />
.show()
method would cause errors.querySelector
and querySelectorAll
methods to DocumentFragment
s. (Joris-van-der-Wel)HTMLAnchorElement
and window.location
should not be null
; they should usually be the empty string.show()
method would cause an error to be thrown.window.location
properties were not updating correctly after using pushState
or replaceState
. (toomanydaves)window.location.port
should default to ""
, not null
. (bpeacock)document.cookie
implementation, that supports multiple cookies. Note that options like path
, max-age
, etc. are still ignored. (dai-shi)port
and protocol
to HTMLAnchorElement
. (sporchia)HTMLInputElement
not have a type
attribute by default. It still has a default value for the type
property, viz. "text"
. (aredridel)getAttributeNS
, hasAttributeNS
, and setAttributeNS
functions. (lddubeau)NamedNodeMap
no longer break jsdom. (papandreou)removeAttributeNS
should not throw on missing attributes. (lddubeau)__proto__
, __defineGetter__
, and __defineSetter__
usage, as part of a project to make jsdom work better across multiple environments. (lawnsea)hash
property to HTMLAnchorElement
. (fr0z3nk0)cssom
to 0.3.0, adding support for @-moz-document
and fixing a few other issues.cssstyle
to 0.2.6, adding support for many shorthand properties and better unit handling.NodeList.prototype.length
calculation, for a speed improvement. (peller)host
property to HTMLAnchorElement
. (sporchia)Error.prototype
. (mitar)getBoundingClientRect
method, that returns 0
for all properties of the rectangle, is now implemented. (F1LT3R)href
property on CSSStyleSheet
instances for external CSS files. (FrozenCow)window
. (nlacasse)querySelector
and querySelectorAll
should be on the prototypes of Element
and Document
, not own-properties. (mbostock)jsdom.env
is a HTML string or a filename, deal with long strings correctly instead of erroring. (baryshev)window.history
support, including back
, forward
, go
, pushState
, and replaceState
. (ralphholzmann)<?xml?>
declaration starts the document, will try to parse as XML, e.g. not lowercasing the tags. (robdodson)createElement
are coerced to strings before evaluating.window.location.replace
was broken. (dai-shi)XMLHttpRequest
support, including cookie passing! (dai-shi)window.navigator.noUI
property that evaluates to true, if you want to specifically distinguish jsdom in your tests.jsdom.env
a string is more accurate, and you can be explicit by using the html
, url
, or file
properties. This is a breaking change in the behavior of html
, which used to do the same auto-detection logic as the string-only version.jsdom.env
's callback. (airportyh)window.location.href
correctly when using jsdom.env
to construct a window from a URL, when that URL causes a redirect. (fegs)window.location
object, which includes firing hashchange
events when the hash is changed. (dai-shi)Object.prototype
, e.g. "constructor"
, would confuse jsdom massively.<img>
elements now fire "load"
events when their src
attributes are changed. (kapouer)jsdom.env
. (jden)<base>
tags that were set, and any relative href
s. This impacts many parts of jsdom having to do with external resources or accurate href
and src
attributes. (deitch)package.json
field "repository"
instead of "repositories"
to prevent npm warnings. (jonathanong)Integrated a new HTML parser, htmlparser2, from fb55. This is an actively maintained and much less buggy parser, fixing many of our parsing issues, including:
<p>
or <td>
.innerHTML
of <script>
tags no longer cuts off the first character.""
as their value instead of the attribute name.^
.>
and <
.on<event>
more spec-compatible, supporting return false
and passing the event
argument. (adrianlang)textContent
more accurate, e.g. in cases involving comment nodes or processing instruction nodes. (adrianlang)<canvas>
behave like a <div>
when the node-canvas
package isn't available, instead of crashing. (stepheneb)on<event>
properties are correctly updated when using setAttributeNode
, attributeNode.value =
, removeAttribute
, and removeAttributeNode
; before it only worked with setAttribute
. (adrianlang)HTMLCollection
s now have named properties based on their members' id
and name
attributes, e.g. form.elements.inputId
is now present. (adrianlang)readOnly
and selected
properties were not correct when their attribute values were falsy, e.g. <option selected="">
. (adrianlang)This release, and all future releases, require at least Node.js 0.8.
jsdom.env
configuration. (xavi-)rowIndex
for table rows that are not part of a table would throw. (medikoo)<img>
elements' src
properties now evaluate relative to location.href
, just like <a>
elements' href
properties. (brianmaissy)This release is compatible with Node.js 0.6, whereas all future releases will require at least Node.js 0.8.
getAttributeNS
now returns null
for attributes that are not present, just like getAttribute
. (mbostock)"request"
dependency pinned to version 2.14 for Node.js 0.6 compatibility.@-webkit-keyframes
rules were crashing calls to getComputedStyle
.features
option to jsdom.env
.style
attribute until the element's style
property is touched. (papandreou)selectedIndex
now changes correctly in response to <option>
elements being selected. This makes <select>
elements actually work like you would want, especially with jQuery. (xcoderzach)checked
works correctly on radio buttons, i.e. only one can be checked and clicking on one does not uncheck it. Previously they worked just like checkboxes. (xcoderzach)click()
on <input>
elements now fires a click event. (xcoderzach)contextify
a non-optional dependency. jsdom never worked without it, really, so this just caused confusion.selected
now returns true for the first <option>
in a <select>
if nothing is explicitly set.querySelectorAll
implementation.<a>
tags with no href
attribute. (eleith)getAttribute
now returns null
for attributes that are not present, as per DOM4 (but in contradiction to DOM1 through DOM3).NodeList
-returning methods (such as querySelectorAll
) now return a real NodeList
instance.NodeList
s no longer expose nonstandard properties to the world, like toArray
, without first prefixing them with an underscore.NodeList
s no longer inconsistently have array methods. Previously, live node lists would have indexOf
, while static node lists would have them all. Now, they have no array methods at all, as is correct per the specification.@media
rules were crashing calls to getComputedStyle
, e.g. those in jQuery's initialization.document.write
calls insert new elements correctly. (johanoverip, kblomquist).<input>
tags with no type
attribute now return a default value of "text"
when calling inputEl.getAttribute("type")
.getComputedStyle
. (chad3814, godmar)querySelector
implementation, courtesy of the nwmatcher project, solves many outstanding querySelector
bugs.matchesSelector
, again via nwmatcher.<style>
and <link rel="stylesheet">
elements being applied to the results of window.getComputedStyle
. (chad3814)focus()
and blur()
methods on appropriate elements. More work remains.jsdom.env
. (TomNomNom)toString
, hasOwnProperty
, etc. could cause lots of problems.load
event always fires asynchronously now, even if no external resources are necessary.href
-less <base>
tags.attr
in the global scope when using node-canvas. (starsquare)SkipExternalResources
feature accepts a regular expression. (fgalassi)cssText
and style
properties again.cssText
and style
properties are no longer as accurate.""
.CSSStyleDeclaration
, giving much more accurate cssText
and style
properties on all elements. (chad3814)checked
property on checkboxes and radiobuttons now reflects the attribute correctly.HTMLOptionElement
's text
property should return the option's text, not its value.name
property only exist on certain specific tags, and accurately reflect the corresponding name
attribute.outerHTML
(especially important for <pre>
elements).value
property from Text
instances (e.g. text nodes).String.prototype.normalize
method, like that of sugar.js.npm test
.<script>
or <style>
tag. (Andreas Lind Petersen)jsdom.level(x, 'feature')
toArray
and item
on NodeList
objects non-enumerable propertieswindow.close
in the readme:not()
throws a ReferenceError
(Felix Gnass)ProcessExternalResources['script']
is disabled, do not run inline event handlers. #355scripts
and src
properties (cjroebuck).env
callback (Gregory Tomlinson)<div onclick='some.horrible.string()'>
) (Brian McDaniel)<!DOCTYPE>
. Closes #259.document.parentWindow === window
work<
, >
, &
, and '
. Closes #147 and #177.option
element. - YonathanAdd the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.