dragonfly_chrome_headless 0.2.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 (228) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.travis.yml +12 -0
  4. data/Gemfile +4 -0
  5. data/README.md +53 -0
  6. data/Rakefile +10 -0
  7. data/bin/console +14 -0
  8. data/bin/setup +8 -0
  9. data/dragonfly_chrome_headless.gemspec +27 -0
  10. data/lib/dragonfly_chrome_headless.rb +9 -0
  11. data/lib/dragonfly_chrome_headless/plugin.rb +17 -0
  12. data/lib/dragonfly_chrome_headless/processors/rasterize.rb +33 -0
  13. data/lib/dragonfly_chrome_headless/version.rb +3 -0
  14. data/node_modules/.bin/chrome-remote-interface +1 -0
  15. data/node_modules/.bin/mkdirp +1 -0
  16. data/node_modules/.bin/rimraf +1 -0
  17. data/node_modules/@types/core-js/LICENSE +21 -0
  18. data/node_modules/@types/core-js/README.md +16 -0
  19. data/node_modules/@types/core-js/index.d.ts +2452 -0
  20. data/node_modules/@types/core-js/package.json +85 -0
  21. data/node_modules/@types/mkdirp/README.md +18 -0
  22. data/node_modules/@types/mkdirp/index.d.ts +14 -0
  23. data/node_modules/@types/mkdirp/package.json +77 -0
  24. data/node_modules/@types/mkdirp/types-metadata.json +25 -0
  25. data/node_modules/@types/node/README.md +16 -0
  26. data/node_modules/@types/node/index.d.ts +4132 -0
  27. data/node_modules/@types/node/package.json +84 -0
  28. data/node_modules/balanced-match/.npmignore +5 -0
  29. data/node_modules/balanced-match/LICENSE.md +21 -0
  30. data/node_modules/balanced-match/README.md +91 -0
  31. data/node_modules/balanced-match/index.js +59 -0
  32. data/node_modules/balanced-match/package.json +112 -0
  33. data/node_modules/brace-expansion/README.md +123 -0
  34. data/node_modules/brace-expansion/index.js +201 -0
  35. data/node_modules/brace-expansion/package.json +114 -0
  36. data/node_modules/chrome-launcher/.clang-format +6 -0
  37. data/node_modules/chrome-launcher/.npmignore +11 -0
  38. data/node_modules/chrome-launcher/README.md +123 -0
  39. data/node_modules/chrome-launcher/ask.js +32 -0
  40. data/node_modules/chrome-launcher/ask.ts +35 -0
  41. data/node_modules/chrome-launcher/chrome-finder.js +157 -0
  42. data/node_modules/chrome-launcher/chrome-finder.ts +186 -0
  43. data/node_modules/chrome-launcher/chrome-launcher.js +245 -0
  44. data/node_modules/chrome-launcher/chrome-launcher.ts +312 -0
  45. data/node_modules/chrome-launcher/compiled-check.js +14 -0
  46. data/node_modules/chrome-launcher/flags.js +27 -0
  47. data/node_modules/chrome-launcher/flags.ts +26 -0
  48. data/node_modules/chrome-launcher/index.js +7 -0
  49. data/node_modules/chrome-launcher/index.ts +1 -0
  50. data/node_modules/chrome-launcher/manual-chrome-launcher.js +30 -0
  51. data/node_modules/chrome-launcher/package.json +116 -0
  52. data/node_modules/chrome-launcher/random-port.js +24 -0
  53. data/node_modules/chrome-launcher/random-port.ts +23 -0
  54. data/node_modules/chrome-launcher/tsconfig.json +19 -0
  55. data/node_modules/chrome-launcher/utils.js +52 -0
  56. data/node_modules/chrome-launcher/utils.ts +44 -0
  57. data/node_modules/chrome-launcher/yarn.lock +1486 -0
  58. data/node_modules/chrome-remote-interface/LICENSE +18 -0
  59. data/node_modules/chrome-remote-interface/README.md +849 -0
  60. data/node_modules/chrome-remote-interface/bin/client.js +337 -0
  61. data/node_modules/chrome-remote-interface/chrome-remote-interface.js +11 -0
  62. data/node_modules/chrome-remote-interface/index.js +39 -0
  63. data/node_modules/chrome-remote-interface/lib/api.js +84 -0
  64. data/node_modules/chrome-remote-interface/lib/chrome.js +307 -0
  65. data/node_modules/chrome-remote-interface/lib/defaults.js +4 -0
  66. data/node_modules/chrome-remote-interface/lib/devtools.js +245 -0
  67. data/node_modules/chrome-remote-interface/lib/external-request.js +28 -0
  68. data/node_modules/chrome-remote-interface/lib/protocol.json +13780 -0
  69. data/node_modules/chrome-remote-interface/lib/websocket-wrapper.js +32 -0
  70. data/node_modules/chrome-remote-interface/package.json +128 -0
  71. data/node_modules/chrome-remote-interface/webpack.config.js +55 -0
  72. data/node_modules/commander/Readme.md +195 -0
  73. data/node_modules/commander/index.js +851 -0
  74. data/node_modules/commander/package.json +92 -0
  75. data/node_modules/concat-map/.travis.yml +4 -0
  76. data/node_modules/concat-map/LICENSE +18 -0
  77. data/node_modules/concat-map/README.markdown +62 -0
  78. data/node_modules/concat-map/example/map.js +6 -0
  79. data/node_modules/concat-map/index.js +13 -0
  80. data/node_modules/concat-map/package.json +117 -0
  81. data/node_modules/concat-map/test/map.js +39 -0
  82. data/node_modules/debug/.coveralls.yml +1 -0
  83. data/node_modules/debug/.eslintrc +11 -0
  84. data/node_modules/debug/.npmignore +9 -0
  85. data/node_modules/debug/.travis.yml +14 -0
  86. data/node_modules/debug/CHANGELOG.md +357 -0
  87. data/node_modules/debug/LICENSE +19 -0
  88. data/node_modules/debug/Makefile +50 -0
  89. data/node_modules/debug/Readme.md +312 -0
  90. data/node_modules/debug/component.json +19 -0
  91. data/node_modules/debug/karma.conf.js +70 -0
  92. data/node_modules/debug/node.js +1 -0
  93. data/node_modules/debug/package.json +124 -0
  94. data/node_modules/debug/src/browser.js +185 -0
  95. data/node_modules/debug/src/debug.js +202 -0
  96. data/node_modules/debug/src/index.js +10 -0
  97. data/node_modules/debug/src/node.js +246 -0
  98. data/node_modules/fs.realpath/LICENSE +43 -0
  99. data/node_modules/fs.realpath/README.md +33 -0
  100. data/node_modules/fs.realpath/index.js +66 -0
  101. data/node_modules/fs.realpath/old.js +303 -0
  102. data/node_modules/fs.realpath/package.json +94 -0
  103. data/node_modules/glob/LICENSE +15 -0
  104. data/node_modules/glob/README.md +368 -0
  105. data/node_modules/glob/changelog.md +67 -0
  106. data/node_modules/glob/common.js +240 -0
  107. data/node_modules/glob/glob.js +790 -0
  108. data/node_modules/glob/package.json +112 -0
  109. data/node_modules/glob/sync.js +486 -0
  110. data/node_modules/html-pdf-chrome/.npmignore +9 -0
  111. data/node_modules/html-pdf-chrome/LICENSE +21 -0
  112. data/node_modules/html-pdf-chrome/README.md +165 -0
  113. data/node_modules/html-pdf-chrome/lib/src/ChromePrintOptions.d.ts +87 -0
  114. data/node_modules/html-pdf-chrome/lib/src/ChromePrintOptions.js +4 -0
  115. data/node_modules/html-pdf-chrome/lib/src/ChromePrintOptions.js.map +1 -0
  116. data/node_modules/html-pdf-chrome/lib/src/CompletionTrigger.d.ts +120 -0
  117. data/node_modules/html-pdf-chrome/lib/src/CompletionTrigger.js +206 -0
  118. data/node_modules/html-pdf-chrome/lib/src/CompletionTrigger.js.map +1 -0
  119. data/node_modules/html-pdf-chrome/lib/src/CreateResult.d.ts +70 -0
  120. data/node_modules/html-pdf-chrome/lib/src/CreateResult.js +98 -0
  121. data/node_modules/html-pdf-chrome/lib/src/CreateResult.js.map +1 -0
  122. data/node_modules/html-pdf-chrome/lib/src/index.d.ts +72 -0
  123. data/node_modules/html-pdf-chrome/lib/src/index.js +123 -0
  124. data/node_modules/html-pdf-chrome/lib/src/index.js.map +1 -0
  125. data/node_modules/html-pdf-chrome/package.json +133 -0
  126. data/node_modules/html-pdf-chrome/src/ChromePrintOptions.ts +99 -0
  127. data/node_modules/html-pdf-chrome/src/CompletionTrigger.ts +201 -0
  128. data/node_modules/html-pdf-chrome/src/CreateResult.ts +100 -0
  129. data/node_modules/html-pdf-chrome/src/index.ts +179 -0
  130. data/node_modules/inflight/LICENSE +15 -0
  131. data/node_modules/inflight/README.md +37 -0
  132. data/node_modules/inflight/inflight.js +54 -0
  133. data/node_modules/inflight/package.json +105 -0
  134. data/node_modules/inherits/LICENSE +16 -0
  135. data/node_modules/inherits/README.md +42 -0
  136. data/node_modules/inherits/inherits.js +7 -0
  137. data/node_modules/inherits/inherits_browser.js +23 -0
  138. data/node_modules/inherits/package.json +97 -0
  139. data/node_modules/lighthouse-logger/README.md +4 -0
  140. data/node_modules/lighthouse-logger/index.js +212 -0
  141. data/node_modules/lighthouse-logger/package.json +69 -0
  142. data/node_modules/lighthouse-logger/yarn.lock +13 -0
  143. data/node_modules/minimatch/LICENSE +15 -0
  144. data/node_modules/minimatch/README.md +209 -0
  145. data/node_modules/minimatch/minimatch.js +923 -0
  146. data/node_modules/minimatch/package.json +99 -0
  147. data/node_modules/minimist/.travis.yml +4 -0
  148. data/node_modules/minimist/LICENSE +18 -0
  149. data/node_modules/minimist/example/parse.js +2 -0
  150. data/node_modules/minimist/index.js +187 -0
  151. data/node_modules/minimist/package.json +101 -0
  152. data/node_modules/minimist/readme.markdown +73 -0
  153. data/node_modules/minimist/test/dash.js +24 -0
  154. data/node_modules/minimist/test/default_bool.js +20 -0
  155. data/node_modules/minimist/test/dotted.js +16 -0
  156. data/node_modules/minimist/test/long.js +31 -0
  157. data/node_modules/minimist/test/parse.js +318 -0
  158. data/node_modules/minimist/test/parse_modified.js +9 -0
  159. data/node_modules/minimist/test/short.js +67 -0
  160. data/node_modules/minimist/test/whitespace.js +8 -0
  161. data/node_modules/mkdirp/.travis.yml +8 -0
  162. data/node_modules/mkdirp/LICENSE +21 -0
  163. data/node_modules/mkdirp/bin/cmd.js +33 -0
  164. data/node_modules/mkdirp/bin/usage.txt +12 -0
  165. data/node_modules/mkdirp/examples/pow.js +6 -0
  166. data/node_modules/mkdirp/index.js +98 -0
  167. data/node_modules/mkdirp/package.json +93 -0
  168. data/node_modules/mkdirp/readme.markdown +100 -0
  169. data/node_modules/mkdirp/test/chmod.js +41 -0
  170. data/node_modules/mkdirp/test/clobber.js +38 -0
  171. data/node_modules/mkdirp/test/mkdirp.js +28 -0
  172. data/node_modules/mkdirp/test/opts_fs.js +29 -0
  173. data/node_modules/mkdirp/test/opts_fs_sync.js +27 -0
  174. data/node_modules/mkdirp/test/perm.js +32 -0
  175. data/node_modules/mkdirp/test/perm_sync.js +36 -0
  176. data/node_modules/mkdirp/test/race.js +37 -0
  177. data/node_modules/mkdirp/test/rel.js +32 -0
  178. data/node_modules/mkdirp/test/return.js +25 -0
  179. data/node_modules/mkdirp/test/return_sync.js +24 -0
  180. data/node_modules/mkdirp/test/root.js +19 -0
  181. data/node_modules/mkdirp/test/sync.js +32 -0
  182. data/node_modules/mkdirp/test/umask.js +28 -0
  183. data/node_modules/mkdirp/test/umask_sync.js +32 -0
  184. data/node_modules/ms/README.md +51 -0
  185. data/node_modules/ms/index.js +152 -0
  186. data/node_modules/ms/license.md +21 -0
  187. data/node_modules/ms/package.json +109 -0
  188. data/node_modules/once/LICENSE +15 -0
  189. data/node_modules/once/README.md +79 -0
  190. data/node_modules/once/once.js +42 -0
  191. data/node_modules/once/package.json +101 -0
  192. data/node_modules/path-is-absolute/index.js +20 -0
  193. data/node_modules/path-is-absolute/license +21 -0
  194. data/node_modules/path-is-absolute/package.json +111 -0
  195. data/node_modules/path-is-absolute/readme.md +59 -0
  196. data/node_modules/rimraf/LICENSE +15 -0
  197. data/node_modules/rimraf/README.md +101 -0
  198. data/node_modules/rimraf/bin.js +50 -0
  199. data/node_modules/rimraf/package.json +99 -0
  200. data/node_modules/rimraf/rimraf.js +363 -0
  201. data/node_modules/ultron/LICENSE +22 -0
  202. data/node_modules/ultron/index.js +138 -0
  203. data/node_modules/ultron/package.json +112 -0
  204. data/node_modules/wrappy/LICENSE +15 -0
  205. data/node_modules/wrappy/README.md +36 -0
  206. data/node_modules/wrappy/package.json +97 -0
  207. data/node_modules/wrappy/wrappy.js +33 -0
  208. data/node_modules/ws/LICENSE +21 -0
  209. data/node_modules/ws/README.md +259 -0
  210. data/node_modules/ws/SECURITY.md +33 -0
  211. data/node_modules/ws/index.js +15 -0
  212. data/node_modules/ws/lib/BufferUtil.fallback.js +56 -0
  213. data/node_modules/ws/lib/BufferUtil.js +15 -0
  214. data/node_modules/ws/lib/ErrorCodes.js +28 -0
  215. data/node_modules/ws/lib/EventTarget.js +158 -0
  216. data/node_modules/ws/lib/Extensions.js +69 -0
  217. data/node_modules/ws/lib/PerMessageDeflate.js +339 -0
  218. data/node_modules/ws/lib/Receiver.js +520 -0
  219. data/node_modules/ws/lib/Sender.js +438 -0
  220. data/node_modules/ws/lib/Validation.fallback.js +9 -0
  221. data/node_modules/ws/lib/Validation.js +17 -0
  222. data/node_modules/ws/lib/WebSocket.js +705 -0
  223. data/node_modules/ws/lib/WebSocketServer.js +336 -0
  224. data/node_modules/ws/package.json +122 -0
  225. data/package.json +26 -0
  226. data/samples/sample.html +13 -0
  227. data/script/rasterize.js +18 -0
  228. metadata +325 -0
