grover 0.14.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/grover.rb +1 -1
- data/lib/grover/js/processor.js +71 -11
- data/lib/grover/options_fixer.rb +3 -2
- data/lib/grover/utils.rb +8 -5
- 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: ec752a494049fb8bfeeb78aec6a5a553f3c6502e869163492556d2bf386b7340
|
4
|
+
data.tar.gz: 8886bbe696f7f6b8510e8cf209c334c67540e560741162e503fb2505da18cc8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f0e2c7d80edc1a037b863ecc14cc117671d030602d1ff243114efd81ccae8e3dbbf31bc98a61b3f63158c68eb87097aaa7feb86215eaff007e336defe9efd5e
|
7
|
+
data.tar.gz: 97aa4ad8721ea2f689af1cb9cbcbeb429c663f35942ebcfcd5007c6e51df66def829965dac16a4a0ec002d93885c8a88a2515784abb024fb097edac922cbcea8
|
data/lib/grover.rb
CHANGED
@@ -144,7 +144,7 @@ class Grover
|
|
144
144
|
end
|
145
145
|
|
146
146
|
def normalized_options(path:)
|
147
|
-
normalized_options = Utils.normalize_object @options
|
147
|
+
normalized_options = Utils.normalize_object @options, excluding: ['extraHTTPHeaders']
|
148
148
|
normalized_options['path'] = path if path.is_a? ::String
|
149
149
|
normalized_options
|
150
150
|
end
|
data/lib/grover/js/processor.js
CHANGED
@@ -66,12 +66,64 @@ const _processPage = (async (convertAction, urlOrHtml, options) => {
|
|
66
66
|
requestOptions.timeout = timeout;
|
67
67
|
}
|
68
68
|
|
69
|
+
// Setup user agent (if provided)
|
70
|
+
const userAgent = options.userAgent; delete options.userAgent;
|
71
|
+
if (userAgent !== undefined) {
|
72
|
+
await page.setUserAgent(userAgent);
|
73
|
+
}
|
74
|
+
|
69
75
|
// Setup viewport options (if provided)
|
70
76
|
const viewport = options.viewport; delete options.viewport;
|
71
77
|
if (viewport !== undefined) {
|
72
78
|
await page.setViewport(viewport);
|
73
79
|
}
|
74
80
|
|
81
|
+
// If specified, emulate the media type
|
82
|
+
const emulateMedia = options.emulateMedia; delete options.emulateMedia;
|
83
|
+
if (emulateMedia !== undefined) {
|
84
|
+
if (typeof page.emulateMediaType === 'function') {
|
85
|
+
await page.emulateMediaType(emulateMedia);
|
86
|
+
} else {
|
87
|
+
await page.emulateMedia(emulateMedia);
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
// Emulate the media features, if specified
|
92
|
+
const mediaFeatures = options.mediaFeatures; delete options.mediaFeatures;
|
93
|
+
if (Array.isArray(mediaFeatures)) {
|
94
|
+
page.emulateMediaFeatures(mediaFeatures);
|
95
|
+
}
|
96
|
+
|
97
|
+
// Emulate timezone (if provided)
|
98
|
+
const timezone = options.timezone; delete options.timezone;
|
99
|
+
if (timezone !== undefined) {
|
100
|
+
await page.emulateTimezone(timezone);
|
101
|
+
}
|
102
|
+
|
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
|
+
// Bypass CSP (content security policy), if provided
|
110
|
+
const bypassCSP = options.bypassCSP; delete options.bypassCSP;
|
111
|
+
if (bypassCSP !== undefined) {
|
112
|
+
page.setBypassCSP(bypassCSP);
|
113
|
+
}
|
114
|
+
|
115
|
+
// Add extra HTTP headers (if provided)
|
116
|
+
const extraHTTPHeaders = options.extraHTTPHeaders; delete options.extraHTTPHeaders;
|
117
|
+
if (extraHTTPHeaders !== undefined) {
|
118
|
+
page.setExtraHTTPHeaders(extraHTTPHeaders);
|
119
|
+
}
|
120
|
+
|
121
|
+
// Set geolocation (if provided)
|
122
|
+
const geolocation = options.geolocation; delete options.geolocation;
|
123
|
+
if (geolocation !== undefined) {
|
124
|
+
page.setGeolocation(geolocation);
|
125
|
+
}
|
126
|
+
|
75
127
|
const waitUntil = options.waitUntil; delete options.waitUntil;
|
76
128
|
if (urlOrHtml.match(/^http/i)) {
|
77
129
|
// Request is for a URL, so request it
|
@@ -91,16 +143,6 @@ const _processPage = (async (convertAction, urlOrHtml, options) => {
|
|
91
143
|
await page.goto(displayUrl || 'http://example.com', requestOptions);
|
92
144
|
}
|
93
145
|
|
94
|
-
// If specified, emulate the media type
|
95
|
-
const emulateMedia = options.emulateMedia; delete options.emulateMedia;
|
96
|
-
if (emulateMedia !== undefined) {
|
97
|
-
if (typeof page.emulateMediaType == 'function') {
|
98
|
-
await page.emulateMediaType(emulateMedia);
|
99
|
-
} else {
|
100
|
-
await page.emulateMedia(emulateMedia);
|
101
|
-
}
|
102
|
-
}
|
103
|
-
|
104
146
|
// add styles (if provided)
|
105
147
|
const styleTagOptions = options.styleTagOptions; delete options.styleTagOptions;
|
106
148
|
if (Array.isArray(styleTagOptions)) {
|
@@ -127,7 +169,25 @@ const _processPage = (async (convertAction, urlOrHtml, options) => {
|
|
127
169
|
const waitForSelector = options.waitForSelector; delete options.waitForSelector;
|
128
170
|
const waitForSelectorOptions = options.waitForSelectorOptions; delete options.waitForSelectorOptions;
|
129
171
|
if (waitForSelector !== undefined) {
|
130
|
-
await page.waitForSelector(waitForSelector, waitForSelectorOptions)
|
172
|
+
await page.waitForSelector(waitForSelector, waitForSelectorOptions);
|
173
|
+
}
|
174
|
+
|
175
|
+
// If specified, wait for timeout
|
176
|
+
const waitForTimeout = options.waitForTimeout; delete options.waitForTimeout;
|
177
|
+
if (waitForTimeout !== undefined) {
|
178
|
+
await page.waitForTimeout(waitForTimeout);
|
179
|
+
}
|
180
|
+
|
181
|
+
// If specified, focus on the specified selector
|
182
|
+
const focusSelector = options.focus; delete options.focus;
|
183
|
+
if (focusSelector !== undefined) {
|
184
|
+
await page.focus(focusSelector);
|
185
|
+
}
|
186
|
+
|
187
|
+
// If specified, hover on the specified selector
|
188
|
+
const hoverSelector = options.hover; delete options.hover;
|
189
|
+
if (hoverSelector !== undefined) {
|
190
|
+
await page.hover(hoverSelector);
|
131
191
|
}
|
132
192
|
|
133
193
|
// If we're running puppeteer in headless mode, return the converted PDF
|
data/lib/grover/options_fixer.rb
CHANGED
@@ -34,13 +34,13 @@ class Grover
|
|
34
34
|
def fix_boolean_options!
|
35
35
|
fix_options!(
|
36
36
|
'display_header_footer', 'full_page', 'landscape', 'omit_background', 'prefer_css_page_size',
|
37
|
-
'print_background', 'viewport.has_touch', 'viewport.is_landscape', 'viewport.is_mobile'
|
37
|
+
'print_background', 'viewport.has_touch', 'viewport.is_landscape', 'viewport.is_mobile', 'bypass_csp'
|
38
38
|
) { |value| !FALSE_VALUES.include?(value) }
|
39
39
|
end
|
40
40
|
|
41
41
|
def fix_integer_options!
|
42
42
|
fix_options!(
|
43
|
-
'viewport.height', 'viewport.width',
|
43
|
+
'viewport.height', 'viewport.width', 'wait_for_timeout',
|
44
44
|
&:to_i
|
45
45
|
)
|
46
46
|
end
|
@@ -48,6 +48,7 @@ class Grover
|
|
48
48
|
def fix_float_options!
|
49
49
|
fix_options!(
|
50
50
|
'clip.height', 'clip.width', 'clip.x', 'clip.y', 'quality', 'scale', 'viewport.device_scale_factor',
|
51
|
+
'geolocation.latitude', 'geolocation.longitude',
|
51
52
|
&:to_f
|
52
53
|
)
|
53
54
|
end
|
data/lib/grover/utils.rb
CHANGED
@@ -6,7 +6,9 @@ class Grover
|
|
6
6
|
#
|
7
7
|
class Utils
|
8
8
|
ACRONYMS = {
|
9
|
-
'css' => 'CSS'
|
9
|
+
'css' => 'CSS',
|
10
|
+
'csp' => 'CSP',
|
11
|
+
'http' => 'HTTP'
|
10
12
|
}.freeze
|
11
13
|
private_constant :ACRONYMS
|
12
14
|
|
@@ -41,11 +43,12 @@ class Grover
|
|
41
43
|
# Copied from active support
|
42
44
|
# @see active_support/core_ext/hash/keys.rb
|
43
45
|
#
|
44
|
-
def self.deep_transform_keys_in_object(object, &block)
|
46
|
+
def self.deep_transform_keys_in_object(object, excluding: [], &block) # rubocop:disable Metrics/MethodLength
|
45
47
|
case object
|
46
48
|
when Hash
|
47
49
|
object.each_with_object({}) do |(key, value), result|
|
48
|
-
|
50
|
+
new_key = yield(key)
|
51
|
+
result[new_key] = excluding.include?(new_key) ? value : deep_transform_keys_in_object(value, &block)
|
49
52
|
end
|
50
53
|
when Array
|
51
54
|
object.map { |e| deep_transform_keys_in_object(e, &block) }
|
@@ -80,8 +83,8 @@ class Grover
|
|
80
83
|
#
|
81
84
|
# Recursively normalizes hash objects with camelized string keys
|
82
85
|
#
|
83
|
-
def self.normalize_object(object)
|
84
|
-
deep_transform_keys_in_object(object) { |k| normalize_key(k) }
|
86
|
+
def self.normalize_object(object, excluding: [])
|
87
|
+
deep_transform_keys_in_object(object, excluding: excluding) { |k| normalize_key(k) }
|
85
88
|
end
|
86
89
|
|
87
90
|
#
|
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: 0.
|
4
|
+
version: 1.0.0
|
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-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: combine_pdf
|