grover 1.1.6 → 1.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1de71127ef3e7173bce45deeec104ec9c876dea335ad73dfc80016da64c64f7
4
- data.tar.gz: 50dce7d9aa7ef01e12144f303868667e4d6587d0dc9a7be337c34d9679e483c0
3
+ metadata.gz: 7bfcdc3d84dade94866bbb29eca6c1e91b9459a5f020ebd175341f740dfdd585
4
+ data.tar.gz: 539a10195c08de66249983fccdf3f5314f1adec83b400d6058f87d127e731f86
5
5
  SHA512:
6
- metadata.gz: '084b8e564818202eead00cb7faef9c181e5bd394e41113fb4b87233fa9fe44ed434318240034a375f20799af909a647fc8dd816f9d74aa79ad101efaa329387f'
7
- data.tar.gz: 5f03611f7f945dac5b75424bc879f90e639f4a97430759028f3cf36727c4c490813dc15fc68271767b1996716278484eae0d7383a42741fbd24f2d572124d4e2
6
+ metadata.gz: 6322c7cd633f776d58bb2fcad105d067a3df4782dcbc2fb15aff4fe60dcc2e8e1a58075e4972bb9f65362075eebe973e51f8aa385bd651d89ad41078e00fd4ca
7
+ data.tar.gz: e9431f9a613f4b40f5d836616ad2e8afd6470a606a8daf80ad5553e248a461035228c62e290f0778e742aa2f2a9b663fe23f0590600cdda592cd8a26339ba391
@@ -7,7 +7,7 @@ class Grover
7
7
  class Configuration
8
8
  attr_accessor :options, :meta_tag_prefix, :ignore_path, :ignore_request,
9
9
  :root_url, :use_pdf_middleware, :use_png_middleware,
10
- :use_jpeg_middleware
10
+ :use_jpeg_middleware, :node_env_vars
11
11
 
12
12
  def initialize
13
13
  @options = {}
@@ -18,6 +18,7 @@ class Grover
18
18
  @use_pdf_middleware = true
19
19
  @use_png_middleware = false
20
20
  @use_jpeg_middleware = false
21
+ @node_env_vars = {}
21
22
  end
22
23
  end
23
24
  end
@@ -1,13 +1,25 @@
1
1
  // Setup imports
2
2
  try {
3
3
  const Module = require('module');
4
- // resolve puppeteer from the CWD instead of where this script is located
5
- var puppeteer = require(require.resolve('puppeteer', { paths: Module._nodeModulePaths(process.cwd()) }));
4
+
5
+ try {
6
+ // resolve puppeteer from the CWD instead of where this script is located
7
+ var puppeteer = require(require.resolve('puppeteer', { paths: Module._nodeModulePaths(process.cwd()) }));
8
+ } catch (puppeteerError) {
9
+ try {
10
+ // try resolve `puppeteer-core` library instead
11
+ var puppeteer = require(require.resolve('puppeteer-core', { paths: Module._nodeModulePaths(process.cwd()) }));
12
+ } catch (coreError) {
13
+ // raise the original puppeteer load issue so we don't send people don't the wrong rabbit hole by default.
14
+ throw puppeteerError;
15
+ }
16
+ }
6
17
  } catch (e) {
7
18
  process.stdout.write(JSON.stringify(['err', e.toString()]));
8
19
  process.stdout.write("\n");
9
20
  process.exit(1);
10
21
  }
22
+
11
23
  process.stdout.write("[\"ok\"]\n");
12
24
 
13
25
  const fs = require('fs');
@@ -15,7 +27,7 @@ const os = require('os');
15
27
  const path = require('path');
16
28
 
