README.md

jsdom

Install

Human contact

Easymode

Bootstrapping a DOM is generally a difficult process involving many error prone steps. We didn't want jsdom to fall into the same trap and that is why a new method, jsdom.env(), has been added in jsdom 0.2.0 which should make everyone's lives easier.

How it works

jsdom.env is built for ease of use, which is rare in the world of the DOM! Since the web has some absolutely horrible javascript on it, as of jsdom 0.2.0 jsdom.env will not process external resources (scripts, images, etc). If you want to process the javascript use one of the methods below (jsdom.jsdom or jsdom.jQueryify)

config.features : see Flexibility section below. Note: the default feature set for jsdom.env does not include fetching remote javascript and executing it. This is something that you will need to carefully enable yourself.

For the hardcore

If you want to spawn a document/window and specify all sorts of options this is the section for you. This section covers the jsdom.jsdom method:

markup is an html/xml document to be parsed. You can also pass null or an undefined value to get a basic document with empty head and body tags. Document fragments are also supported (including ""), and will behave as sanely as possible (eg. the resulting document will lack the head, body and documentElement properties if the corresponding elements aren't included).

level is null (which means level3) by default, but you can pass another level if you'd like.

Flexibility

One of the goals of jsdom is to be as minimal and light as possible. This section details how
someone can change the behavior of Documents on the fly. These features are baked into
the DOMImplementation that every Document has, and may be tweaked in two ways:

When you create a new Document using the jsdom builder (require('jsdom').jsdom())

Default Features

Default features are extremely important for jsdom as they lower the configuration requirement and present developers a set of consistent default behaviors. The following sections detail the available features, their defaults, and the values that jsdom uses.

Disabling this will disable script execution (currently only javascript).

MutationEventsdefault: '2.0'
allowed : '2.0' or false

Initially enabled to be up to spec. Disable this if you do not need mutation events and want jsdom to be a bit more efficient.

Note: ProcessExternalResources requires this to be enabled

QuerySelectordefault : false
allowed : true

This feature is backed by sizzle but currently causes problems with some libraries. Enable this if you want document.querySelector and friends, but be aware that many libraries feature detect for this, and it may cause you a bit of trouble.