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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec752a494049fb8bfeeb78aec6a5a553f3c6502e869163492556d2bf386b7340
4
- data.tar.gz: 8886bbe696f7f6b8510e8cf209c334c67540e560741162e503fb2505da18cc8c
3
+ metadata.gz: 49f70f988f01666e9141fc0ad9584468d3efb06e6a82042460b3d403b94966e3
4
+ data.tar.gz: 3a87cb41b36398d56f48930da0df266cc87435d85aa41c520de0759175793131
5
5
  SHA512:
6
- metadata.gz: 1f0e2c7d80edc1a037b863ecc14cc117671d030602d1ff243114efd81ccae8e3dbbf31bc98a61b3f63158c68eb87097aaa7feb86215eaff007e336defe9efd5e
7
- data.tar.gz: 97aa4ad8721ea2f689af1cb9cbcbeb429c663f35942ebcfcd5007c6e51df66def829965dac16a4a0ec002d93885c8a88a2515784abb024fb097edac922cbcea8
6
+ metadata.gz: a24f664083b90c1e5666c6800a7b8ed8fce43c27c91763c1f2c5ffac797d8c29c77fe37489186ea1567ef0667da88d85d8519fefea31b2bd4ae583af4832d1cb
7
+ data.tar.gz: 9a90bd6c19b5f09e1a90b9b998df5a7446e87915abe326e94ae4e75ddefa5bd592460dbad406e25dbc2c6714899ea77122ceea938cc294e46f447fcbc64cafa0
@@ -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
- page.once('request', request => {
137
- request.respond({ body: urlOrHtml === '' ? ' ' : urlOrHtml });
138
- // Reset the request interception
139
- // (we only want to intercept the first request - ie our HTML)
140
- page.on('request', request => request.continue());
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);
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Grover
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.4'
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.0.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-03-01 00:00:00.000000000 Z
11
+ date: 2021-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: combine_pdf