html-snapshots 0.19.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/.github/workflows/verify.yml +2 -2
  2. package/HISTORY.md +42 -0
  3. package/README.md +92 -244
  4. package/examples/README.md +149 -0
  5. package/examples/custom/package-lock.json +1090 -9
  6. package/examples/custom/package.json +1 -1
  7. package/examples/debug-phantomjs/package.json +1 -1
  8. package/examples/debug-phantomjs/snapshot.js +1 -0
  9. package/examples/debug-puppeteer/README.md +18 -0
  10. package/examples/debug-puppeteer/package-lock.json +2804 -0
  11. package/examples/debug-puppeteer/package.json +12 -0
  12. package/examples/debug-puppeteer/snapshot.js +30 -0
  13. package/examples/html5rocks/package-lock.json +2 -2
  14. package/examples/html5rocks/package.json +1 -1
  15. package/examples/html5rocks/snapshot.js +0 -6
  16. package/examples/process-limit/package-lock.json +2 -2
  17. package/examples/process-limit/package.json +1 -1
  18. package/examples/simple-promise/package-lock.json +2 -2
  19. package/examples/simple-promise/package.json +1 -1
  20. package/examples/sitemap-index/package-lock.json +2 -2
  21. package/examples/sitemap-index/package.json +1 -1
  22. package/examples/verbose/package-lock.json +3 -4
  23. package/examples/verbose/package.json +1 -1
  24. package/examples/verbose/snapshot.js +1 -0
  25. package/lib/html-snapshots.js +87 -4
  26. package/lib/input-generators/_base.js +7 -1
  27. package/lib/puppeteer/index.js +98 -0
  28. package/lib/puppeteer/removeScripts.js +8 -0
  29. package/package.json +6 -2
  30. package/test/mocha/browsers/puppeteer.js +106 -0
  31. package/test/mocha/browsers/server/index.html +9 -0
  32. package/test/mocha/browsers/test.js +11 -0
  33. package/test/mocha/html-snapshots/basics.js +60 -47
  34. package/test/mocha/html-snapshots/phantomjs-options.js +54 -60
  35. package/test/mocha/html-snapshots/process-limit.js +100 -92
  36. package/test/mocha/html-snapshots/puppeteer.js +47 -0
  37. package/test/mocha/html-snapshots/robots.js +137 -120
  38. package/test/mocha/html-snapshots/server/public/page-sitemap.xml +16 -0
  39. package/test/mocha/html-snapshots/sitemap-index.js +89 -80
  40. package/test/mocha/html-snapshots/sitemap.js +75 -31
  41. package/test/mocha/html-snapshots/snapshot-scripts.js +124 -120
  42. package/test/mocha/html-snapshots/test.js +11 -2
  43. package/test/mocha/html-snapshots/use-jquery.js +65 -64
  44. package/test/mocha/html-snapshots/utils.js +29 -29
@@ -18,12 +18,12 @@ jobs:
18
18
  steps:
19
19
  - uses: actions/checkout@v3
20
20
  - name: Use Node.js ${{ matrix.node-version }}
21
- uses: actions/setup-node@v3.0.0
21
+ uses: actions/setup-node@v3
22
22
  with:
23
23
  node-version: ${{ matrix.node-version }}
24
24
  - run: npm ci
25
25
  - name: Lint, Test, And Coverage
26
- run: npm run lint && npm run test && npm run test:cover
26
+ run: npm run lint && xvfb-run -a npm run test:cover
27
27
  - name: Coverage Upload
28
28
  if: ${{ success() }}
29
29
  uses: coverallsapp/github-action@master
