doing 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.
EventTargets 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.jsdomjsdom.version: use require("jsdom/package.json").versionjsdom.level: levels are deprecated and will probably be removed in 2.0.0jsdom.domjsdom.browserAugmentationjsdom.windowAugmentationjsdom.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.parentWindowdocument.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 DocumentFragments. (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 hrefs. 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)HTMLCollections 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.NodeLists no longer expose nonstandard properties to the world, like toArray, without first prefixing them with an underscore.NodeLists 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