grover 1.0.0 → 1.0.4
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.
- checksums.yaml +4 -4
- data/lib/grover/js/processor.js +46 -6
- data/lib/grover/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49f70f988f01666e9141fc0ad9584468d3efb06e6a82042460b3d403b94966e3
|
4
|
+
data.tar.gz: 3a87cb41b36398d56f48930da0df266cc87435d85aa41c520de0759175793131
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a24f664083b90c1e5666c6800a7b8ed8fce43c27c91763c1f2c5ffac797d8c29c77fe37489186ea1567ef0667da88d85d8519fefea31b2bd4ae583af4832d1cb
|
7
|
+
data.tar.gz: 9a90bd6c19b5f09e1a90b9b998df5a7446e87915abe326e94ae4e75ddefa5bd592460dbad406e25dbc2c6714899ea77122ceea938cc294e46f447fcbc64cafa0
|
data/lib/grover/js/processor.js
CHANGED
@@ -11,7 +11,7 @@ try {
|
|
11
11
|
process.stdout.write("[\"ok\"]\n");
|
12
12
|
|
13
13
|
const _processPage = (async (convertAction, urlOrHtml, options) => {
|
14
|
-
let browser;
|
14
|
+
let browser, errors = [];
|
15
15
|
try {
|
16
16
|
const launchParams = {
|
17
17
|
args: process.env.GROVER_NO_SANDBOX === 'true' ? ['--no-sandbox', '--disable-setuid-sandbox'] : []
|
@@ -124,6 +124,18 @@ const _processPage = (async (convertAction, urlOrHtml, options) => {
|
|
124
124
|
page.setGeolocation(geolocation);
|
125
125
|
}
|
126
126
|
|
127
|
+
const raiseOnRequestFailure = options.raiseOnRequestFailure; delete options.raiseOnRequestFailure;
|
128
|
+
if (raiseOnRequestFailure) {
|
129
|
+
page.on('requestfinished', (request) => {
|
130
|
+
if (request.response() && !(request.response().ok() || request.response().status() == 304) && !request.redirectChain().length > 0) {
|
131
|
+
errors.push(request);
|
132
|
+
}
|
133
|
+
});
|
134
|
+
page.on('requestfailed', (request) => {
|
135
|
+
errors.push(request);
|
136
|
+
});
|
137
|
+
}
|
138
|
+
|
127
139
|
const waitUntil = options.waitUntil; delete options.waitUntil;
|
128
140
|
if (urlOrHtml.match(/^http/i)) {
|
129
141
|
// Request is for a URL, so request it
|
@@ -133,11 +145,15 @@ const _processPage = (async (convertAction, urlOrHtml, options) => {
|
|
133
145
|
// Request is some HTML content. Use request interception to assign the body
|
134
146
|
requestOptions.waitUntil = waitUntil || 'networkidle0';
|
135
147
|
await page.setRequestInterception(true);
|
136
|
-
|
137
|
-
|
138
|
-
//
|
139
|
-
|
140
|
-
|
148
|
+
let htmlIntercepted = false;
|
149
|
+
page.on('request', request => {
|
150
|
+
// We only want to intercept the first request - ie our HTML
|
151
|
+
if (htmlIntercepted)
|
152
|
+
request.continue();
|
153
|
+
else {
|
154
|
+
htmlIntercepted = true
|
155
|
+
request.respond({ body: urlOrHtml === '' ? ' ' : urlOrHtml });
|
156
|
+
}
|
141
157
|
});
|
142
158
|
const displayUrl = options.displayUrl; delete options.displayUrl;
|
143
159
|
await page.goto(displayUrl || 'http://example.com', requestOptions);
|
@@ -172,6 +188,13 @@ const _processPage = (async (convertAction, urlOrHtml, options) => {
|
|
172
188
|
await page.waitForSelector(waitForSelector, waitForSelectorOptions);
|
173
189
|
}
|
174
190
|
|
191
|
+
// If specified, wait for function
|
192
|
+
const waitForFunction = options.waitForFunction; delete options.waitForFunction;
|
193
|
+
const waitForFunctionOptions = options.waitForFunctionOptions; delete options.waitForFunctionOptions;
|
194
|
+
if (waitForFunction !== undefined) {
|
195
|
+
await page.waitForFunction(waitForFunction, waitForFunctionOptions);
|
196
|
+
}
|
197
|
+
|
175
198
|
// If specified, wait for timeout
|
176
199
|
const waitForTimeout = options.waitForTimeout; delete options.waitForTimeout;
|
177
200
|
if (waitForTimeout !== undefined) {
|
@@ -190,6 +213,23 @@ const _processPage = (async (convertAction, urlOrHtml, options) => {
|
|
190
213
|
await page.hover(hoverSelector);
|
191
214
|
}
|
192
215
|
|
216
|
+
if (errors.length > 0) {
|
217
|
+
function RequestFailedError(errors) {
|
218
|
+
this.name = "RequestFailedError";
|
219
|
+
this.message = errors.map(e => {
|
220
|
+
if (e.failure()) {
|
221
|
+
return e.failure().errorText + " at " + e.url();
|
222
|
+
} else if (e.response() && e.response().status()) {
|
223
|
+
return e.response().status() + " " + e.url();
|
224
|
+
} else {
|
225
|
+
return "UnknownError " + e.url()
|
226
|
+
}
|
227
|
+
}).join("\n");
|
228
|
+
}
|
229
|
+
RequestFailedError.prototype = Error.prototype;
|
230
|
+
throw new RequestFailedError(errors);
|
231
|
+
}
|
232
|
+
|
193
233
|
// If we're running puppeteer in headless mode, return the converted PDF
|
194
234
|
if (debug === undefined || (typeof debug === 'object' && (debug.headless === undefined || debug.headless))) {
|
195
235
|
return await page[convertAction](options);
|
data/lib/grover/version.rb
CHANGED
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.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Bromwich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: combine_pdf
|