dragonfly_chrome_headless 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
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,312 @@
1
+ /**
2
+ * @license Copyright 2016 Google Inc. All Rights Reserved.
3
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
4
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
5
+ */
6
+ 'use strict';
7
+
8
+ import * as childProcess from 'child_process';
9
+ import * as fs from 'fs';
10
+ import * as chromeFinder from './chrome-finder';
11
+ import {getRandomPort} from './random-port';
12
+ import {DEFAULT_FLAGS} from './flags';
13
+ import {makeTmpDir, defaults, delay} from './utils';
14
+ import * as net from 'net';
15
+ const rimraf = require('rimraf');
16
+ const log = require('lighthouse-logger');
17
+ const spawn = childProcess.spawn;
18
+ const execSync = childProcess.execSync;
19
+ const isWindows = process.platform === 'win32';
20
+ const _SIGINT = 'SIGINT';
21
+ const _SIGINT_EXIT_CODE = 130;
22
+ const _SUPPORTED_PLATFORMS = new Set(['darwin', 'linux', 'win32']);
23
+
24
+ type SupportedPlatforms = 'darwin'|'linux'|'win32';
25
+
26
+ export interface Options {
27
+ startingUrl?: string;
28
+ chromeFlags?: Array<string>;
29
+ port?: number;
30
+ handleSIGINT?: boolean;
31
+ chromePath?: string;
32
+ userDataDir?: string;
33
+ logLevel?: string;
34
+ }
35
+
36
+ export interface LaunchedChrome {
37
+ pid: number;
38
+ port: number;
39
+ kill: () => Promise<{}>;
40
+ }
41
+
42
+ export interface ModuleOverrides {
43
+ fs?: typeof fs;
44
+ rimraf?: typeof rimraf;
45
+ spawn?: typeof childProcess.spawn;
46
+ }
47
+
48
+ export async function launch(opts: Options = {}): Promise<LaunchedChrome> {
49
+ opts.handleSIGINT = defaults(opts.handleSIGINT, true);
50
+
51
+ const instance = new Launcher(opts);
52
+
53
+ // Kill spawned Chrome process in case of ctrl-C.
54
+ if (opts.handleSIGINT) {
55
+ process.on(_SIGINT, async () => {
56
+ await instance.kill();
57
+ process.exit(_SIGINT_EXIT_CODE);
58
+ });
59
+ }
60
+
61
+ await instance.launch();
62
+
63
+ return {pid: instance.pid!, port: instance.port!, kill: async () => instance.kill()};
64
+ }
65
+
66
+ export class Launcher {
67
+ private tmpDirandPidFileReady = false;
68
+ private pollInterval: number = 500;
69
+ private pidFile: string;
70
+ private startingUrl: string;
71
+ private outFile?: number;
72
+ private errFile?: number;
73
+ private chromePath?: string;
74
+ private chromeFlags: string[];
75
+ private requestedPort?: number;
76
+ private chrome?: childProcess.ChildProcess;
77
+ private fs: typeof fs;
78
+ private rimraf: typeof rimraf;
79
+ private spawn: typeof childProcess.spawn;
80
+
81
+ userDataDir?: string;
82
+ port?: number;
83
+ pid?: number;
84
+
85
+ constructor(private opts: Options = {}, moduleOverrides: ModuleOverrides = {}) {
86
+ this.fs = moduleOverrides.fs || fs;
87
+ this.rimraf = moduleOverrides.rimraf || rimraf;
88
+ this.spawn = moduleOverrides.spawn || spawn;
89
+
90
+ log.setLevel(defaults(this.opts.logLevel, 'info'));
91
+
92
+ // choose the first one (default)
93
+ this.startingUrl = defaults(this.opts.startingUrl, 'about:blank');
94
+ this.chromeFlags = defaults(this.opts.chromeFlags, []);
95
+ this.requestedPort = defaults(this.opts.port, 0);
96
+ this.chromePath = this.opts.chromePath;
97
+ }
98
+
99
+ private get flags() {
100
+ const flags = DEFAULT_FLAGS.concat([
101
+ `--remote-debugging-port=${this.port}`,
102
+ // Place Chrome profile in a custom location we'll rm -rf later
103
+ `--user-data-dir=${this.userDataDir}`
104
+ ]);
105
+
106
+ if (process.platform === 'linux') {
107
+ flags.push('--disable-setuid-sandbox');
108
+ }
109
+
110
+ flags.push(...this.chromeFlags);
111
+ flags.push(this.startingUrl);
112
+
113
+ return flags;
114
+ }
115
+
116
+ // Wrapper function to enable easy testing.
117
+ makeTmpDir() {
118
+ return makeTmpDir();
119
+ }
120
+
121
+ prepare() {
122
+ const platform = process.platform as SupportedPlatforms;
123
+ if (!_SUPPORTED_PLATFORMS.has(platform)) {
124
+ throw new Error(`Platform ${platform} is not supported`);
125
+ }
126
+
127
+ this.userDataDir = this.opts.userDataDir || this.makeTmpDir();
128
+ this.outFile = this.fs.openSync(`${this.userDataDir}/chrome-out.log`, 'a');
129
+ this.errFile = this.fs.openSync(`${this.userDataDir}/chrome-err.log`, 'a');
130
+
131
+ // fix for Node4
132
+ // you can't pass a fd to fs.writeFileSync
133
+ this.pidFile = `${this.userDataDir}/chrome.pid`;
134
+
135
+ log.verbose('ChromeLauncher', `created ${this.userDataDir}`);
136
+
137
+ this.tmpDirandPidFileReady = true;
138
+ }
139
+
140
+ async launch() {
141
+ if (this.requestedPort !== 0) {
142
+ this.port = this.requestedPort;
143
+
144
+ // If an explict port is passed first look for an open connection...
145
+ try {
146
+ return await this.isDebuggerReady();
147
+ } catch (err) {
148
+ log.log(
149
+ 'ChromeLauncher',
150
+ `No debugging port found on port ${this.port}, launching a new Chrome.`);
151
+ }
152
+ }
153
+
154
+ if (!this.tmpDirandPidFileReady) {
155
+ this.prepare();
156
+ }
157
+
158
+ if (this.chromePath === undefined) {
159
+ const installations = await chromeFinder[process.platform as SupportedPlatforms]();
160
+ if (installations.length === 0) {
161
+ throw new Error('No Chrome Installations Found');
162
+ }
163
+
164
+ this.chromePath = installations[0];
165
+ }
166
+
167
+ this.pid = await this.spawnProcess(this.chromePath);
168
+ return Promise.resolve();
169
+ }
170
+
171
+ private async spawnProcess(execPath: string) {
172
+ // Typescript is losing track of the return type without the explict typing.
173
+ const spawnPromise: Promise<number> = new Promise(async (resolve) => {
174
+ if (this.chrome) {
175
+ log.log('ChromeLauncher', `Chrome already running with pid ${this.chrome.pid}.`);
176
+ return resolve(this.chrome.pid);
177
+ }
178
+
179
+
180
+ // If a zero value port is set, it means the launcher
181
+ // is responsible for generating the port number.
182
+ // We do this here so that we can know the port before
183
+ // we pass it into chrome.
184
+ if (this.requestedPort === 0) {
185
+ this.port = await getRandomPort();
186
+ }
187
+
188
+ const chrome = this.spawn(
189
+ execPath, this.flags, {detached: true, stdio: ['ignore', this.outFile, this.errFile]});
190
+ this.chrome = chrome;
191
+
192
+ this.fs.writeFileSync(this.pidFile, chrome.pid.toString());
193
+
194
+ log.verbose('ChromeLauncher', `Chrome running with pid ${chrome.pid} on port ${this.port}.`);
195
+ resolve(chrome.pid);
196
+ });
197
+
198
+ const pid = await spawnPromise;
199
+ await this.waitUntilReady();
200
+ return pid;
201
+ }
202
+
203
+ private cleanup(client?: net.Socket) {
204
+ if (client) {
205
+ client.removeAllListeners();
206
+ client.end();
207
+ client.destroy();
208
+ client.unref();
209
+ }
210
+ }
211
+
212
+ // resolves if ready, rejects otherwise
213
+ private isDebuggerReady(): Promise<{}> {
214
+ return new Promise((resolve, reject) => {
215
+ const client = net.createConnection(this.port!);
216
+ client.once('error', err => {
217
+ this.cleanup(client);
218
+ reject(err);
219
+ });
220
+ client.once('connect', () => {
221
+ this.cleanup(client);
222
+ resolve();
223
+ });
224
+ });
225
+ }
226
+
227
+ // resolves when debugger is ready, rejects after 10 polls
228
+ private waitUntilReady() {
229
+ const launcher = this;
230
+
231
+ return new Promise((resolve, reject) => {
232
+ let retries = 0;
233
+ let waitStatus = 'Waiting for browser.';
234
+
235
+ const poll = () => {
236
+ if (retries === 0) {
237
+ log.log('ChromeLauncher', waitStatus);
238
+ }
239
+ retries++;
240
+ waitStatus += '..';
241
+ log.log('ChromeLauncher', waitStatus);
242
+
243
+ launcher.isDebuggerReady()
244
+ .then(() => {
245
+ log.log('ChromeLauncher', waitStatus + `${log.greenify(log.tick)}`);
246
+ resolve();
247
+ })
248
+ .catch(err => {
249
+ if (retries > 10) {
250
+ log.error('ChromeLauncher', err.message);
251
+ const stderr =
252
+ this.fs.readFileSync(`${this.userDataDir}/chrome-err.log`, {encoding: 'utf-8'});
253
+ log.error(
254
+ 'ChromeLauncher', `Logging contents of ${this.userDataDir}/chrome-err.log`);
255
+ log.error('ChromeLauncher', stderr);
256
+ return reject(err);
257
+ }
258
+ delay(launcher.pollInterval).then(poll);
259
+ });
260
+ };
261
+ poll();
262
+
263
+ });
264
+ }
265
+
266
+ kill() {
267
+ return new Promise(resolve => {
268
+ if (this.chrome) {
269
+ this.chrome.on('close', () => {
270
+ this.destroyTmp().then(resolve);
271
+ });
272
+
273
+ log.log('ChromeLauncher', 'Killing all Chrome Instances');
274
+ try {
275
+ if (isWindows) {
276
+ execSync(`taskkill /pid ${this.chrome.pid} /T /F`);
277
+ } else {
278
+ process.kill(-this.chrome.pid);
279
+ }
280
+ } catch (err) {
281
+ log.warn('ChromeLauncher', `Chrome could not be killed ${err.message}`);
282
+ }
283
+
284
+ delete this.chrome;
285
+ } else {
286
+ // fail silently as we did not start chrome
287
+ resolve();
288
+ }
289
+ });
290
+ }
291
+
292
+ destroyTmp() {
293
+ return new Promise(resolve => {
294
+ // Only clean up the tmp dir if we created it.
295
+ if (this.userDataDir === undefined || this.opts.userDataDir !== undefined) {
296
+ return resolve();
297
+ }
298
+
299
+ if (this.outFile) {
300
+ this.fs.closeSync(this.outFile);
301
+ delete this.outFile;
302
+ }
303
+
304
+ if (this.errFile) {
305
+ this.fs.closeSync(this.errFile);
306
+ delete this.errFile;
307
+ }
308
+
309
+ this.rimraf(this.userDataDir, () => resolve());
310
+ });
311
+ }
312
+ };
@@ -0,0 +1,14 @@
1
+ 'use strict'
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+
6
+ module.exports = function(filename) {
7
+ if (!fs.existsSync(path.join(__dirname, filename))) {
8
+ console.log(
9
+ 'Oops! Looks like the chrome-launcher files needs to be compiled. Please run:');
10
+ console.log(' yarn install-launcher; yarn build-launcher;');
11
+ console.log('More at: https://github.com/GoogleChrome/lighthouse#develop');
12
+ process.exit(1);
13
+ }
14
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @license Copyright 2017 Google Inc. All Rights Reserved.
3
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
4
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
5
+ */
6
+ 'use strict';
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.DEFAULT_FLAGS = [
9
+ // Disable built-in Google Translate service
10
+ '--disable-translate',
11
+ // Disable all chrome extensions entirely
12
+ '--disable-extensions',
13
+ // Disable various background network services, including extension updating,
14
+ // safe browsing service, upgrade detector, translate, UMA
15
+ '--disable-background-networking',
16
+ // Disable fetching safebrowsing lists, likely redundant due to disable-background-networking
17
+ '--safebrowsing-disable-auto-update',
18
+ // Disable syncing to a Google account
19
+ '--disable-sync',
20
+ // Disable reporting to UMA, but allows for collection
21
+ '--metrics-recording-only',
22
+ // Disable installation of default apps on first run
23
+ '--disable-default-apps',
24
+ // Skip first run wizards
25
+ '--no-first-run',
26
+ ];
27
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmxhZ3MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJmbGFncy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7OztHQUlHO0FBQ0gsWUFBWSxDQUFDOztBQUVBLFFBQUEsYUFBYSxHQUFHO0lBQzNCLDRDQUE0QztJQUM1QyxxQkFBcUI7SUFDckIseUNBQXlDO0lBQ3pDLHNCQUFzQjtJQUN0Qiw2RUFBNkU7SUFDN0UsNERBQTREO0lBQzVELGlDQUFpQztJQUNqQyw2RkFBNkY7SUFDN0Ysb0NBQW9DO0lBQ3BDLHNDQUFzQztJQUN0QyxnQkFBZ0I7SUFDaEIsc0RBQXNEO0lBQ3RELDBCQUEwQjtJQUMxQixvREFBb0Q7SUFDcEQsd0JBQXdCO0lBQ3hCLHlCQUF5QjtJQUN6QixnQkFBZ0I7Q0FDakIsQ0FBQyJ9
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @license Copyright 2017 Google Inc. All Rights Reserved.
3
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
4
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
5
+ */
6
+ 'use strict';
7
+
8
+ export const DEFAULT_FLAGS = [
9
+ // Disable built-in Google Translate service
10
+ '--disable-translate',
11
+ // Disable all chrome extensions entirely
12
+ '--disable-extensions',
13
+ // Disable various background network services, including extension updating,
14
+ // safe browsing service, upgrade detector, translate, UMA
15
+ '--disable-background-networking',
16
+ // Disable fetching safebrowsing lists, likely redundant due to disable-background-networking
17
+ '--safebrowsing-disable-auto-update',
18
+ // Disable syncing to a Google account
19
+ '--disable-sync',
20
+ // Disable reporting to UMA, but allows for collection
21
+ '--metrics-recording-only',
22
+ // Disable installation of default apps on first run
23
+ '--disable-default-apps',
24
+ // Skip first run wizards
25
+ '--no-first-run',
26
+ ];
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ function __export(m) {
3
+ for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
4
+ }
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ __export(require("./chrome-launcher"));
7
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJpbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLHVDQUFrQyJ9
@@ -0,0 +1 @@
1
+ export * from './chrome-launcher';
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env node
2
+
3
+ 'use strict'
4
+ /**
5
+ * @fileoverview Script to launch a clean Chrome instance on-demand.
6
+ * Assuming Lighthouse is installed globally or `npm link`ed, use via:
7
+ * chrome-debug
8
+ * Optionally pass additional flags and/or a URL
9
+ * chrome-debug http://goat.com
10
+ * chrome-debug --show-paint-rects
11
+ */
12
+
13
+ require('./compiled-check.js')('chrome-launcher.js');
14
+
15
+ const args = process.argv.slice(2);
16
+
17
+ let chromeFlags;
18
+ let startingUrl;
19
+
20
+ if (args.length) {
21
+ chromeFlags = args.filter(flag => flag.startsWith('--'));
22
+ startingUrl = args.find(flag => !flag.startsWith('--'));
23
+ }
24
+
25
+ const {launch} = require('./chrome-launcher');
26
+
27
+ launch({
28
+ startingUrl,
29
+ chromeFlags,
30
+ }).then(v => console.log(`✨ Chrome debugging port: ${v.port}`))
@@ -0,0 +1,116 @@
1
+ {
2
+ "_args": [
3
+ [
4
+ {
5
+ "raw": "chrome-launcher@^0.3.1",
6
+ "scope": null,
7
+ "escapedName": "chrome-launcher",
8
+ "name": "chrome-launcher",
9
+ "rawSpec": "^0.3.1",
10
+ "spec": ">=0.3.1 <0.4.0",
11
+ "type": "range"
12
+ },
13
+ "/Users/tomascelizna/Devel/dragonfly_chrome_headless/node_modules/html-pdf-chrome"
14
+ ]
15
+ ],
16
+ "_from": "chrome-launcher@>=0.3.1 <0.4.0",
17
+ "_id": "chrome-launcher@0.3.1",
18
+ "_inCache": true,
19
+ "_location": "/chrome-launcher",
20
+ "_nodeVersion": "8.1.2",
21
+ "_npmOperationalInternal": {
22
+ "host": "s3://npm-registry-packages",
23
+ "tmp": "tmp/chrome-launcher-0.3.1.tgz_1499275221569_0.5772193057928234"
24
+ },
25
+ "_npmUser": {
26
+ "name": "paulirish",
27
+ "email": "paul.irish@gmail.com"
28
+ },
29
+ "_npmVersion": "5.0.3",
30
+ "_phantomChildren": {},
31
+ "_requested": {
32
+ "raw": "chrome-launcher@^0.3.1",
33
+ "scope": null,
34
+ "escapedName": "chrome-launcher",
35
+ "name": "chrome-launcher",
36
+ "rawSpec": "^0.3.1",
37
+ "spec": ">=0.3.1 <0.4.0",
38
+ "type": "range"
39
+ },
40
+ "_requiredBy": [
41
+ "/html-pdf-chrome"
42
+ ],
43
+ "_resolved": "https://registry.npmjs.org/chrome-launcher/-/chrome-launcher-0.3.1.tgz",
44
+ "_shasum": "0e9a2904a6f549ba135d20554189028eddd0a22d",
45
+ "_shrinkwrap": null,
46
+ "_spec": "chrome-launcher@^0.3.1",
47
+ "_where": "/Users/tomascelizna/Devel/dragonfly_chrome_headless/node_modules/html-pdf-chrome",
48
+ "author": {
49
+ "name": "The Chromium Authors"
50
+ },
51
+ "dependencies": {
52
+ "@types/core-js": "^0.9.41",
53
+ "@types/mkdirp": "^0.3.29",
54
+ "@types/node": "6.0.66",
55
+ "lighthouse-logger": "^1.0.0",
56
+ "mkdirp": "0.5.1",
57
+ "rimraf": "^2.6.1"
58
+ },
59
+ "description": "Launch latest Chrome with the devtools-protocol port open",
60
+ "devDependencies": {
61
+ "@types/mocha": "^2.2.41",
62
+ "@types/sinon": "^2.3.1",
63
+ "clang-format": "^1.0.50",
64
+ "mocha": "^3.2.0",
65
+ "nyc": "^11.0.2",
66
+ "sinon": "^2.3.5",
67
+ "ts-node": "^3.0.4",
68
+ "typescript": "2.2.1"
69
+ },
70
+ "directories": {},
71
+ "dist": {
72
+ "integrity": "sha512-1NqEo4Cq1u2GitEkrC1bKqfDcU6ZvB/SoS9QRvzG5ptvlA4nmQO9mgVsgrwNcr7GN8iOgJCnNKyLXetPv9mteg==",
73
+ "shasum": "0e9a2904a6f549ba135d20554189028eddd0a22d",
74
+ "tarball": "https://registry.npmjs.org/chrome-launcher/-/chrome-launcher-0.3.1.tgz"
75
+ },
76
+ "license": "Apache-2.0",
77
+ "main": "index.js",
78
+ "maintainers": [
79
+ {
80
+ "name": "brendankenny",
81
+ "email": "bckenny@gmail.com"
82
+ },
83
+ {
84
+ "name": "ebidel",
85
+ "email": "ebidel@gmail.com"
86
+ },
87
+ {
88
+ "name": "patrickhulce",
89
+ "email": "patrick.hulce@gmail.com"
90
+ },
91
+ {
92
+ "name": "paulirish",
93
+ "email": "paul.irish@gmail.com"
94
+ },
95
+ {
96
+ "name": "samccone",
97
+ "email": "sam@samx.it"
98
+ }
99
+ ],
100
+ "name": "chrome-launcher",
101
+ "optionalDependencies": {},
102
+ "readme": "ERROR: No README data found!",
103
+ "repository": {
104
+ "type": "git",
105
+ "url": "https://github.com/GoogleChrome/lighthouse/tree/master/chrome-launcher"
106
+ },
107
+ "scripts": {
108
+ "build": "tsc",
109
+ "coverage": "nyc yarn test && nyc report --reporter=text-lcov > lcov.info",
110
+ "dev": "tsc -w",
111
+ "format": "clang-format -i -style=file **/*.ts *.ts",
112
+ "test": "mocha --require ts-node/register --reporter=dot test/**/*-test.ts --timeout=10000",
113
+ "test-formatting": "test/check-formatting.sh"
114
+ },
115
+ "version": "0.3.1"
116
+ }