@@ -0,0 +1,9 @@
1
+ coverage/
2
+ gulpfile.js
3
+ lib/test/
4
+ test/
5
+ tsconfig.json
6
+ tslint.json
7
+ .istanbul.yml
8
+ .travis.yml
9
+ .vscode/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Seth Westphal
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,165 @@
1
+ # html-pdf-chrome
2
+
3
+ [![npm version](https://badge.fury.io/js/html-pdf-chrome.svg)](https://badge.fury.io/js/html-pdf-chrome)
4
+ [![Build Status](https://travis-ci.org/westy92/html-pdf-chrome.svg)](https://travis-ci.org/westy92/html-pdf-chrome/)
5
+ [![Code Coverage](https://codecov.io/gh/westy92/html-pdf-chrome/branch/master/graph/badge.svg)](https://codecov.io/gh/westy92/html-pdf-chrome)
6
+ [![Dependency Status](https://david-dm.org/westy92/html-pdf-chrome.svg)](https://david-dm.org/westy92/html-pdf-chrome)
7
+ [![Known Vulnerabilities](https://snyk.io/test/github/westy92/html-pdf-chrome/badge.svg)](https://snyk.io/test/github/westy92/html-pdf-chrome)
8
+
9
+ HTML to PDF converter via Chrome/Chromium.
10
+
11
+ ## Prerequisites
12
+
13
+ * Chrome/Chromium 59 or higher (60 or higher for some features)
14
+ * Windows, macOS, or Linux
15
+ * Node.js v6 or later
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install --save html-pdf-chrome
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ __Note:__ It is _strongly_ recommended that you keep Chrome running side-by-side with Node.js. There is significant overhead starting up Chrome for each PDF generation which can be easily avoided.
26
+
27
+ It's suggested to use [pm2](http://pm2.keymetrics.io/) to ensure Chrome continues to run. If it crashes, it will restart automatically.
28
+
29
+ As of this writing, headless Chrome uses about 65mb of RAM while idle.
30
+
31
+ ```bash
32
+ # install pm2 globally
33
+ npm install -g pm2
34
+ # start Chrome and be sure to specify a port to use in the html-pdf-chrome options.
35
+ pm2 start google-chrome \
36
+ --interpreter none \
37
+ -- \
38
+ --headless \
39
+ --disable-gpu \
40
+ --disable-translate \
41
+ --disable-extensions \
42
+ --disable-background-networking \
43
+ --safebrowsing-disable-auto-update \
44
+ --disable-sync \
45
+ --metrics-recording-only \
46
+ --disable-default-apps \
47
+ --no-first-run \
48
+ --remote-debugging-port=<port goes here>
49
+ # run your Node.js app.
50
+ ```
51
+
52
+ TypeScript:
53
+
54
+ ```js
55
+ import * as htmlPdf from 'html-pdf-chrome';
56
+
57
+ const html = '<p>Hello, world!</p>';
58
+ const options: htmlPdf.CreateOptions = {
59
+ port: 9222, // port Chrome is listening on
60
+ };
61
+
62
+ // async
63
+ const pdf = await htmlPdf.create(html, options);
64
+ await pdf.toFile('test.pdf');
65
+ const base64 = pdf.toBase64();
66
+ const buffer = pdf.toBuffer();
67
+
68
+ // Promise
69
+ htmlPdf.create(html, options).then((pdf) => pdf.toFile('test.pdf'));
70
+ htmlPdf.create(html, options).then((pdf) => pdf.toBase64());
71
+ htmlPdf.create(html, options).then((pdf) => pdf.toBuffer());
72
+ ```
73
+
74
+ JavaScript:
75
+
76
+ ```js
77
+ const htmlPdf = require('html-pdf-chrome');
78
+
79
+ const html = '<p>Hello, world!</p>';
80
+ const options = {
81
+ port: 9222, // port Chrome is listening on
82
+ };
83
+
84
+ htmlPdf.create(html, options).then((pdf) => pdf.toFile('test.pdf'));
85
+ htmlPdf.create(html, options).then((pdf) => pdf.toBase64());
86
+ htmlPdf.create(html, options).then((pdf) => pdf.toBuffer());
87
+ ```
88
+
89
+ View the full documentation in the source code.
90
+
91
+ ### Using an External Site
92
+
93
+ ```js
94
+ import * as htmlPdf from 'html-pdf-chrome';
95
+
96
+ const options: htmlPdf.CreateOptions = {
97
+ port: 9222, // port Chrome is listening on
98
+ };
99
+
100
+ const url = 'https://github.com/westy92/html-pdf-chrome';
101
+ const pdf = await htmlPdf.create(url, options);
102
+ ```
103
+
104
+ ### Using a Template Engine
105
+
106
+ Pug (formerly known as Jade)
107
+
108
+ ```js
109
+ import * as htmlPdf from 'html-pdf-chrome';
110
+ import * as pug from 'pug';
111
+
112
+ const template = pug.compile('p Hello, #{noun}!');
113
+ const templateData = {
114
+ noun: 'world',
115
+ };
116
+ const options: htmlPdf.CreateOptions = {
117
+ port: 9222, // port Chrome is listening on
118
+ };
119
+
120
+ const html = template(templateData);
121
+ const pdf = await htmlPdf.create(html, options);
122
+ ```
123
+
124
+ ### Trigger Render Completion
125
+
126
+ There are a few `CompletionTrigger` types that wait for something to occur before triggering PDF printing.
127
+
128
+ * Callback - waits for a callback to be called
129
+ * Element - waits for an element to be injected into the DOM
130
+ * Event - waits for an Event to fire
131
+ * Timer - waits a specified amount of time
132
+ * Variable - waits for a variable to be set to `true`
133
+
134
+ ```js
135
+ const options: htmlPdf.CreateOptions = {
136
+ port: 9222, // port Chrome is listening on
137
+ completionTrigger: new htmlPdf.CompletionTrigger.Timer(5000), // milliseconds
138
+ };
139
+
140
+ // Alternative completionTrigger options:
141
+ new htmlPdf.CompletionTrigger.Callback(
142
+ 'cbName', // optional, name of the callback to define for the browser to call when finished rendering. Defaults to 'htmlPdfCb'.
143
+ 5000 // optional, timeout (milliseconds)
144
+ ),
145
+
146
+ new htmlPdf.CompletionTrigger.Element(
147
+ 'div#myElement', // name of the DOM element to wait for
148
+ 5000 // optional, timeout (milliseconds)
149
+ ),
150
+
151
+ new htmlPdf.CompletionTrigger.Event(
152
+ 'myEvent', // name of the event to listen for
153
+ '#myElement', // optional DOM element CSS selector to listen on, defaults to body
154
+ 5000 // optional timeout (milliseconds)
155
+ ),
156
+
157
+ new htmlPdf.CompletionTrigger.Variable(
158
+ 'myVarName', // optional, name of the variable to wait for. Defaults to 'htmlPdfDone'
159
+ 5000 // optional, timeout (milliseconds)
160
+ ),
161
+ ```
162
+
163
+ ## License
164
+
165
+ html-pdf-chrome is released under the MIT License.
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Chrome Page.printToPDF options.
3
+ * Note: these require Chrome >= 60.
4
+ *
5
+ * @export
6
+ * @interface ChromePrintOptions
7
+ */
8
+ export interface ChromePrintOptions {
9
+ /**
10
+ * Paper orientation. Defaults to false.
11
+ *
12
+ * @type {boolean}
13
+ * @memberof ChromePrintOptions
14
+ */
15
+ landscape?: boolean;
16
+ /**
17
+ * Display header and footer. Defaults to false.
18
+ *
19
+ * @type {boolean}
20
+ * @memberof ChromePrintOptions
21
+ */
22
+ displayHeaderFooter?: boolean;
23
+ /**
24
+ * Print background graphics. Defaults to false.
25
+ *
26
+ * @type {boolean}
27
+ * @memberof ChromePrintOptions
28
+ */
29
+ printBackground?: boolean;
30
+ /**
31
+ * Scale of the webpage rendering. Defaults to 1.
32
+ *
33
+ * @type {number}
34
+ * @memberof ChromePrintOptions
35
+ */
36
+ scale?: number;
37
+ /**
38
+ * Paper width in inches. Defaults to 8.5 inches.
39
+ *
40
+ * @type {number}
41
+ * @memberof ChromePrintOptions
42
+ */
43
+ paperWidth?: number;
44
+ /**
45
+ * Paper height in inches. Defaults to 11 inches.
46
+ *
47
+ * @type {number}
48
+ * @memberof ChromePrintOptions
49
+ */
50
+ paperHeight?: number;
51
+ /**
52
+ * Top margin in inches. Defaults to 1cm (~0.4 inches).
53
+ *
54
+ * @type {number}
55
+ * @memberof ChromePrintOptions
56
+ */
57
+ marginTop?: number;
58
+ /**
59
+ * Bottom margin in inches. Defaults to 1cm (~0.4 inches).
60
+ *
61
+ * @type {number}
62
+ * @memberof ChromePrintOptions
63
+ */
64
+ marginBottom?: number;
65
+ /**
66
+ * Left margin in inches. Defaults to 1cm (~0.4 inches).
67
+ *
68
+ * @type {number}
69
+ * @memberof ChromePrintOptions
70
+ */
71
+ marginLeft?: number;
72
+ /**
73
+ * Right margin in inches. Defaults to 1cm (~0.4 inches).
74
+ *
75
+ * @type {number}
76
+ * @memberof ChromePrintOptions
77
+ */
78
+ marginRight?: number;
79
+ /**
80
+ * Paper ranges to print, e.g., '1-5, 8, 11-13'.
81
+ * Defaults to the empty string, which means print all pages.
82
+ *
83
+ * @type {string}
84
+ * @memberof ChromePrintOptions
85
+ */
86
+ pageRanges?: string;
87
+ }
@@ -0,0 +1,4 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+
4
+ //# sourceMappingURL=ChromePrintOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["src/ChromePrintOptions.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC","file":"ChromePrintOptions.js","sourcesContent":["'use strict';\n\n/**\n * Chrome Page.printToPDF options.\n * Note: these require Chrome >= 60.\n *\n * @export\n * @interface ChromePrintOptions\n */\nexport interface ChromePrintOptions {\n /**\n * Paper orientation. Defaults to false.\n *\n * @type {boolean}\n * @memberof ChromePrintOptions\n */\n landscape?: boolean;\n\n /**\n * Display header and footer. Defaults to false.\n *\n * @type {boolean}\n * @memberof ChromePrintOptions\n */\n displayHeaderFooter?: boolean;\n\n /**\n * Print background graphics. Defaults to false.\n *\n * @type {boolean}\n * @memberof ChromePrintOptions\n */\n printBackground?: boolean;\n\n /**\n * Scale of the webpage rendering. Defaults to 1.\n *\n * @type {number}\n * @memberof ChromePrintOptions\n */\n scale?: number;\n\n /**\n * Paper width in inches. Defaults to 8.5 inches.\n *\n * @type {number}\n * @memberof ChromePrintOptions\n */\n paperWidth?: number;\n\n /**\n * Paper height in inches. Defaults to 11 inches.\n *\n * @type {number}\n * @memberof ChromePrintOptions\n */\n paperHeight?: number;\n\n /**\n * Top margin in inches. Defaults to 1cm (~0.4 inches).\n *\n * @type {number}\n * @memberof ChromePrintOptions\n */\n marginTop?: number;\n\n /**\n * Bottom margin in inches. Defaults to 1cm (~0.4 inches).\n *\n * @type {number}\n * @memberof ChromePrintOptions\n */\n marginBottom?: number;\n\n /**\n * Left margin in inches. Defaults to 1cm (~0.4 inches).\n *\n * @type {number}\n * @memberof ChromePrintOptions\n */\n marginLeft?: number;\n\n /**\n * Right margin in inches. Defaults to 1cm (~0.4 inches).\n *\n * @type {number}\n * @memberof ChromePrintOptions\n */\n marginRight?: number;\n\n /**\n * Paper ranges to print, e.g., '1-5, 8, 11-13'.\n * Defaults to the empty string, which means print all pages.\n *\n * @type {string}\n * @memberof ChromePrintOptions\n */\n pageRanges?: string;\n}\n"],"sourceRoot":"../.."}
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Defines a trigger that signifies page render completion.
3
+ *
4
+ * @export
5
+ * @abstract
6
+ * @class CompletionTrigger
7
+ */
8
+ export declare abstract class CompletionTrigger {
9
+ protected timeout: number;
10
+ protected timeoutMessage: string;
11
+ /**
12
+ * Creates an instance of CompletionTrigger.
13
+ * @param {number} [timeout=1000] milliseconds until timing out.
14
+ * @param {string} [timeoutMessage='CompletionTrigger timed out.'] The timeout message.
15
+ * @memberof CompletionTrigger
16
+ */
17
+ constructor(timeout?: number, timeoutMessage?: string);
18
+ /**
19
+ * Abstracts away the trigger logic.
20
+ *
21
+ * @abstract
22
+ * @param {*} client the Chrome connection information.
23
+ * @returns {Promise<any>} resolves if triggered, rejects on error or timeout.
24
+ * @memberof CompletionTrigger
25
+ */
26
+ abstract wait(client: any): Promise<any>;
27
+ }
28
+ /**
29
+ * Waits for a specified amount of time.
30
+ *
31
+ * @export
32
+ * @class Timer
33
+ * @extends {CompletionTrigger}
34
+ */
35
+ export declare class Timer extends CompletionTrigger {
36
+ /**
37
+ * Creates an instance of the Timer CompletionTrigger.
38
+ * @param {number} timeout ms to wait until timing out.
39
+ * @memberof Timer
40
+ */
41
+ constructor(timeout: number);
42
+ wait(client: any): Promise<any>;
43
+ }
44
+ /**
45
+ * Waits for an Event to fire.
46
+ *
47
+ * @export
48
+ * @class Event
49
+ * @extends {CompletionTrigger}
50
+ */
51
+ export declare class Event extends CompletionTrigger {
52
+ protected event: string;
53
+ protected cssSelector: string;
54
+ /**
55
+ * Creates an instance of the Event CompletionTrigger.
56
+ * @param {string} event the name of the event to listen for.
57
+ * @param {string} [cssSelector] the CSS selector of the element to listen on.
58
+ * Defaults to body.
59
+ * @param {number} [timeout] ms to wait until timing out.
60
+ * @memberof Event
61
+ */
62
+ constructor(event: string, cssSelector?: string, timeout?: number);
63
+ wait(client: any): Promise<any>;
64
+ }
65
+ /**
66
+ * Waits for a callback to be called.
67
+ *
68
+ * @export
69
+ * @class Callback
70
+ * @extends {CompletionTrigger}
71
+ */
72
+ export declare class Callback extends CompletionTrigger {
73
+ protected callbackName: string;
74
+ /**
75
+ * Creates an instance of the Callback CompletionTrigger.
76
+ * @param {string} [callbackName] the name of the callback to listen for.
77
+ * Defaults to htmlPdfCb.
78
+ * @param {number} [timeout] ms to wait until timing out.
79
+ * @memberof Callback
80
+ */
81
+ constructor(callbackName?: string, timeout?: number);
82
+ wait(client: any): Promise<any>;
83
+ }
84
+ /**
85
+ * Waits for a DOM element to appear.
86
+ *
87
+ * @export
88
+ * @class Element
89
+ * @extends {CompletionTrigger}
90
+ */
91
+ export declare class Element extends CompletionTrigger {
92
+ protected cssSelector: string;
93
+ /**
94
+ * Creates an instance of the Element CompletionTrigger.
95
+ * @param {string} cssSelector the element to listen for.
96
+ * @param {number} [timeout] ms to wait until timing out.
97
+ * @memberof Element
98
+ */
99
+ constructor(cssSelector: string, timeout?: number);
100
+ wait(client: any): Promise<any>;
101
+ }
102
+ /**
103
+ * Waits for a variable to be true.
104
+ *
105
+ * @export
106
+ * @class Variable
107
+ * @extends {CompletionTrigger}
108
+ */
109
+ export declare class Variable extends CompletionTrigger {
110
+ protected variableName: string;
111
+ /**
112
+ * Creates an instance of the Variable CompletionTrigger.
113
+ * @param {string} [variableName] the variable to listen on.
114
+ * Defaults to htmlPdfDone.
115
+ * @param {number} [timeout] ms to wait until timing out.
116
+ * @memberof Variable
117
+ */
118
+ constructor(variableName?: string, timeout?: number);
119
+ wait(client: any): Promise<any>;
120
+ }
@@ -0,0 +1,206 @@
1
+ 'use strict';
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ /**
12
+ * Defines a trigger that signifies page render completion.
13
+ *
14
+ * @export
15
+ * @abstract
16
+ * @class CompletionTrigger
17
+ */
18
+ class CompletionTrigger {
19
+ /**
20
+ * Creates an instance of CompletionTrigger.
21
+ * @param {number} [timeout=1000] milliseconds until timing out.
22
+ * @param {string} [timeoutMessage='CompletionTrigger timed out.'] The timeout message.
23
+ * @memberof CompletionTrigger
24
+ */
25
+ constructor(timeout = 1000, timeoutMessage = 'CompletionTrigger timed out.') {
26
+ this.timeout = timeout;
27
+ this.timeoutMessage = timeoutMessage;
28
+ }
29
+ }
30
+ exports.CompletionTrigger = CompletionTrigger;
31
+ /**
32
+ * Waits for a specified amount of time.
33
+ *
34
+ * @export
35
+ * @class Timer
36
+ * @extends {CompletionTrigger}
37
+ */
38
+ class Timer extends CompletionTrigger {
39
+ /**
40
+ * Creates an instance of the Timer CompletionTrigger.
41
+ * @param {number} timeout ms to wait until timing out.
42
+ * @memberof Timer
43
+ */
44
+ constructor(timeout) {
45
+ super(timeout);
46
+ }
47
+ wait(client) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ return new Promise((resolve) => {
50
+ setTimeout(resolve, this.timeout);
51
+ });
52
+ });
53
+ }
54
+ }
55
+ exports.Timer = Timer;
56
+ /**
57
+ * Waits for an Event to fire.
58
+ *
59
+ * @export
60
+ * @class Event
61
+ * @extends {CompletionTrigger}
62
+ */
63
+ class Event extends CompletionTrigger {
64
+ /**
65
+ * Creates an instance of the Event CompletionTrigger.
66
+ * @param {string} event the name of the event to listen for.
67
+ * @param {string} [cssSelector] the CSS selector of the element to listen on.
68
+ * Defaults to body.
69
+ * @param {number} [timeout] ms to wait until timing out.
70
+ * @memberof Event
71
+ */
72
+ constructor(event, cssSelector, timeout) {
73
+ super(timeout);
74
+ this.event = event;
75
+ this.cssSelector = cssSelector;
76
+ }
77
+ wait(client) {
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ const { Runtime } = client;
80
+ const selector = this.cssSelector ? `querySelector('${this.cssSelector}')` : 'body';
81
+ return Runtime.evaluate({
82
+ awaitPromise: true,
83
+ expression: `
84
+ new Promise((resolve, reject) => {
85
+ document.${selector}.addEventListener('${this.event}', resolve, { once: true });
86
+ setTimeout(() => reject('${this.timeoutMessage}'), ${this.timeout});
87
+ })`,
88
+ });
89
+ });
90
+ }
91
+ }
92
+ exports.Event = Event;
93
+ /**
94
+ * Waits for a callback to be called.
95
+ *
96
+ * @export
97
+ * @class Callback
98
+ * @extends {CompletionTrigger}
99
+ */
100
+ class Callback extends CompletionTrigger {
101
+ /**
102
+ * Creates an instance of the Callback CompletionTrigger.
103
+ * @param {string} [callbackName] the name of the callback to listen for.
104
+ * Defaults to htmlPdfCb.
105
+ * @param {number} [timeout] ms to wait until timing out.
106
+ * @memberof Callback
107
+ */
108
+ constructor(callbackName, timeout) {
109
+ super(timeout);
110
+ this.callbackName = callbackName;
111
+ }
112
+ wait(client) {
113
+ return __awaiter(this, void 0, void 0, function* () {
114
+ const { Runtime } = client;
115
+ const cbName = this.callbackName || 'htmlPdfCb';
116
+ return Runtime.evaluate({
117
+ awaitPromise: true,
118
+ expression: `
119
+ new Promise((resolve, reject) => {
120
+ ${cbName} = resolve;
121
+ setTimeout(() => reject('${this.timeoutMessage}'), ${this.timeout});
122
+ })`,
123
+ });
124
+ });
125
+ }
126
+ }
127
+ exports.Callback = Callback;
128
+ /**
129
+ * Waits for a DOM element to appear.
130
+ *
131
+ * @export
132
+ * @class Element
133
+ * @extends {CompletionTrigger}
134
+ */
135
+ class Element extends CompletionTrigger {
136
+ /**
137
+ * Creates an instance of the Element CompletionTrigger.
138
+ * @param {string} cssSelector the element to listen for.
139
+ * @param {number} [timeout] ms to wait until timing out.
140
+ * @memberof Element
141
+ */
142
+ constructor(cssSelector, timeout) {
143
+ super(timeout);
144
+ this.cssSelector = cssSelector;
145
+ }
146
+ wait(client) {
147
+ return __awaiter(this, void 0, void 0, function* () {
148
+ const { Runtime } = client;
149
+ return Runtime.evaluate({
150
+ awaitPromise: true,
151
+ expression: `
152
+ new Promise((resolve, reject) => {
153
+ new MutationObserver((mutations, observer) => {
154
+ mutations.forEach((mutation) => {
155
+ if ([...mutation.addedNodes].find((node) => node.matches('${this.cssSelector}'))) {
156
+ observer.disconnect();
157
+ resolve();
158
+ }
159
+ });
160
+ }).observe(document.body, { childList: true });
161
+ setTimeout(() => reject('${this.timeoutMessage}'), ${this.timeout});
162
+ })`,
163
+ });
164
+ });
165
+ }
166
+ }
167
+ exports.Element = Element;
168
+ /**
169
+ * Waits for a variable to be true.
170
+ *
171
+ * @export
172
+ * @class Variable
173
+ * @extends {CompletionTrigger}
174
+ */
175
+ class Variable extends CompletionTrigger {
176
+ /**
177
+ * Creates an instance of the Variable CompletionTrigger.
178
+ * @param {string} [variableName] the variable to listen on.
179
+ * Defaults to htmlPdfDone.
180
+ * @param {number} [timeout] ms to wait until timing out.
181
+ * @memberof Variable
182
+ */
183
+ constructor(variableName, timeout) {
184
+ super(timeout);
185
+ this.variableName = variableName;
186
+ }
187
+ wait(client) {
188
+ return __awaiter(this, void 0, void 0, function* () {
189
+ const { Runtime } = client;
190
+ const varName = this.variableName || 'htmlPdfDone';
191
+ return Runtime.evaluate({
192
+ awaitPromise: true,
193
+ expression: `
194
+ new Promise((resolve, reject) => {
195
+ Object.defineProperty(window, '${varName}', {
196
+ set: (val) => { if (val === true) resolve(); }
197
+ });
198
+ setTimeout(() => reject('${this.timeoutMessage}'), ${this.timeout});
199
+ })`,
200
+ });
201
+ });
202
+ }
203
+ }
204
+ exports.Variable = Variable;
205
+
206
+ //# sourceMappingURL=CompletionTrigger.js.map