17
29
  const _processPage = (async (convertAction, urlOrHtml, options) => {
18
- let browser, errors = [], tmpDir;
30
+ let browser, page, errors = [], tmpDir, wsConnection = false;
19
31
 
20
32
  try {
21
33
  // Configure puppeteer debugging options
@@ -25,8 +37,18 @@ const _processPage = (async (convertAction, urlOrHtml, options) => {
25
37
  const connectParams = {
26
38
  browserWSEndpoint: browserWsEndpoint,
27
39
  };
28
-
29
- browser = await puppeteer.connect(connectParams);
40
+ wsConnection = true;
41
+
42
+ try {
43
+ browser = await puppeteer.connect(connectParams);
44
+ } catch {
45
+ function WsConnectFailedError() {
46
+ this.name = "WsConnectFailedError";
47
+ this.message = `Failed to connect to browser WS endpoint: ${browserWsEndpoint}`;
48
+ }
49
+ WsConnectFailedError.prototype = Error.prototype;
50
+ throw new WsConnectFailedError();
51
+ }
30
52
  } else {
31
53
  tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'grover-'));
32
54
 
@@ -34,29 +56,29 @@ const _processPage = (async (convertAction, urlOrHtml, options) => {
34
56
  args: process.env.GROVER_NO_SANDBOX === 'true' ? ['--no-sandbox', '--disable-setuid-sandbox'] : [],
35
57
  userDataDir: tmpDir
36
58
  };
37
-
59
+
38
60
  if (typeof debug === 'object' && !!debug) {
39
61
  if (debug.headless !== undefined) { launchParams.headless = debug.headless; }
40
62
  if (debug.devtools !== undefined) { launchParams.devtools = debug.devtools; }
41
63
  }
42
-
64
+
43
65
  // Configure additional launch arguments
44
66
  const args = options.launchArgs; delete options.launchArgs;
45
67
  if (Array.isArray(args)) {
46
68
  launchParams.args = launchParams.args.concat(args);
47
69
  }
48
-
70
+
49
71
  // Set executable path if given
50
72
  const executablePath = options.executablePath; delete options.executablePath;
51
73
  if (executablePath) {
52
74
  launchParams.executablePath = executablePath;
53
75
  }
54
-
76
+
55
77
  // Launch the browser and create a page
56
78
  browser = await puppeteer.launch(launchParams);
57
79
  }
58
80
 
59
- const page = await browser.newPage();
81
+ page = await browser.newPage();
60
82
 
61
83
  // Basic auth
62
84
  const username = options.username; delete options.username
@@ -78,6 +100,7 @@ const _processPage = (async (convertAction, urlOrHtml, options) => {
78
100
  }
79
101
 
80
102
  // Setup timeout option (if provided)
103
+ if (options.timeout === null) delete options.timeout;
81
104
  let requestOptions = {};
82
105
  let requestTimeout = options.requestTimeout; delete options.requestTimeout;
83
106
  if (requestTimeout === undefined) requestTimeout = options.timeout;
@@ -261,7 +284,12 @@ const _processPage = (async (convertAction, urlOrHtml, options) => {
261
284
  }
262
285
  } finally {
263
286
  if (browser) {
264
- await browser.close();
287
+ if (wsConnection) {
288
+ if (page) await page.close();
289
+ await browser.disconnect();
290
+ } else {
291
+ await browser.close();
292
+ }
265
293
  }
266
294
 
267
295
  try {
@@ -32,6 +32,7 @@ class Grover
32
32
 
33
33
  def spawn_process
34
34
  @stdin, @stdout, @stderr, @wait_thr = Open3.popen3(
35
+ Grover.configuration.node_env_vars,
35
36
  'node',
36
37
  File.expand_path(File.join(__dir__, 'js/processor.cjs')),
37
38
  chdir: app_root
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Grover
4
- VERSION = '1.1.6'
4
+ VERSION = '1.1.8'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grover
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Bromwich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-15 00:00:00.000000000 Z
11
+ date: 2024-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: combine_pdf
@@ -38,180 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.0'
41
- - !ruby/object:Gem::Dependency
42
- name: childprocess
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: mini_magick
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '4.12'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '4.12'
69
- - !ruby/object:Gem::Dependency
70
- name: pdf-reader
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '2.11'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '2.11'
83
- - !ruby/object:Gem::Dependency
84
- name: puma
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '6.4'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '6.4'
97
- - !ruby/object:Gem::Dependency
98
- name: rack-test
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '1.1'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '1.1'
111
- - !ruby/object:Gem::Dependency
112
- name: rake
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: '13.0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: '13.0'
125
- - !ruby/object:Gem::Dependency
126
- name: rspec
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: '3.12'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: '3.12'
139
- - !ruby/object:Gem::Dependency
140
- name: rubocop
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - "~>"
144
- - !ruby/object:Gem::Version
145
- version: '1.43'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - "~>"
151
- - !ruby/object:Gem::Version
152
- version: '1.43'
153
- - !ruby/object:Gem::Dependency
154
- name: rubocop-rake
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - "~>"
158
- - !ruby/object:Gem::Version
159
- version: '0.6'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - "~>"
165
- - !ruby/object:Gem::Version
166
- version: '0.6'
167
- - !ruby/object:Gem::Dependency
168
- name: rubocop-rspec
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - "~>"
172
- - !ruby/object:Gem::Version
173
- version: '2.18'
174
- type: :development
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - "~>"
179
- - !ruby/object:Gem::Version
180
- version: '2.18'
181
- - !ruby/object:Gem::Dependency
182
- name: sinatra
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - "~>"
186
- - !ruby/object:Gem::Version
187
- version: '3.2'
188
- type: :development
189
- prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - "~>"
193
- - !ruby/object:Gem::Version
194
- version: '3.2'
195
- - !ruby/object:Gem::Dependency
196
- name: simplecov
197
- requirement: !ruby/object:Gem::Requirement
198
- requirements:
199
- - - "~>"
200
- - !ruby/object:Gem::Version
201
- version: '0.17'
202
- - - "<"
203
- - !ruby/object:Gem::Version
204
- version: '0.18'
205
- type: :development
206
- prerelease: false
207
- version_requirements: !ruby/object:Gem::Requirement
208
- requirements:
209
- - - "~>"
210
- - !ruby/object:Gem::Version
211
- version: '0.17'
212
- - - "<"
213
- - !ruby/object:Gem::Version
214
- version: '0.18'
215
41
  description: Transform HTML into PDF/PNG/JPEG using Google Puppeteer/Chromium
216
42
  email:
217
43
  - abromwich@studiosity.com