package/HISTORY.md ADDED
@@ -0,0 +1,42 @@
1
+ # History
2
+ An overview of the [Breaking Changes](#breaking-changes) and [Node Support](#node-support-tags).
3
+
4
+ ## Breaking Changes
5
+
6
+ ### Introduced in v1.0.0
7
+ Puppeteer process introduced and used as the default browser, `browser` option added to switch back ("puppeteer" vs "phantomjs").
8
+
9
+ ### Introduced in v0.19.x
10
+ #### Robots Input
11
+ Robots.txt files are now searched for `Sitemap` directive(s) **first** for sitemap/sitemapIndex files. If those directives are found, those directives are used to drive the crawl of the site alone. If no Sitemap directives are found, htmlSnapshots reverts back to using `Allow` directives. If no `Sitemap` directive is found, this is a non-breaking change.
12
+
13
+ ### Introduced in v0.18.x
14
+ #### Dropped support for Node 10 & 12.
15
+
16
+ ### Introduced in v0.17.x
17
+ #### Dropped support for Node 8.
18
+
19
+ ### Introduced in v0.16.x
20
+ #### Dropped support for Node 6.
21
+
22
+ ### Introduced in v0.15.x
23
+ #### Dropped support for Node 4.
24
+
25
+ ### Introduced in v0.14.x
26
+ #### Run method return value
27
+ The library `run` method no longer returns a boolean value indicating a successful start. Instead, it returns a Promise that resolves to an array of file paths to completed snapshots, or error on failure. The `run` method's second argument, a completion callback, is now **optional** and provided for compatibility only. If you supply one, it will be called, but the Promise will also resolve, so it is not needed.
28
+ #### Dropped support for Node <= 0.12
29
+
30
+ ### Introduced in v0.6.x
31
+ jQuery selectors are no longer supported by default. To restore the previous behavior, set the `useJQuery` option to `true`.
32
+ The upside is jQuery is no longer required to be loaded by the page being snapshotted. However, if you use jQuery selectors, or selectors not supported by [querySelector](https://developer.mozilla.org/en-US/docs/Web/API/document.querySelector), the page being snapshotted must load jQuery.
33
+
34
+ ## Node Support Tags
35
+ `v0.13.2 ` Node 0.12 (or less)
36
+ `v0.14.16` Node 4+
37
+ `v0.15.x ` Node 6+
38
+ `v0.16.x ` Node 8+
39
+ `v0.17.x ` Node 10+
40
+ `v0.18.x ` Node 14+
41
+ `v0.19.x ` Node 14+
42
+ `v1.0.x ` Node 14+
package/README.md CHANGED
@@ -11,20 +11,8 @@
11
11
  + [Getting Started](#getting-started)
12
12
  + [Grunt Task](https://github.com/localnerve/grunt-html-snapshots)
13
13
  + [More Information](#more-information)
14
- + [Breaking Changes](#breaking-changes)
15
14
  + [API Reference](#api)
16
15
  + [Example Usage](#example-usage)
17
- + [Per-page Selectors](#example---per-page-selectors-and-timeouts)
18
- + [Per-page Output Paths](#example---per-page-special-output-paths)
19
- + [Per-page jQuery](#example---per-page-selectors-and-jquery)
20
- + [Array Input](#example---array)
21
- + [Array Input DRY](/examples/html5rocks)
22
- + [Sitemap Index](/examples/sitemap-index)
23
- + [Process Limit](/examples/process-limit)
24
- + [Script Removal](#example---remote-robotstxt-remove-script-tags-from-html-snapshots)
25
- + [Custom Filters](/examples/custom)
26
- + [Debug PhantomJS w/Verbose Output](/examples/verbose)
27
- + [Debug PhantomJS w/Attach](/examples/debug-phantomjs)
28
16
  + [Option Reference](#options)
29
17
  + [Input Options](#input-control-options)
30
18
  + [Output Options](#output-control-options)
@@ -56,45 +44,11 @@ Here are some [background and other notes](/docs/notes.md) regarding this projec
56
44
  + [Why Does This Library Exist?](/docs/notes.md#why-does-this-exist)
57
45
  + [How To Use Without Knowing About Page Content](/docs/notes.md#what-if-i-dont-know-about-the-rendered-page-content)
58
46
  + [Caveats](/docs/notes.md#caveats)
47
+ + [Support History](HISTORY.md)
59
48
 
60
49
  ### Process Model
61
50
  html-snapshots takes snapshots in parallel, each page getting its own browser process. Each browser process dies after snapshotting one page. You can limit the number of browser processes that can ever run at once with the `processLimit` option. This effectively sets up a process pool for browser instances. The default processLimit is 4 browser instances. When a browser process dies, and another snapshot needs to be taken, a new browser process is spawned to take the vacant slot. This continues until a `processLimit` number of processes are running at once.
62
51
 
63
- ### Node Support Tags
64
- `v0.13.2 ` Node 0.12 (or less)
65
- `v0.14.16` Node 4+
66
- `v0.15.x ` Node 6+
67
- `v0.16.x ` Node 8+
68
- `v0.17.x ` Node 10+
69
- `v0.18.x ` Node 14+
70
-
71
- ### Breaking Changes
72
-
73
- #### Introduced in v0.19.x
74
- ##### Robots Input
75
- Robots.txt files are now searched for `Sitemap` directive(s) **first** for sitemap/sitemapIndex files. If those directives are found, those directives are used to drive the crawl of the site alone. If no Sitemap directives are found, htmlSnapshots reverts back to using `Allow` directives. If no `Sitemap` directive is found, this is a non-breaking change.
76
-
77
- #### Introduced in v0.18.x
78
- ##### Dropped support for Node 10 & 12.
79
-
80
- #### Introduced in v0.17.x
81
- ##### Dropped support for Node 8.
82
-
83
- #### Introduced in v0.16.x
84
- ##### Dropped support for Node 6.
85
-
86
- #### Introduced in v0.15.x
87
- ##### Dropped support for Node 4.
88
-
89
- #### Introduced in v0.14.x
90
- ##### Run method return value
91
- The library `run` method no longer returns a boolean value indicating a successful start. Instead, it returns a Promise that resolves to an array of file paths to completed snapshots, or error on failure. The `run` method's second argument, a completion callback, is now **optional** and provided for compatibility only. If you supply one, it will be called, but the Promise will also resolve, so it is not needed.
92
- ##### Dropped support for Node <= 0.12
93
-
94
- #### Introduced in v0.6.x
95
- jQuery selectors are no longer supported by default. To restore the previous behavior, set the `useJQuery` option to `true`.
96
- The upside is jQuery is no longer required to be loaded by the page being snapshotted. However, if you use jQuery selectors, or selectors not supported by [querySelector](https://developer.mozilla.org/en-US/docs/Web/API/document.querySelector), the page being snapshotted must load jQuery.
97
-
98
52
  ## API
99
53
  The api is just one `run` method that returns a Promise.
100
54
 
@@ -124,173 +78,37 @@ callback (errorObject, arrayOfPathsToCompletedSnapshots)
124
78
  *For the callback, in the error case, the errorObject does not have the new extra properties `completed` and `notCompleted`. However, `arrayOfPathsToCompletedSnapshots` is supplied, and contains the paths to the snapshots that successfully completed.*
125
79
 
126
80
  ## Example Usage
127
- Simple examples to demonstrate the usage of [options](#options).
128
-
129
- A growing showcase of runnable examples can be found [here](/examples).
130
-
131
- An older (version 0.13.2), more in depth usage example is located in this [article](/docs/example-heroku-redis.md) that includes explanation and code of a real usage featuring dynamic app routes, ExpressJS, Heroku, and more.
132
-
133
- ### Simple example
134
- ```javascript
135
- const htmlSnapshots = require('html-snapshots');
136
- htmlSnapshots.run({
137
- source: '/path/to/robots.txt',
138
- hostname: 'exampledomain.com',
139
- outputDir: './snapshots',
140
- outputDirClean: true,
141
- selector: '#dynamic-content'
142
- })
143
- .then(completed => {
144
- // completed is an array of full file paths to the completed snapshots.
145
- })
146
- .catch(error => {
147
- // error is an Error instance.
148
- // error.completed is an array of snapshot file paths that were completed.
149
- // error.notCompleted is an array of file paths that did NOT complete.
150
- });
151
- ```
152
- This reads the urls from your robots.txt and produces snapshots in the ./snapshots directory. In this example, a selector named "#dynamic-content" appears in all pages across the site. Once this selector is visible in a page, the html snapshot is taken.
153
-
154
- ### Example - Per page selectors and timeouts
155
- ```javascript
156
- const htmlSnapshots = require('html-snapshots');
157
- htmlSnapshots.run({
158
- input: 'sitemap',
159
- source: '/path/to/sitemap.xml',
160
- outputDir: './snapshots',
161
- outputDirClean: true,
162
- selector: {
163
- 'http://mysite.com': '#home-content',
164
- '__default': '#dynamic-content'
165
- },
166
- timeout: {
167
- 'http://mysite.com/superslowpage': 20000,
168
- '__default': 10000
169
- }
170
- })
171
- .then(completed => {
172
- // completed is an array of full file paths to the completed snapshots.
173
- })
174
- .catch(error => {
175
- // error is an Error instance.
176
- // error.completed is an array of snapshot file paths that were completed.
177
- // error.notCompleted is an array of file paths that did NOT complete.
178
- });
179
- ```
180
- This reads the urls from your sitemap.xml and produces snapshots in the ./snapshots directory. In this example, a selector named "#dynamic-content" appears in all pages across the site except the home page, where "#home-content" appears \(the appearance of a selector in the output triggers the snapshot\). Finally, a default timeout of 10000 ms is set on all pages except http://mysite.com/superslowpage, where it waits 20000 ms.
181
-
182
- ### Example - Per page special output paths
183
- ```javascript
184
- const htmlSnapshots = require('html-snapshots');
185
- htmlSnapshots.run({
186
- input: 'sitemap',
187
- source: '/path/to/sitemap.xml',
188
- outputDir: './snapshots',
189
- outputDirClean: true,
190
- outputPath: {
191
- 'http://mysite.com/services/?page=1': 'services/page/1',
192
- 'http://mysite.com/services/?page=2': 'services/page/2'
193
- },
194
- selector: '#dynamic-content'
195
- })
196
- .then(completed => {
197
- // completed is an array of full file paths to the completed snapshots.
198
- })
199
- .catch(error => {
200
- // error is an Error instance.
201
- // error.completed is an array of snapshot file paths that were completed.
202
- // error.notCompleted is an array of file paths that did NOT complete.
203
- });
204
- ```
205
- This example implies there are a couple of pages with query strings in sitemap.xml, and we don't want html-snapshots to create directories with query string characters in the names. We would also have a rewrite rule that reflects this same mapping when `_escaped_fragment_` shows up in the querystring of a request so we serve the snapshot from the appropriate directory.
81
+ This example reads the pages from a mix of sitemap or sitemap-index files found in the robots.txt and produces snapshots in the ./snapshots directory. In this example, a selector named "#dynamic-content" appears in all pages across the site. Once this selector is visible in a page, the html snapshot is taken and saved to ./snapshots.
206
82
 
207
- ### Example - Per page selectors and jQuery
83
+ ### Quick Example
208
84
  ```javascript
209
85
  const htmlSnapshots = require('html-snapshots');
210
86
  htmlSnapshots.run({
211
- source: '/path/to/robots.txt',
212
- hostname: 'mysite.com',
213
- outputDir: './snapshots',
214
- outputDirClean: true,
215
- selector: {
216
- '__default': '#dynamic-content',
217
- '/jqpage': 'A-Selector-Not-Supported-By-querySelector'
218
- },
219
- useJQuery: {
220
- '/jqpage': true,
221
- '__default': false
222
- }
223
- })
224
- .then(completed => {
225
- // completed is an array of full file paths to the completed snapshots.
226
- })
227
- .catch(error => {
228
- // error is an Error instance.
229
- // error.completed is an array of snapshot file paths that were completed.
230
- // error.notCompleted is an array of file paths that did NOT complete.
231
- });
232
- ```
233
- This reads the urls from your robots.txt and produces snapshots in the ./snapshots directory. In this example, a selector named "#dynamic-content" appears in all pages across the site except in "/jqpage", where a selector not supported by [querySelector](https://developer.mozilla.org/en-US/docs/Web/API/document.querySelector) is used. Further, "/jqpage" loads jQuery itself \(required\). All the other pages don't need to use special selectors, so the default is set to `false`. Notice that since a robots.txt input is used, full URLs are **not** used to match selectors. Instead, paths \(and QueryStrings and any Hashes\) are used, just as specified in the robots.txt file itself.
234
-
235
- ### Example - Array
236
- ```javascript
237
- const htmlSnapshots = require('html-snapshots');
238
- htmlSnapshots.run({
239
- input: 'array',
240
- source: ['http://mysite.com', 'http://mysite.com/contact', 'http://mysite.com:82/special'],
87
+ source: 'https://host.domain/robots.txt',
88
+ selector: '#dynamic-content',
241
89
  outputDir: './snapshots',
242
- outputDirClean: true,
243
- selector: '#dynamic-content'
90
+ outputDirClean: true
244
91
  })
245
92
  .then(completed => {
246
93
  // completed is an array of full file paths to the completed snapshots.
247
94
  })
248
95
  .catch(error => {
249
96
  // error is an Error instance.
250
- // error.completed is an array of snapshot file paths that were completed.
97
+ // error.completed is an array of snapshot file paths that did complete.
251
98
  // error.notCompleted is an array of file paths that did NOT complete.
252
99
  });
253
100
  ```
254
- Generates snapshots for "/", "/contact", and "/special" from mysite.com. "/special" uses port 82. All use http protocol. Array input can be powerful, check out a [simple example](/examples/simple-promise), or a more [complex example](/examples/html5rocks).
255
101
 
256
- ### Example - Remote robots.txt, remove script tags from html snapshots
257
- ```javascript
258
- const assert = require('assert');
259
- const fs = require('fs');
260
- const htmlSnapshots = require('html-snapshots');
102
+ More examples can be found in [this document](/examples/README.md). Also, A showcase of runnable examples can be found [here](/examples).
261
103
 
262
- htmlSnapshots.run({
263
- source: 'http://localhost/robots.txt',
264
- hostname: 'localhost',
265
- outputDir: './snapshots',
266
- outputDirClean: true,
267
- selector: '#dynamic-content',
268
- snapshotScript: {
269
- script: 'removeScripts'
270
- }
271
- })
272
- .then(completed => {
273
- completed.forEach(snapshotFile => {
274
- const content = fs.readFileSync(snapshotFile, { encoding: 'utf8'});
275
- assert.equal(false, /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi.test(content));
276
- });
277
- // It didn't throw b/c there are no script tags in the html snapshots
278
- console.log('stripped all script tags as expected');
279
- })
280
- .catch(error => {
281
- // error is an Error instance.
282
- // error.completed is an array of snapshot file paths that were completed.
283
- // error.notCompleted is an array of file paths that did NOT complete.
284
- });
285
- ```
286
- Removes all script tags from the output of the html snapshot. Custom filters are also supported, see the customFilter Example in the explanation of the `snapshotScript` option. Also, check out the concrete [example](/examples/custom).
104
+ An older (version 0.13.2), more in depth usage example is located in this [article](/docs/example-heroku-redis.md) that includes explanation and code of a real usage featuring dynamic app routes, ExpressJS, Heroku, and more.
287
105
 
288
106
  ## Options
289
107
  > Every option has a default value except `outputDir`.
290
108
 
291
109
  ### Input Control Options
292
110
 
293
- + `input`
111
+ * **input** {String}
294
112
  + default: `"robots"`
295
113
  + Specifies the input generator to be used to produce the urls.
296
114
 
@@ -302,15 +120,16 @@ Removes all script tags from the output of the html snapshot. Custom filters are
302
120
  + `"robots"` Supply urls from a local or remote robots.txt file. Robots.txt is first scanned for `Sitemap` directives. If found, those are used to drive the crawl. Otherwise, `Allow` directives are used in conjunction with [origin options](#origin-options).
303
121
  + `"textfile"` Supply urls from a local line-oriented text file in the style of robots.txt
304
122
 
305
- + `source`
123
+ * **source** {String|Array}
306
124
  + default: `"./robots.txt"`, `"./sitemap.xml"`, `"./sitemap-index.xml"`, `"./line.txt"`, or `[]`, depending on the input generator.
307
- + Specifies the input source. This must be a valid array or the location of a robots, text, or sitemap file for the corresponding input generator. robots.txt, sitemap.xml(.gz), sitemap-index.xml(.gz) can be local or remote. However, for the array input generator, this must be an array of urls.
125
+ + Specifies the input source. This must be a valid array or the location (local or remote) of a robots, text, or sitemap file for the corresponding input generator. For the array input generator, it must be an array of urls.
308
126
 
309
- ##### Robots.txt-With-Sitemap-Directives/Sitemap/Sitemap-Index Only Input Options
127
+ ##### Sitemap Only Input Options
128
+ > Options that apply to robots.txt with Sitemap directives, sitemaps, and sitemap-index input
310
129
 
311
- + `sitemapPolicy`
130
+ * **sitemapPolicy** {Boolean}
312
131
  + default: `false`
313
- + For use only with the sitemap and sitemap-index input generators. When true, lastmod and/or changefreq sitemap url child elements can be used to determine if a snapshot needs to be taken. Here are the possibilities for usage:
132
+ + For use only with the robots, sitemap, and sitemap-index input generators. When true, lastmod and/or changefreq sitemap url child elements can be used to determine if a snapshot needs to be taken. Here are the possibilities for usage:
314
133
  + Both lastmod and changefreq tags are specified alongside loc tags in the sitemap. In this case, both of these tags are used to determine if the url is out-of-date and needs a snapshot.
315
134
  + Only a lastmod tag is specified alongside loc tags in the sitemap. In this case, if an output file from a previous run is found for the url loc, then the file modification time is compared against the lastmod value to see if the url is out-of-date and needs a snapshot.
316
135
  + Only a changefreq tag is specified alongside loc tags in the sitemap. In this case, if an output file from a previous run is found for the url loc, then the last file modification time is used as a timespan \(from now\) and compared against the given changefreq to see if the url is out-of-date and needs a snapshot.
@@ -319,7 +138,7 @@ Removes all script tags from the output of the html snapshot. Custom filters are
319
138
 
320
139
  Not all url elements in a sitemap have to have lastmod and/or changefreq \(those tags are optional, unlike loc\), but the urls you want to be able to skip \(if they are current\) must make use of those tags. You can intermix usage of these tags, as long as the requirements are met for making an age determination. If a determination on age cannot be made for any reason, the url is processed normally. For more info on sitemap tags and acceptable values, read the [wikipedia](http://en.wikipedia.org/wiki/Sitemaps) page.
321
140
 
322
- + `sitemapOutputDir`
141
+ * **sitemapOutputDir** {String}
323
142
  + default: `_sitemaps_`
324
143
  + For use only with the sitemap-index input generator, this option directs the storage of sitemaps locally. It is a string that defines the name of the subdirectory under the `outputDir` where sitemaps are stored.
325
144
  Locally stored sitemaps are used for age determinations with incoming lastmod tags. If this option is falsy, it will prevent sitemap storage and thereby disable sitemapPolicy for sitemaps referenced in a sitemap-index.
@@ -329,33 +148,33 @@ Removes all script tags from the output of the html snapshot. Custom filters are
329
148
  ##### Origin Options
330
149
  > Origin options are only useful for Robots.txt files that use `Allow` directives and Textfile input types.
331
150
 
332
- + `hostname`
151
+ * **hostname** {String}
333
152
  + default: `"localhost"`
334
153
  + Specifies the hostname to use for paths found in a robots.txt or textfile. Applies to all pages. This option is ignored if you are using the sitemap or array input generators.
335
154
 
336
- + `port`
155
+ * **port** {Number}
337
156
  + default: 80
338
157
  + Specifies the port to use for all paths found in a robots.txt or textfile. This option is ignored if you are using the sitemap or array input generators.
339
158
 
340
- + `auth`
159
+ * **auth** {String}
341
160
  + default: none
342
161
  + Specifies the old-school authentication portion of the url. Applies to all path found in a robots.txt or textfile.
343
162
 
344
- + `protocol`
163
+ * **protocol** {String}
345
164
  + default: `"http"`
346
165
  + Specifies the protocol to use for all paths found in a robots.txt or textfile. This option is ignored if you are using the sitemap or array input generators.
347
166
 
348
167
  ### Output Control Options
349
168
 
350
- + `outputDir`
169
+ * **outputDir** {String}
351
170
  + default: none
352
171
  + **Required** \(you must specify a value\). Specifies the root output directory to put all the snapshot files in. Paths to the snapshot files in the output directory are defined by the paths in the urls themselves. The snapshot files are always named "index.html".
353
172
 
354
- + `outputDirClean`
173
+ * **outputDirClean** {Boolean}
355
174
  + default: `false`
356
175
  + Specifies if html-snapshots should clean the output directory before it creates the snapshots. If you are using sitemapPolicy and only specifying one of lastmod or changefreq in your sitemap \(thereby relying on file modification times on output files from a previous run\) this value must be false.
357
176
 
358
- + `outputPath`
177
+ * **outputPath** {Object|Function}
359
178
  + default: none
360
179
  + Specifies per url overrides to the generated snapshot output path. The default output path for a snapshot file, while rooted at outputDir, is simply an echo of the input path - plus any arguments. Depending on your urls, your `_escaped_fragment_` rewrite rule (see below), or the characters allowed in directory names in your environment, it might be necessary to use this option to change the output paths.
361
180
 
@@ -371,9 +190,9 @@ Removes all script tags from the output of the html snapshot. Custom filters are
371
190
 
372
191
  ### Snapshot Control Options
373
192
 
374
- + `selector`
193
+ * **selector** {String|Object|Function}
375
194
  + default: `"body"`
376
- + Specifies the selector to find in the output before taking the snapshot. The appearence of this selector in the output triggers a snapshot to be taken.
195
+ + The selector to wait for in the output that triggers a snapshot to be taken.
377
196
 
378
197
  The value can be one of these *javascript types*:
379
198
 
@@ -385,42 +204,43 @@ Removes all script tags from the output of the html snapshot. Custom filters are
385
204
 
386
205
  NOTE: By default, selectors must conform to [this spec](http://www.w3.org/TR/selectors-api/#grammar), as they are used by [querySelector](https://developer.mozilla.org/en-US/docs/Web/API/document.querySelector). If you need selectors not supported by this, you must specify the `useJQuery` option, and load jQuery in your page.
387
206
 
388
- + `useJQuery`
389
- + default: `false`
390
- + Specifies to use jQuery selectors to detect when to snapshot a page. Please note that you cannot use these selectors if the page to be snapshotted does not load jQuery itself. To return to the behavior prior to v0.6.x, set this to `true`.
207
+ * **snapshotScript** {String|Object}
208
+ + default: This library's default snapshot script. Which one is used is determined by the [`browser`](#process-control-options) option.
209
+ + Specifies the browser script to run to actually produce the snapshot. The script supplied in this option is run per url (or path) by html-snapshots in a separate browser process. Applies to all pages.
391
210
 
392
211
  The value can be one of these *javascript types*:
393
212
 
394
- `"boolean"` If the value is a boolean, it is used for every page. Note that if it is any scalar type such as "string" or "number", it will be interpreted as a boolean using javascript rules. Coerced string values "true", "yes", and "1" are specifically true, all others are false.
395
-
396
- `"object"` If the value is an object, it is interpreted as key/value pairs where the key must match the url (or path in the case of robots.txt style) found by the input generator. This allows you to specify the use of jQuery for individual pages. The reserved key "__default" allows you to specify a default jQuery usage so you don't have to specify usage for every individual page.
397
-
398
- `"function"` If the value is a function, it is called for every page and passed a single argument that is the url (or path in the case of robots.txt style) found in the input. The function must return a value to use for this option for the page it is given. The value returned for a given page must be a boolean.
399
-
400
- NOTE: You do not *have to* use this option if your page uses jQuery. You only need this if your selector is not supported by [querySelector](https://developer.mozilla.org/en-US/docs/Web/API/document.querySelector). However, if you do use this option, the page being snapshotted must load jQuery itself.
401
-
402
- + `snapshotScript`
403
- + default: This library's [default](/lib/phantom/default.js) snapshot script. This script runs in PhantomJS and takes the snapshot when the supplied selector becomes visible.
404
- + Specifies the PhantomJS script to run to actually produce the snapshot. The script supplied in this option is run per url (or path) by html-snapshots in a separate PhantomJS process. Applies to all pages.
405
-
406
- The value can be one of these *javascript types*:
407
-
408
- `"string"` If the value is a string, it must an absolute path to a custom PhantomJS script you supply. html-snapshots will spawn a separate PhantomJS instance to run your snapshot script and give it the following [arguments](http://phantomjs.org/api/system/property/args.html):
213
+ `"string"` If the value is a string, it must an absolute path to a custom script you supply.
214
+
215
+ + `browser: "phantomjs"`:
216
+ html-snapshots will spawn a separate phantomjs process to run your snapshot script and give it the following [arguments](http://phantomjs.org/api/system/property/args.html):
409
217
  + `system.args[0]` The path to your PhantomJS script.
410
- + `system.args[1]` The output path.
218
+ + `system.args[1]` The output file path.
411
219
  + `system.args[2]` The url to snapshot.
412
220
  + `system.args[3]` The selector to watch for to signal page completion.
413
221
  + `system.args[4]` The overall timeout \(milliseconds\).
414
222
  + `system.args[5]` The interval \(milliseconds\) to watch for the selector.
415
223
  + `system.args[6]` A flag indicating jQuery selectors should be supported.
416
224
  + `system.args[7]` A flag indicating verbose output is desired.
417
- + `system.args[8]` A custom module to load.
418
-
419
- `"object"` If an object is supplied, it has the following properties:
420
- + `script` This must be one of the following values:
421
- + `"removeScripts"` This runs the default snapshot script with an output filter that removes all script tags are removed from the html snapshot before it is saved.
422
- + `"customFilter"` This runs the default snapshot script, but allows you to supply any output filter.
423
- + `module` This property is required only if you supplied a value of `"customFilter"` for the `script` property. This must be an absolute path to a PhantomJS module you supply. Your module will be `require`d and called as a function to filter the html snapshot output. Your module's function will receive the entire raw html content as a single input string, and must return the filtered html content.
225
+ + `system.args[8]` A custom module to load.
226
+
227
+ + `browser: "puppeteer"`:
228
+ html-snapshots will spawn your script as a separate process and give it the following arguments:
229
+ + `process.argv[0]` The path to NodeJS.
230
+ + `process.argv[1]` The path to your snapshot script.
231
+ + `process.argv[2]` The output file path.
232
+ + `process.argv[3]` The url to snapshot.
233
+ + `process.argv[4]` The selector to wait for to signal page completion.
234
+ + `process.argv[5]` The overall timeout \(milliseconds\).
235
+ + `process.argv[6]` The path to a custom NodeJS module that returns a filter function.
236
+ + `process.argv[7]` A debug flag to kick the browser into headed, devtools mode.
237
+ + `process.argv[8]` A slowMo time \(milliseconds\) to slow the browser down.
238
+
239
+ `"object"` If an object is supplied, it has the following properties:
240
+ + `script` This must be one of the following values:
241
+ + `"removeScripts"` This runs the default snapshot script with an output filter that removes all script tags are removed from the html snapshot before it is saved.
242
+ + `"customFilter"` This runs the default snapshot script, but allows you to supply any output filter.
243
+ + `module` This property is required only if you supplied a value of `"customFilter"` for the `script` property. This must be an absolute path to a PhantomJS module you supply. Your module will be `require`d and called as a function to filter the html snapshot output. Your module's function will receive the entire raw html content as a single input string, and must return the filtered html content.
424
244
 
425
245
  customFilter Example:
426
246
  ```javascript
@@ -437,9 +257,30 @@ Removes all script tags from the output of the html snapshot. Custom filters are
437
257
  return content.replace(/someregex/g, 'somereplacement'); // remove or replace anything
438
258
  }
439
259
  ```
440
- A more complete example using custom options is available [here](/examples/custom).
260
+ A more complete example using custom options is available [here](/examples/custom).
261
+
262
+ * **debug** {Object}
263
+ > This options is only supported with the puppeteer browser script.
264
+ + default: `{ flag: false, slowMo: 500 }`
265
+ + Setting the `debug.flag` to true starts chrome in headed mode with devtools open. `debug.slowMo` is a time in milliseconds to reduce browser processing speed (larger numbers slows down chrome more). Recommended use is with a single problem page input using an Array source.
266
+
267
+ * **useJQuery** {Boolean|Object|Function}
268
+ > This option is only supported with the phantomjs browser script.
269
+ + default: `false`
270
+ + Specifies to use jQuery selectors to detect when to snapshot a page. Please note that you cannot use these selectors if the page to be snapshotted does not load jQuery itself. To return to the behavior prior to v0.6.x, set this to `true`.
441
271
 
442
- + `verbose`
272
+ The value can be one of these *javascript types*:
273
+
274
+ `"boolean"` If the value is a boolean, it is used for every page. Note that if it is any scalar type such as "string" or "number", it will be interpreted as a boolean using javascript rules. Coerced string values "true", "yes", and "1" are specifically true, all others are false.
275
+
276
+ `"object"` If the value is an object, it is interpreted as key/value pairs where the key must match the url (or path in the case of robots.txt style) found by the input generator. This allows you to specify the use of jQuery for individual pages. The reserved key "__default" allows you to specify a default jQuery usage so you don't have to specify usage for every individual page.
277
+
278
+ `"function"` If the value is a function, it is called for every page and passed a single argument that is the url (or path in the case of robots.txt style) found in the input. The function must return a value to use for this option for the page it is given. The value returned for a given page must be a boolean.
279
+
280
+ NOTE: You do not *have to* use this option if your page uses jQuery. You only need this if your selector is not supported by [querySelector](https://developer.mozilla.org/en-US/docs/Web/API/document.querySelector). However, if you do use this option, the page being snapshotted must load jQuery itself.
281
+
282
+ * **verbose** {Boolean|Object|Function}
283
+ > This option is only used with the phantomjs browser script
443
284
  + default: `false`
444
285
  + Specifies to turn on extended console output in the PhantomJS process for debugging purposes. Can be applied to all pages, or just specific page(s). It is recommended to do this one page at a time, as the output can be large, and interleaved with parallel processes. See following explanation of types for how to debug just one page, and also [this example](/examples/verbose).
445
286
 
@@ -453,7 +294,11 @@ Removes all script tags from the output of the html snapshot. Custom filters are
453
294
 
454
295
  ### Process Control Options
455
296
 
456
- + `timeout`
297
+ * **browser** {String}
298
+ + default: `"puppeteer"`
299
+ + Specifies which browser process to use in the crawl. Can be one of "phantomjs" or "puppeteer".
300
+
301
+ * **timeout** {Number|Object|Function}
457
302
  + default: 10000 \(milliseconds\)
458
303
  + Specifies the time to wait for the selector to become visible.
459
304
 
@@ -465,19 +310,21 @@ Removes all script tags from the output of the html snapshot. Custom filters are
465
310
 
466
311
  `"function"` If the value is a function, it is called for every page and passed a single argument that is the url (or path in the case of robots.txt style) found in the input. The function must return a value to use for this option for the page it is given. The value returned for a given page must be a number.
467
312
 
468
- + `processLimit`
313
+ * **processLimit** {Number}
469
314
  + default: 4
470
315
  + Limits the number of child PhantomJS processes that can ever be actively running in parallel. A value of 1 effectively forces the snapshots to be taken in series (only one at a time). Useful if you need to limit the number of processes spawned by this library. Experiment with what works best. One guideline suggests about [4 per CPU](http://stackoverflow.com/questions/9961254/how-to-manage-a-pool-of-phantomjs-instances).
471
316
 
472
- + `checkInterval`
317
+ * **pollInterval** {Number}
318
+ + default: 500 \(milliseconds\)
319
+ + Specifies the rate at which html-snapshots checks to see if a browser script has completed. Applies to all pages.
320
+
321
+ * **checkInterval** {Number}
322
+ > This option is only used with the phantomjs browser script
473
323
  + default: 250 (milliseconds)
474
324
  + Specifies the rate at which the PhantomJS script checks to see if the selector is visible yet. Applies to all pages.
475
325
 
476
- + `pollInterval`
477
- + default: 500 (milliseconds)
478
- + Specifies the rate at which html-snapshots checks to see if a PhantomJS script has completed. Applies to all pages.
479
-
480
- + `phantomjsOptions`
326
+ * **phantomjsOptions** {String|Array|Object|Function}
327
+ > This option is only used with the phantomjs browser script
481
328
  + default: ""
482
329
  + Specifies options to give to PhantomJS. Can specify per page or for all pages. Since PhantomJS instances run per page, it is possible to specify different PhantomJS options per page. Useful for debugging PhantomJS scripts on a specific page.
483
330
  For PhantomJS options syntax, checkout the [current options](http://phantomjs.org/api/command-line.html).
@@ -510,7 +357,8 @@ Removes all script tags from the output of the html snapshot. Custom filters are
510
357
  ```
511
358
  An example demonstrating how to **debug** a PhantomJS script is available [here](/examples/debug-phantomjs). It also demonstrates per-page option usage.
512
359
 
513
- + `phantomjs`
360
+ * **phantomjs** {String}
361
+ > This option is only used with the phantomjs browser script
514
362
  + default: A package local reference to PhantomJS.
515
363
  + Specifies the PhantomJS executable to run. Applies to all pages. Override this if you want to supply a path to a different version of PhantomJS. To reference PhantomJS globally in your environment, just use the value, "phantomjs". Remember, it must be found in your environment path to execute.
516
364
  See [PhantomJS](http://phantomjs.org/) for more information.