grover 1.0.4 → 1.1.1

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: 49f70f988f01666e9141fc0ad9584468d3efb06e6a82042460b3d403b94966e3
4
- data.tar.gz: 3a87cb41b36398d56f48930da0df266cc87435d85aa41c520de0759175793131
3
+ metadata.gz: 5ed292a1f0bbc16c0df46a6f55a2fc93e7eac292add527b5cccdac16cadb7d6a
4
+ data.tar.gz: c9845b8d717409406b62ffa4f73e6e639617d9006f7dfdfec349c123515e11c8
5
5
  SHA512:
6
- metadata.gz: a24f664083b90c1e5666c6800a7b8ed8fce43c27c91763c1f2c5ffac797d8c29c77fe37489186ea1567ef0667da88d85d8519fefea31b2bd4ae583af4832d1cb
7
- data.tar.gz: 9a90bd6c19b5f09e1a90b9b998df5a7446e87915abe326e94ae4e75ddefa5bd592460dbad406e25dbc2c6714899ea77122ceea938cc294e46f447fcbc64cafa0
6
+ metadata.gz: 1c2c17127f2cada74be6759f08d8c38969c2c4268ba0e0c5f05170b6105360fd55e4bfb94921085a6b9335c897a7d4e37c7647e1cf5e4c5a2f71a030b0dd5cc7
7
+ data.tar.gz: 160da07aceb8a1d277d0ea0099b3243b02dd72d1dba8cd3b22d53a6cc7bdec006c7a9430c913d9121069f516b3838d82c3099624cb22526b647fc5001f74a651
@@ -5,13 +5,15 @@ class Grover
5
5
  # Configuration of the options for Grover HTML to PDF conversion
6
6
  #
7
7
  class Configuration
8
- attr_accessor :options, :meta_tag_prefix, :ignore_path, :root_url,
9
- :use_pdf_middleware, :use_png_middleware, :use_jpeg_middleware
8
+ attr_accessor :options, :meta_tag_prefix, :ignore_path, :ignore_request,
9
+ :root_url, :use_pdf_middleware, :use_png_middleware,
10
+ :use_jpeg_middleware
10
11
 
11
12
  def initialize
12
13
  @options = {}
13
14
  @meta_tag_prefix = 'grover-'
14
15
  @ignore_path = nil
16
+ @ignore_request = nil
15
17
  @root_url = nil
16
18
  @use_pdf_middleware = true
17
19
  @use_png_middleware = false
