grover 1.0.4 → 1.1.1
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/configuration.rb +4 -2
- data/lib/grover/js/processor.js +21 -14
- data/lib/grover/middleware.rb +9 -2
- data/lib/grover/version.rb +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5ed292a1f0bbc16c0df46a6f55a2fc93e7eac292add527b5cccdac16cadb7d6a
|
4
|
+
data.tar.gz: c9845b8d717409406b62ffa4f73e6e639617d9006f7dfdfec349c123515e11c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c2c17127f2cada74be6759f08d8c38969c2c4268ba0e0c5f05170b6105360fd55e4bfb94921085a6b9335c897a7d4e37c7647e1cf5e4c5a2f71a030b0dd5cc7
|
7
|
+
data.tar.gz: 160da07aceb8a1d277d0ea0099b3243b02dd72d1dba8cd3b22d53a6cc7bdec006c7a9430c913d9121069f516b3838d82c3099624cb22526b647fc5001f74a651
|
data/lib/grover/configuration.rb
CHANGED
@@ -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, :
|
9
|
-
:use_pdf_middleware, :use_png_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
|
data/lib/grover/js/processor.js
CHANGED
@@ -61,9 +61,10 @@ const _processPage = (async (convertAction, urlOrHtml, options) => {
|
|
61
61
|
|
62
62
|
// Setup timeout option (if provided)
|
63
63
|
let requestOptions = {};
|
64
|
-
|
65
|
-
if (
|
66
|
-
|
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()
|
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);
|
data/lib/grover/middleware.rb
CHANGED
@@ -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
|
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
|
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.
|
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:
|
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.
|
192
|
+
version: 2.6.0
|
193
193
|
- - "<"
|
194
194
|
- !ruby/object:Gem::Version
|
195
|
-
version: 3.
|
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.
|
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
|