You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+20-18Lines changed: 20 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -90,14 +90,12 @@ jsdom.env({
90
90
91
91
### How it works
92
92
93
-
`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`)
93
+
The do-what-I-mean API is used like so:
94
94
95
95
```js
96
96
jsdom.env(string, [scripts], [config], callback);
97
97
```
98
98
99
-
The arguments are:
100
-
101
99
-`string`: may be a URL, file name, or HTML fragment
102
100
-`scripts`: a string or array of strings, containing file names or URLs that will be inserted as `<script>` tags
103
101
-`config`: see below
@@ -170,6 +168,10 @@ Now that you know about `created` and `loaded`, you can see that `done` is essen
170
168
171
169
If you used jsdom before v1.0.0, it only had a `done` callback, and it was kind of buggy, sometimes behaving one way, and sometimes another. Due to some excellent work by [@Sebmaster](https://github.com/Sebmaster) in [#792](https://github.com/tmpvar/jsdom/pull/792), we fixed it up into the above lifecycle. For more information on the migration, see [the wiki](https://github.com/tmpvar/jsdom/wiki/PR-792).
172
170
171
+
### On running scripts and being safe
172
+
173
+
By default, `jsdom.env` will not process and run external JavaScript, since our sandbox is not foolproof. That is, code running inside the DOM's `<script>`s can, if it tries hard enough, get access to the Node environment, and thus to your machine. If you want to (carefully!) enable running JavaScript, you can use `jsdom.jsdom`, `jsdom.jQueryify`, or modify the defaults passed to `jsdom.env`.
174
+
173
175
## For the hardcore: `jsdom.jsdom`
174
176
175
177
The `jsdom.jsdom` method does less things automatically; it takes in only HTML source, and does not let you to separately supply script that it will inject and execute. It just gives you back a `document` object, with usable `document.parentWindow`, and starts asynchronously executing any `<script>`s included in the HTML source. You can listen for the `'load'` event to wait until scripts are done loading and executing, just like you would in a normal HTML page.
@@ -182,15 +184,15 @@ var doc = jsdom(markup, options);
182
184
varwindow=doc.parentWindow;
183
185
```
184
186
185
-
-`markup` is an HTML/XML document to be parsed. You can also pass `undefined` to get the basic document, equivalent to what a browser will give if you open up an empty `.html` file. Our parser currently doesn't do that well with missing `<html>`, `<head>`, and `<body>` tags, but we're working to fix that.
187
+
-`markup` is a HTML document to be parsed. You can also pass `undefined` to get the basic document, equivalent to what a browser will give if you open up an empty `.html` file.
186
188
187
-
-`options` See the explanation of the `config` object above.
189
+
-`options`: see the explanation of the `config` object above.
188
190
189
191
### Flexibility
190
192
191
-
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 `Document`s on the fly. These features are baked into the `DOMImplementation` that every `Document` has, and may be tweaked in two ways:
193
+
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 `Document`s before they are created. These features are baked into the `DOMImplementation` that every `Document` has, and may be tweaked in two ways:
192
194
193
-
1. When you create a new `Document` using the jsdom builder (`require("jsdom").jsdom()`)
195
+
1. When you create a new `Document`, by overriding the configuration:
194
196
195
197
```js
196
198
var jsdom =require("jsdom").jsdom;
@@ -212,32 +214,33 @@ One of the goals of jsdom is to be as minimal and light as possible. This sectio
212
214
};
213
215
```
214
216
215
-
#### Default Features
217
+
#### External Resources
216
218
217
219
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.
218
220
219
-
220
221
`FetchExternalResources`
221
222
222
223
-_Default_: `["script"]`
223
224
-_Allowed_: `["script", "img", "css", "frame", "iframe", "link"]` or `false`
225
+
-_Default for `jsdom.env`_: `false`
224
226
225
-
Enables/disables fetching files over the file system/HTTP.
227
+
Enables/disables fetching files over the file system/HTTP
226
228
227
229
`ProcessExternalResources`
228
230
229
231
-_Default_: `["script"]`
230
232
-_Allowed_: `["script"]` or `false`
233
+
-_Default for `jsdom.env`_: `false`
231
234
232
-
Disabling this will disable script execution (currently only JavaScript).
235
+
Enables/disables JavaScript execution
233
236
234
237
`SkipExternalResources`
235
238
236
-
-_Default_: `false`
239
+
-_Default_: `false` (allow all)
237
240
-_Allowed_: `/url to be skipped/` or `false`
238
241
-_Example_: `/http:\/\/example.org/js/bad\.js/`
239
242
240
-
Do not download and process resources with url matching a regular expression.
243
+
Filters resource downloading and processing to disallow those maching the given regular expression
241
244
242
245
### Canvas
243
246
@@ -249,7 +252,7 @@ jsdom includes support for using the [canvas](https://npmjs.org/package/canvas)
0 commit comments