@@ -61,9 +61,10 @@ const _processPage = (async (convertAction, urlOrHtml, options) => {
61
61
 
62
62
  // Setup timeout option (if provided)
63
63
  let requestOptions = {};
64
- const timeout = options.timeout; delete options.timeout;
65
- if (timeout !== undefined) {
66
- requestOptions.timeout = timeout;
64
+ let requestTimeout = options.requestTimeout; delete options.requestTimeout;
65
+ if (requestTimeout === undefined) requestTimeout = options.timeout;
66
+ if (requestTimeout !== undefined) {
67
+ requestOptions.timeout = requestTimeout;
67
68
  }
68
69
 
69
70
  // Setup user agent (if provided)
@@ -91,7 +92,7 @@ const _processPage = (async (convertAction, urlOrHtml, options) => {
91
92
  // Emulate the media features, if specified
92
93
  const mediaFeatures = options.mediaFeatures; delete options.mediaFeatures;
93
94
  if (Array.isArray(mediaFeatures)) {
94
- page.emulateMediaFeatures(mediaFeatures);
95
+ await page.emulateMediaFeatures(mediaFeatures);
95
96
  }
96
97
 
97
98
  // Emulate timezone (if provided)
@@ -100,34 +101,28 @@ const _processPage = (async (convertAction, urlOrHtml, options) => {
100
101
  await page.emulateTimezone(timezone);
101
102
  }
102
103
 
103
- // Emulate vision deficiency (if provided)
104
- const visionDeficiency = options.visionDeficiency; delete options.visionDeficiency;
105
- if (visionDeficiency !== undefined) {
106
- page.emulateVisionDeficiency(type);
107
- }
108
-
109
104
  // Bypass CSP (content security policy), if provided
110
105
  const bypassCSP = options.bypassCSP; delete options.bypassCSP;
111
106
  if (bypassCSP !== undefined) {
112
- page.setBypassCSP(bypassCSP);
107
+ await page.setBypassCSP(bypassCSP);
113
108
  }
114
109
 
115
110
  // Add extra HTTP headers (if provided)
116
111
  const extraHTTPHeaders = options.extraHTTPHeaders; delete options.extraHTTPHeaders;
117
112
  if (extraHTTPHeaders !== undefined) {
118
- page.setExtraHTTPHeaders(extraHTTPHeaders);
113
+ await page.setExtraHTTPHeaders(extraHTTPHeaders);
119
114
  }
120
115
 
121
116
  // Set geolocation (if provided)
122
117
  const geolocation = options.geolocation; delete options.geolocation;
123
118
  if (geolocation !== undefined) {
124
- page.setGeolocation(geolocation);
119
+ await page.setGeolocation(geolocation);
125
120
  }
126
121
 
127
122
  const raiseOnRequestFailure = options.raiseOnRequestFailure; delete options.raiseOnRequestFailure;
128
123
  if (raiseOnRequestFailure) {
129
124
  page.on('requestfinished', (request) => {
130
- if (request.response() && !(request.response().ok() || request.response().status() == 304) && !request.redirectChain().length > 0) {
125
+ if (request.response() && !(request.response().ok() || request.response().status() === 304) && !request.redirectChain().length > 0) {
131
126
  errors.push(request);
132
127
  }
133
128
  });
@@ -201,6 +196,12 @@ const _processPage = (async (convertAction, urlOrHtml, options) => {
201
196
  await page.waitForTimeout(waitForTimeout);
202
197
  }
203
198
 
199
+ // Emulate vision deficiency (if provided)
200
+ const visionDeficiency = options.visionDeficiency; delete options.visionDeficiency;
201
+ if (visionDeficiency !== undefined) {
202
+ await page.emulateVisionDeficiency(visionDeficiency);
203
+ }
204
+
204
205
  // If specified, focus on the specified selector
205
206
  const focusSelector = options.focus; delete options.focus;
206
207
  if (focusSelector !== undefined) {
@@ -230,6 +231,12 @@ const _processPage = (async (convertAction, urlOrHtml, options) => {
230
231
  throw new RequestFailedError(errors);
231
232
  }
232
233
 
234
+ // Setup conversion timeout
235
+ if (options.convertTimeout !== undefined) {
236
+ options.timeout = options.convertTimeout;
237
+ delete options.convertTimeout;
238
+ }
239
+
233
240
  // If we're running puppeteer in headless mode, return the converted PDF
234
241
  if (debug === undefined || (typeof debug === 'object' && (debug.headless === undefined || debug.headless))) {
235
242
  return await page[convertAction](options);
@@ -56,10 +56,10 @@ class Grover
56
56
  end
57
57
 
58
58
  def grover_request?
59
- (pdf_request || png_request || jpeg_request) && !ignore_request?
59
+ (pdf_request || png_request || jpeg_request) && !ignore_path? && !ignore_request?
60
60
  end
61
61
 
62
- def ignore_request?
62
+ def ignore_path?
63
63
  ignore_path = Grover.configuration.ignore_path
64
64
  case ignore_path
65
65
  when String then @request.path.start_with? ignore_path
@@ -68,6 +68,13 @@ class Grover
68
68
  end
69
69
  end
70
70
 
71
+ def ignore_request?
72
+ ignore_request = Grover.configuration.ignore_request
73
+ return unless ignore_request.is_a?(Proc)
74
+
75
+ ignore_request.call @request
76
+ end
77
+
71
78
  def html_content?(headers)
72
79
  headers['Content-Type'] =~ %r{text/html|application/xhtml\+xml}
73
80
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Grover
4
- VERSION = '1.0.4'
4
+ VERSION = '1.1.1'
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.4
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Bromwich
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-27 00:00:00.000000000 Z
11
+ date: 2022-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: combine_pdf
@@ -181,7 +181,7 @@ homepage: https://github.com/Studiosity/grover
181
181
  licenses:
182
182
  - MIT
183
183
  metadata: {}
184
- post_install_message:
184
+ post_install_message:
185
185
  rdoc_options: []
186
186
  require_paths:
187
187
  - lib
@@ -189,18 +189,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
189
189
  requirements:
190
190
  - - ">="
191
191
  - !ruby/object:Gem::Version
192
- version: 2.5.0
192
+ version: 2.6.0
193
193
  - - "<"
194
194
  - !ruby/object:Gem::Version
195
- version: 3.1.0
195
+ version: 3.2.0
196
196
  required_rubygems_version: !ruby/object:Gem::Requirement
197
197
  requirements:
198
198
  - - ">="
199
199
  - !ruby/object:Gem::Version
200
200
  version: '0'
201
201
  requirements: []
202
- rubygems_version: 3.0.6
203
- signing_key:
202
+ rubygems_version: 3.0.9
203
+ signing_key:
204
204
  specification_version: 4
205
205
  summary: A Ruby gem to transform HTML into PDF, PNG or JPEG by wrapping the NodeJS
206
206
  Google Puppeteer driver for Chromium