getComputedStyle()
, unless you pass a ::part
or ::slotted
pseudo-element, in which case we throw an error per the spec. (ExE-Boss)el.tagName
, which also indirectly improves performance of selector matching and style computation. (eps1lon)form.elements
to respect the form=""
attribute, so that it can contain non-descendant form controls. (ccwebdesign)el.focus()
to do nothing on disconnected elements. (eps1lon)el.focus()
to work on SVG elements. (zjffun)<body>
element. (eps1lon)imgEl.complete
to return true for <img>
elements with empty or unset src=""
attributes. (strager)imgEl.complete
to return true if an error occurs loading the <img>
, when canvas is enabled. (strager)imgEl.complete
to return false if the <img>
element's src=""
attribute is reset. (strager)valueMissing
validation check for <input type="radio">
. (zjffun)translate=""
and draggable=""
attribute processing to use ASCII case-insensitivity, instead of Unicode case-insensitivity. (zjffun)focusin
and focusout
when using el.focus()
and el.blur()
. (trueadm)contenteditable=""
attribute to be considered as focusable. (jamieliu386)window.NodeFilter
to be per-Window
, instead of shared across all Window
s. (ExE-Boss)handleEvent
properties as event listeners. (ExE-Boss)load
event instead of an error
event, when the canvas
package is installed. (strager)StyleSheetList
for better spec compliance; notably it no longer inherits from Array.prototype
. (ExE-Boss)requestAnimationFrame()
from preventing process exit. This likely regressed in v16.1.0.setTimeout()
to no longer leak the closures passed in to it. This likely regressed in v16.1.0. (AviVahl)click()
on a <label>
element, or one of its descendants.getComputedStyle()
to consider inline style=""
attributes. (eps1lon)<input type="number">
's stepUp()
and stepDown()
functions to be properly decimal-based, instead of floating point-based.selectEl.value
would not invalidate properties such as selectEl.selectedOptions
. (ExE-Boss)<input>
's src
property, and <ins>
/<del>
's cite
property, to properly reflect as URLs.window.addEventLister
, window.removeEventListener
, and window.dispatchEvent
to properly be inherited from EventTarget
, instead of being distinct functions. (ExE-Boss)addEventListener
.data:
URLs.<input type="month">
that could occur in some time zones and for some times.document.implementation.createDocument()
to return an XMLDocument
, instead of a Document
. (ExE-Boss)saxes
, to bring in some BOM-related fixes.npm audit
warnings.Attr
as a Node
, e.g. by checking its baseURI
property or calling attr.cloneNode()
.console.timeLog()
.Attr
to extend Node
, to align with specifications. (ExE-Boss)<noscript>
children to be parsed as nodes, instead of as text, when runScripts
is left as the default of undefined
. (ACHP)cssstyle
to v2.1.0, which brings along fixes to handling of rgba()
and hsl()
colors. (kraynel)<input>
s and <textarea>
s. (Matthew-Goldberg)setTimeout()
, setInterval()
, and requestAnimationFrame()
, particularly around window closing and recursive calls.runScripts
was set.<input>
's type=""
attribute.<input type="range">
when max=""
is less than min=""
.For this release we'd like to welcome @pmdartus to the core team. Among other work, he's driven the heroic effort of constructor prototype and reform in jsdom and its dependencies over the last few months, to allow us to move away from shared constructors and prototypes, and set the groundwork for custom elements support (coming soon!).
Breaking changes:
dom.runVMScript()
API has been replaced with the more general dom.getInternalVMContext()
API.Window
now creates new instances of all the web platform globals. That is, our old shared constructor and prototypes caveat is no longer in play.Window
now exposes all JavaScript-spec-defined globals uniformly. When runScripts
is disabled, it exposes them as aliases of the ones from the outer Node.js environment. Whereas when runScripts
is enabled, it exposes fresh copies of each global from the new scripting environment. (Previously, a few typed array classes would always be aliased, and with runScripts
disabled, the other classes would not be exposed at all.)Other changes:
AbstractRange
, Range
, StaticRange
, Selection
, and window.getSelection()
APIs.Comment
, Text
, and DocumentFragment
.valueAsDate
, valueAsNumber
, stepUp()
and stepDown()
to <input>
elements. (kraynel)window.origin
.document.origin
.<template>
to work correctly inside XML documents.<meta charset>
or <meta http-equiv="charset">
elements.input.type
to default to "text"
. (connormeredith)<input>
with fractional values for their step=""
attribute. (kontomondo)<input>
elements.<input type="email" multiple pattern="...">
validation.fileReader.readAsDataURL()
to always base64-encode the result. (ytetsuro)<img>
elements into documents without a browsing context to no longer crash when the canvas
package is installed.window.setTimeout()
or window.setInterval()
.getComputedStyle()
. (eps1lon)JSDOM.fromURL()
handling of URLs with hashes in them, to no longer send the hash to the server and append an extra copy of it when constructing the Document
. (rchl)focus
events. (eps1lon)mediaElement.addTextTrack()
. (mtsmfm)nwsapi
minimum version to 2.2.0, which fixes issues with ::-webkit-
prefixed pseudo-elements and namespaced attribute selectors.getComputedStyle()
for the 'visibility'
property. This sets the foundation for further work on inheritance, cascading, and specificity. (eps1lon)shadowRoot.activeElement
.readystatechange
events during document loading.form.requestSubmit()
, to match our existing stub for form.submit()
.el.tabIndex
's default value, when no tabindex=""
attribute was set, to reflect the updated specification.el.attachShadow()
on something that's already a shadow host, to reflect the updated specification.<input type="range">
.selectEl.value
when no <option>
is selected to return the empty string, instead of the value of the first option. (tgohn)new FormData(formElement)
. (brendo)"undefined"
. (papandreou)el.getAttributeNS()
or el.setAttributeNS()
.canvas
as an optional ``peerDependency`, which apparently helps with Yarn PnP support.nonce
property from HTMLScriptElement
and HTMLStyleElement
to HTMLElement
. Note that it is still just a simple reflection of the attribute, and has not been updated for the rest of the changes in whatwg/html#2373.style
and on<event>
properties to properly track their related attributes for SVG elements. (kbruneel)XMLHttpRequest
merging preflight and response headers. (thiagohirata)XMLHttpRequest
reserializing content-type
request headers unnecessarily. See whatwg/mimesniff#84 for more details. (thiagohirata)element.tagName
to be the ASCII uppercase of the element's qualified name, instead of the Unicode uppercase.Headers
class from the Fetch standard.element.translate
getter and setter.XMLHttpRequest
on the newly-released Node.js v12.form.elements
to exclude <input type="image">
elements.pattern=""
form control validation to apply the given regular expression to the whole string. (kontomondo)Several potentially-breaking changes, each of them fairly unlikely to actually break anything:
JSDOM.fromFile()
now treats .xht
files as application/xhtml+xml
, the same as it does for .xhtml
and .xml
. Previously, it would treat them as text/html
.JSDOM
constructor's contentType
option has a charset
parameter, and the first argument to the constructor is a binary data type (e.g. Buffer
or ArrayBuffer
), then the charset
will override any sniffed encoding in the same way as a Content-Type
header would in browser scenarios. Previously, the charset
parameter was ignored.Blob
or File
constructor with the endings: "native"
option, jsdom will now convert line endings to \n
on all operating systems, for consistency. Previously, on Windows, it would convert line endings to \r\n
.<a>
and <area>
elements whose href=""
points to a javascript:
URL or fragment.<datalist>
element's options
property.<input>
element's list
property.PageTransitionEvent
, and the firing of pageshow
events during loading.External
class as a property of window
.innerHTML
and outerHTML
) to be spec-compliant. (pmdartus)innerHTML
) breaking after setting certain properties to non-string values.<style>
s to no longer apply to documents without a browsing context. This includes fixing a crash that would occur with such styles if they had an @import
rule.<option>
's label
and value
properties to return correct values in various edge cases.load
event during document loading to target the Document
, not the Window
.pretendToBeVisual
option to propagate to child subframes, as well as the main Window
. (pyrho)nwsapi
version from v2.1.1 to v2.1.3, bringing along a few fixes in our selector engine.Breaking changes:
JSDOM.fragment()
now creates fragments whose document has no browsing context, i.e. no associated Window
. This means the defaultView
property will be null, resources will not load, etc.JSDOM.fragment()
, called with no arguments, now creates a DocumentFragment
with no children, instead of with a single child text node whose data was "undefined"
.Other changes:
element.blur()
on a focused element.<link>
elements into documents with no browsing context to no longer crash if the originating JSDOM
was configured to fetch the resource. Now, per spec, <link>
elements only attempt to fetch if they are browsing-context connected.<template>
elements to have the correct semantics, of using a separate browsing-context-less document to store its contents. In particular this means resources will not be fetched for elements inside the <template>
, as per spec.MutationObserver
s! (pmdartus)<progress>
element's value
, max
, and position
properties.navigator.plugins
and navigator.mimeTypes
. (But, they are always empty.)<summary>
elements respond to click
events by toggling their parent <details>
.<summary>
elements to be focusable.isTrusted
set to true
.DOMParser
-created documents to have their readyState
set to "complete"
.<fieldset>
s get disabled.getComputedStyle()
to throw a sensible exception when passed the wrong argument, instead of one that exposes jsdom internals.saxes
dependency, so that it now correctly errors on XML fragments like <foo bar:="1"/>
.el.insertAdjacentElement()
and el.insertAdjacentText()
.reset
event to form.reset()
. (epfremmer)type
, value
, and defaultValue
properties to <output>
elements, including their form reset behavior. (epfremmer)outputEl.htmlFor
property.<style>
or <script>
elements. This regressed in v11.6.0. To learn more, see V8 issue #6730.style
property on <a>
and <area>
elements. This regressed in v13.0.0.node.isConnected
to not always return false for nodes inside a shadow tree. (pmdartus)<button type="reset">
and <input type="reset">
elements to actually perform a form reset when clicked, instead of doing nothing. (epfremmer)el.setCustomValidity()
for <output>
and <fieldset>
.click
events, so that for example calling el.click()
on the child of a submit button element will submit the form.focus
/blur
events to be composed.mediaElement.duration
to default to NaN
.olEl.start
to default to 1
.XMLHttpRequest
against non-existant file:
URLs to treat that as a network error, instead of crashing. (pascalbayer) Note that in the future we may completely disable XMLHttpRequest
usage against file:
URLs to follow the browser security model.document.title
in SVG documents.titleElement.text
to return the child text content, instead of being the same as titleElement.innerHTML
.<textarea>
s to properly account for child CDATA section nodes changing.Element.prototype[Symbol.unscopables]
.Breaking change:
canvas
package, in favor of v2.x. This also removes support for canvas-prebuilt
, since canvas
v2.x has a built-in prebuilt version.Other changes:
w3c-xmlserializer
package. Previously we were just using the HTML serialization, even in XML documents.storageEvent.initStorageEvent()
method.passive
option to addEventListener()
.relList
property to <a>
, <area>
, and <link>
elements.element.toggleAttribute()
method.XMLHttpRequest
sometimes sending an empty request body after a preflight request. (andreasf)formElement.form
property to use an algorithm that also checks the form=""
attribute, instead of always looking for the closest ancestor <form>
element. (jamietre)canvas
or canvas-prebuilt
packages were installed, but failed to load. (joscha)sax
package to the well-maintained saxes
replacement. This increases our specification conformance, including rejecting certain ill-formed XML documents that were previously accepted, and properly handling other constructs like empty comments, CDATA sections, and <script>
elements. (lddubeau)fieldsetEl.elements
and fieldsetEl.type
properties.options
parameter to dom.runVMScript()
. (SimenB)fetch()
implementations to see what element initiated the fetch. (sarvaje)input
and change
events for <input>
elements to be trusted and uncancelable.<script>
s with the async
attribute to not execute before sync <script>
s that precede them. We still do not, in general, have proper execution of scripts during the initial parsing of a document, so this fix is more of a reduction of badness than an alignment with the specification. This behavior regressed in v12.0.0. (sarvaje)This major release brings along our new resource loader API, finally bringing all the capabilities from jsdom v9 to the new (jsdom v10+) API. Thanks very much to @sarvaje for his work to make this possible!
Breaking changes:
parse5
dependency to v5, which changes the format of the node locations returned by dom.nodeLocation()
.whatwg-url
dependency to v7, which changes the origin of file:
URLs to be an opaque origin (and thus file:
URLs are no longer same origin to each other).Other changes:
countReset()
, dir()
and dirxml()
methods to console
.InputEvent
class.window.status
.htmlElement.draggable
.window.frameElement
to correctly return an actual HTMLElement
instance, instead of a jsdom internal class.textarea
elements to preserve their values.select.selectedOptions
sometimes returning outdated results.:checked
.window.name
to default to the empty string, per spec, instead of "nodejs"
.window.localStorage
, window.sessionStorage
, and StorageEvent
support. These are currently only stored in-memory; file an issue if you need persistent (on-disk) storage capability so we can discuss adding that. This feature includes the new storageQuota
option for controlling how much can be stored.element.closest()
. (caub)hashchange
and popstate
events to no longer bubble, per a specification update.cssstyle
to v1.0.0, bringing along various fixes to our CSS parser and object model. (eddies)nwsapi
to v2.0.7, bringing along various fixes to our selector engine.node.getRootNode()
. (FrecksterGIT)label.control
. (FrecksterGIT)el.labels
for form control elements. (FrecksterGIT)contentType
of Document
s created through <iframe>
s.contentType
and origin
of Document
s created through document.implementation.createDocument()
.sourceEl.srcset
to return the value of the srcset=""
attribute, instead of the cite=""
attribute.node.normalize()
to not modify non-Text
nodes. (lddubeau)cssstyle
to v0.3.1, bringing along various fixes to our CSS parser and object model. (jsakas)whatwg-url
to v6.4.1, fixing the interaction of URL
's href
and searchParams
properties.nwsmatcher
to nwsapi
, bringing along extensive fixes, performance improvements, and additional selector support.event.srcElement
and event.returnValue
.XMLHttpRequest
to correctly set the User-Agent header, and set it on CORS preflight requests. (BehindTheMath)node.lookupPrefix()
, node.lookupNamespaceURI()
and node.isDefaultNamespace()
.Document
s; previously it would not clone all of the appropriate state, and would sometimes add an extra document type node.textContent
and nodeValue
properties.canvas.toBlob()
to properly pass through the JPEG quality argument, instead of always passing zero to node-canvas
. (challakoushik)willValidate
, validity
, validationMessage
, checkValidity()
, reportValidity()
, and setCustomValidity()
, on HTMLButtonElement
, HTMLFieldSetElement
, HTMLFormElement
, HTMLInputElement
, HTMLObjectElement
, HTMLOutputElement
, HTMLSelectElement
, and HTMLTextAreaElement
. (kontomondo)getElementById()
to DocumentFragment
.DOMTokenList
's replace()
method, per the recent spec addition.FileReader
's readAsBinaryString()
method, as it has been added back to the specification.Window
, instead of on Window.prototype
. (Fetz)<img>
element's src=""
attribute. (atsikov)abort
events on AbortSignal
s to have their isTrusted
set to true.XMLHttpRequest
's open()
method.data:
URL parsing throughout jsdom, by using the new whatwg-mimetype
and data-urls
packages..webidl
files that were included in the npm package.<style>
elements, where they would omit a series of parsing jsdomError
events for any style sheet text containing spaces.<style>
and <script>
elements are evaluated; for example, <script>
elements inserted by innerHTML
are no longer evaluated.<style>
elements, where their sheet
property would sometimes be null
when it should not be.<style>
element's sheet
property would be left as a CSSStyleSheet
despite it not being in the document.Another regression remains where we are emitting spurious CSS-parsing jsdomError
events; see #2123. We also discovered a large amount of preexisting brokenness around <style>
, <link>
, and @import
; see #2124 for more details.
We'll try to fix these soon, especially the regression.
WebSocket
implementation!window.performance
implementation, including the basics of the High Resolution Time specification: performance.now()
, performance.timeOrigin
, and performance.toJSON()
.HTMLMeterElement
, except for meterEl.labels
.locationbar
, menubar
, personalbar
, scrollbars
, statusbar
, and toolbar
properties to Window
.window.screen
: availWidth
, availHeight
, colorDepth
, and pixelDepth
. All of its properties are now getters as well.window.devicePixelRatio
.getModifierState()
to MouseEvent
and KeyboardEvent
.HTMLInputElement
's files
property.endings
option to the Blob
constructor.MouseEvent
when using element.click()
.popstate
and hashchange
events during fragment navigation to make them trusted events.data:
URL parsing to not include the fragment portions.new Document()
to be UTF-8.probablySupportsContext()
and setContext()
from HTMLCanvasElement
, per spec updates.window.scrollLeft
and window.scrollTop
properties, and the window.createPopup()
method.(This should have been a minor release; oops.)
AbortSignal
and AbortController
.<input>
s and implemented validation for more input types.For this release we'd like to welcome @Zirro to the core team; his contributions over the course of this year have enhanced jsdom immensely.
SVGElement
, SVGGraphicsElement
, SVGSVGElement
, SVGTests
, SVGAnimatedString
, SVGNumber
, and SVGStringList
. The main impact here is that SVG elements are now instances of SVGElement
, instead of being simply Element
(as they were in v11.3.0) or HTMLUnknownElement
(as they were in v11.2.0 and previously). The only concrete subclass that is implemented is SVGSVGElement
, for <svg>
itself; other tags will not map to their correct classes, because those classes are not yet implemented.pretendToBeVisual
option, which controls the presence of the new requestAnimationFrame()
and cancelAnimationFrame()
methods, and the new values of document.hidden
/document.visibilityState
. See the README for more information. (SimenB)append()
and prepend()
methods to Document
, DocumentFragment
, and Element
. (caub)before()
, after()
, and replaceWith()
methods to DocumentType
, Element
, and CharacterData
. (caub)node.isConnected
.node.isSameNode()
.domParser.parseFromString()
. (myabc)input.value
getter/setter logic for <input type="file">
.NamedNodeMap
, i.e. of element.attributes
, such that retrieving named or indexed properties will now always work properly.domParser.parseFromString()
to not parse HTML character entities in XML documents. (myabc)xhr.abort()
to clear any set headers.XMLHttpRequest
to always decoded responses as UTF-8 when responseType
is set to "json"
.XMLHttpRequest
CORS header handling, especially with regard to preflights and Access-Control-Allow-Headers. (ScottAlbertine)radioButton.click()
to fire appropriate input
and change
events. (liqwid)querySelector()
/querySelectorAll()
behavior for SVG elements inside <template>
contents DocumentFragment
s, including those created by JSDOM.fragment()
. (caub)<script>
elements, when includeNodeLocations
is set.<applet>
element, following the spec.For this release we'd like to formally welcome @TimothyGu to the core team, as a prolific contributor. He will join the illustrious ranks of those who do so much work on jsdom that we no longer note their names in the changelog.
table.tHead
, table.tFoot
, and table.caption
setters, and the table.createTBody()
method.CompositionEvent
and WheelEvent
classes.<details>
element implementation. (Zirro)<marquee>
and <picture>
element implementations. (Zirro)uiEvent.initUIEvent()
, keyboardEvent.initKeyboardEvent()
, and mouseEvent.initiMouseEvent()
to match the latest specifications.DOMTokenList
(used by, e.g., element.classList
) to use proxies for improved specification compliance and "liveness".DOMException
class to be spec-compliant, including its constructor signature.table.rows
getter, and the table.createCaption()
and table.deleteRow()
methods.document.querySelector === documentFragment.querySelector
, incorrectly).FocusEvent
creation, which regressed in v11.2.0.UIEvent
to only allow initializing with Window
objects for its view
property.tr.rowIndex
and tr.deleteCall()
.<td>
and <th>
to be simply HTMLTableCellElement
, and improved that class's spec compliance.label.click()
to not trigger the labeled control's activation behavior when the control is disabled. (schreifels)document.getElementsByName()
to return a NodeList
instead of a HTMLCollection
. (Zirro)XMLHttpRequest
. (Zirro)This release brings with it a much-awaited infrastructure change, as part of webidl2js v7.3.0 by the ever-amazing TimothyGu: jsdom can now generate spec-compliant versions of classes that have "Proxy
-like" behavior, i.e. allow getting or setting keys in unusual ways. This enables a number of improvements, also by TimothyGu:
NodeList
and HTMLCollection
, such that retrieving properties via indices or (in HTMLCollection
's case) id
/name
values will always work correctly.element.dataset
support.<select>
elements, as well as the corresponding item()
and namedItem()
methods.FileList
indexed properties, i.e. fileList[i]
.select.options
an instance of the newly-implemented HTMLOptionsCollection
, instead of just a HTMLCollection
.This infrastructure will allow us to improve and implement many other similar behaviors; that work is being tracked in #1129.
In addition to these improvements to the object model, we have more work to share:
document.clear()
, document.captureEvents()
, document.releaseEvents()
, window.external.AddSearchProvider()
, and window.external.IsSearchProviderInstalled()
. (Zirro)TreeWalker
and NodeIterator
.<textarea>
's value
, defaultValue
, and textContent
per a recent spec changeid="undefined"
shadowing the undefined
property of the global object. (TimothyGu)getElementsByClassName()
to be ASCII case-insensitive, instead of using JavaScript's toLowerCase()
.XMLHttpRequest
and FileReader
behavior, mainly around event handlers, abort()
, and network errors.NodeIterator
.javascript:
URL "navigation" via window.location
, at least by evaluating the side effects. It still doesn't actually navigate anywhere. (ForbesLindesay)whatwg-url
to v6.1.0, bringing along origin serialization changes and URLSearchParams
among various other fixes. (ForbesLindesay)javascript:
URL loading for iframes to do proper percent-decoding and error reporting.XMLHttpRequest
responses when they were over 1 MiB.close()
d, which could cause strange errors since most objects are unusable at that point. (Enverbalalic)Breaking changes:
parser
option to the old API, can no longer be specified. They were never tested, often broken, and a maintenance burden. The defaults, of parse5 for HTML and sax for XML, now always apply.dom.nodeLocation()
or the old API's jsdom.nodeLocation()
now have a different structure.runScripts
applies to event handler attributes; now they will no longer be converted into event handler functions unless runScripts: "dangerously"
is set. However, event handler properties will now work with any runScripts
option value, instead of being blocked.Other changes:
oneventname
properties to various prototypes, ensures the correct order when interleaving event handlers and other event listeners, and ensures that event handlers are evaluated with the correct values in scope.Location
properties to be on the instance, instead of the prototype, and to be non-configurable.HTMLCollection
, and thus of parsing large documents. (Zirro)getComputedStyle()
by removing unsupported selectors from the default style sheet. (flaviut)TypeError
when given invalid values. (TimothyGu)Symbol.toStringTag
properties to be non-writable and non-enumerable. (TimothyGu)tokenList.remove()
when the DOMTokenList
corresponded to a non-existant attribute. (Zirro)fileReader.abort()
to terminate ongoing reads properly.xhr.send()
to support array buffer views, not just ArrayBuffer
s. (ondras)GET
requests to data:
URLs using XMLHttpRequest
. (Zirro)runScripts
.tokenList.replace()
edge-case behavior."InvalidCharacterError"
DOMException
s, instead of "NamespaceError"
DOMException
s.input.select()
to no longer throw on types where selection does not apply.event.initEvent()
and various related methods to have additional defaults.XMLHttpRequest
responses.xhr.getAllResponseHeaders()
, and separating the header values with a comma-space (not just a comma).XMLHttpRequest
.XMLHttpRequest
.xhr.overrideMimeType()
to no longer throw for invalid input.blob.close()
and blob.isClosed()
.toString()
methods on various prototypes, which were made redundant in v10.1.0 but we forgot to remove.Symbol.toStringTag
to all web platform classes, so that now Object.prototype.toString.call()
works as expected on jsdom objects.select.selectedOptions
property.toString()
methods on various prototypes that returned "[object ClassName]"
in an attempt to fake the Symbol.toStringTag
behavior.XMLHttpRequest
to pre-allocate a 1 MiB buffer, which it grows exponentially as needed, in order to avoid frequent buffer allocation and concatenation. (skygon)runScripts
and resources
options into iframes.xhr.abort()
during a readystatechange
event.This release includes a complete overhaul of jsdom's API for creating and manipulating jsdoms. The new API is meant to be much more intuitive and have better defaults, with complete documentation in the newly-overhauled README. We hope you like it!
As discussed in the new README, the old API is still available and supported via require("jsdom/lib/old-api.js")
, at least until we have ported all of its features over to the new API. It will, however, not be gaining any new features, and we suggest you try the new API unless you really need the customizable resource loading the old API provides.
Apart from the new API, the following changes were made, with breaking changes bolded:
omitJsdomErrors
option to omitJSDOMErrors
, for consistency with web platform APIs.document.dir
. (Zirro)<a>
and <area>
APIs to the latest specification, and fixed a few bugs with them. (makana)<img>
elements to no longer fire load
events unless their image data is actually loaded (which generally only occurs when the canvas
package is installed).XMLHttpRequest
preflights to forward approved preflight headers to the actual request. (mbroadst)htmlElement.dir
to properly restrict its values to "ltr"
, "rtl"
, or "auto"
. (Zirro)innerHTML
to the empty string to no longer be a no-op. (Zirro)window.postMessage()
, so that now you don't always have to pass an origin of "*"
. (jmlopez-rod)xhr.open()
error message when there are not enough arguments. (lencioni)Option
named constructor. (NAlexPear)canvas-prebuilt
npm package as an alternative to canvas
. (asturur)setTimeout()
and setInterval()
to always return a positive integer, instead of returning 0
the first time were called. (yefremov)jsdom.env()
to preserve URL fragments across redirects. (josephfrazier)optionEl.text
and optionEl.value
to be more spec-compliant.event.stopImmediatePropagation()
to actually stop immediate propagation, not just propagation.clearTimeout()
and clearInterval()
to work correctly when using jsdom browserified.offsetTop
, offsetLeft
, offsetWidth
, and offsetHeight
that always return 0
, and offsetParent
which always returns null
, for all HTML elements. (yefremov)forEach
, keys
, values
, and entries
methods to NodeList
.event.cancelBubble
.scrollWidth
, scrollHeight
, clientTop
, clientLeft
, clientWidth
, and clientHeight
that always return 0
to all elements. (alistairjcbrown)Blob
, File
, and FileReader
to better match the File API specification. (TimothyGu)XMLHttpRequest
to match recent specification changes and test updates.element.getClientRects()
to return an empty array, instead of an array containing a dummy bounding box. (alistairjcbrown)navigator.vendor
to return "Apple Computer, Inc."
instead of "Google Inc."
, since we have chosen the WebKit navigator compatibility mode.array.includes
to fix a compatibility issue with Node.js v4.CDATASection
nodes, including document.createCDATASection
. (snuggs)node.wholeText
. (jdanyow)document.body
.document.embeds
, document.plugsin
, and document.scripts
. These were supposed to be added in 9.5.0 but were mistakenly omitted.element.insertAdjacentHTML
to work when the element has null or the document as its parent node, as long as the insertion position is "afterbegin"
or "beforeend"
.{ once: true }
option to addEventListener
. (i8-pi)XHTMLHttpRequest
and POSTing JSON contents to an endpoint that requires CORS while using an Authorization
header. (dunnock)document.body
and document.title
to act more correctly in various edge cases.HTMLCollection
named access to return the first element encountered, not the last.DOMTokenList
and getElementsByClassName
to only split on ASCII whitespace, not all Unicode whitespace.getElementsByClassName
, e.g. getElementsByClassName("")
or getElementsByClassName(" ")
.blob.isClosed
property. (TimothyGu)file.lastModified
property to be on File
instead of on Blob
. (TimothyGu)file.lastModified
property to default to the time of the File
object's creation, not the time that the property is accessed. (TimothyGu)"iframe"
became focusable in v9.7.0.EventListenerOptions
support to addEventListener
and removeEventListener
, including both the once
and capture
options. (GianlucaGuarini)document.hasFocus()
(acusti)iframe
will also focus the iframe
itself. (acusti)HTMLCollection.prototype[Symbol.iterator]
, so you can use for
-of
loops over HTMLCollection
s now. (i8-pi)file.lastModified
to return the current time as the default, instead of 0
.Attr
s to properly clone the namespace prefix.XMLHttpRequest
progress event ordering slightly to better match the spec and browsers.event.stopPropagation
and event.stopImmediatePropagation
on already-dispatched events, per the latest changes to the DOM Standard.document.scripts
, document.embeds
, and document.plugins
.document.getElementsByTagName
and document.getElementsByTagNameNS
to return HTMLCollection
s instead of NodeList
s, and to follow the spec algorithms more exactly.HTMLCollection
-returning getters such as document.applets
or table.cells
to be more spec-compliant.agent
and agentClass
options, not just the agentOptions
one.console.groupCollapse
to be console.groupCollapsed
(and changed the virtual console accordingly).error
events from failed resource loads going missing since v9.4.3. I really should have tested that release better.console.log
introduced in the error handling path in v9.4.3."jsdomError"
s occuring when closing a window, due to aborted resource loads.element.onclick
) would return non-boolean values (such as undefined
); it would previously erroneously cancel the event, in many cases. (dmethvin)<input>
elements, so that cloned inputs properly copy over their value, checkedness, dirty value flag, and dirty checkedness flag. (matthewp)DOMParser
API. It is spec-compliant, including producing <parsererror>
elements, except that the produced documents do not have the same URL as the creating document (they instead always have "about:blank"
).parsingMode: "xml"
. Creating documents will now fail, just like in a browser, when ill-formed XHTML markup is used.<!ENTITY
declarations.window.frameElement
, although without appropriate cross-origin security checks.jsdom.evalVMScript
public API.agent
and agentClass
in addition to agentOptions
. (frarees)<fieldset disabled>
.FormData
for recent spec fixes: blobs, files, and filenames should now all work like you'd expect.FormData
constructor to use the proper, rather-complex, constructing the form data set algorithm.window
object to be non-enumerable.<script>
elements to load when they gain a src
attribute while in a document.<link rel="stylesheet">
elements to load when their href
attributes change while in a document.<img>
s (when the canvas
npm package is installed) that were specified via relative URL; this regressed in 9.2.1.<iframe>
documents to have the correct referrer
value (viz. the URL of their parent).input.checked
inside click
events on checkboxes.<iframe>
element or the <iframe>
's window in appropriate scenarios involving name
vs. id
attributes on the <iframe>
. (matthewp)Audio
named constructor.Image
named constructor to follow the spec more closely (e.g. Image.prototype
is now equal to HTMLImageElement.prototype
).tabIndex
setter, which regressed in 9.1.0, to no longer cause errors.<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
v2.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 v9.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 ""
.DOMError
, 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.jsdom()
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
v0.2.29.div[title=""]
, now work correctly, as of nwmatcher
v1.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)jsdom.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. - Yonathan