grover 1.0.2 → 1.0.6

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: afca67d672e63071ee66a65dc2d2a65e728eb06715b2c59b43cf44dce587ab1c
4
- data.tar.gz: 50313e3201d5f1bbbf8e6d9c92147c3ddc373fbdd51145ee3315a616b69b303c
3
+ metadata.gz: b29220f00e289b012a01c83e1ac3a4d7fe70b034589760f3aea045069127e453
4
+ data.tar.gz: f90bcb0e42bab405df3d296d4f70221684652d2e523970b9018b3a38737f8694
5
5
  SHA512:
6
- metadata.gz: f8aa164f8b52ef008c70fe7ff4918194859db0be10cee102556cc67d49fe9cf5035ee181f9dac64dce87dfa7b7295effe090b851504dd9774e33a23ecab7e15e
7
- data.tar.gz: cd5b46accc2bbbdc5f3d149d62099c4d47c36744aa877876966680e687bfa0fc69f9ad6045c0a4b9a1e3f135c90279ffd595d526f373daddda02a5fb42db754d
6
+ metadata.gz: 2415a80b468c7bbe454cf622fbae3b2cef2b7450577f92845e30fbef54d602a3f46dbf4594258053f07badc847c7ab1f3ac53c72f04a385d993b85e054295448
7
+ data.tar.gz: a928a1f0bc91ba18b7059fd60e44d2348d6727e4cd7d37fbc47e13cf56b1a5e9fa04d6136189a1a3e1a673ab3a86572d5ef58e7e2ca54cc797ab355327c2db37
@@ -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
@@ -91,7 +91,7 @@ const _processPage = (async (convertAction, urlOrHtml, options) => {
91
91
  // Emulate the media features, if specified
92
92
  const mediaFeatures = options.mediaFeatures; delete options.mediaFeatures;
93
93
  if (Array.isArray(mediaFeatures)) {
94
- page.emulateMediaFeatures(mediaFeatures);
94
+ await page.emulateMediaFeatures(mediaFeatures);
95
95
  }
96
96
 
97
97
  // Emulate timezone (if provided)
@@ -100,34 +100,28 @@ const _processPage = (async (convertAction, urlOrHtml, options) => {
100
100
  await page.emulateTimezone(timezone);
101
101
  }
102
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
103
  // Bypass CSP (content security policy), if provided
110
104
  const bypassCSP = options.bypassCSP; delete options.bypassCSP;
111
105
  if (bypassCSP !== undefined) {
112
- page.setBypassCSP(bypassCSP);
106
+ await page.setBypassCSP(bypassCSP);
113
107
  }
114
108
 
115
109
  // Add extra HTTP headers (if provided)
116
110
  const extraHTTPHeaders = options.extraHTTPHeaders; delete options.extraHTTPHeaders;
117
111
  if (extraHTTPHeaders !== undefined) {
118
- page.setExtraHTTPHeaders(extraHTTPHeaders);
112
+ await page.setExtraHTTPHeaders(extraHTTPHeaders);
119
113
  }
120
114
 
121
115
  // Set geolocation (if provided)
122
116
  const geolocation = options.geolocation; delete options.geolocation;
123
117
  if (geolocation !== undefined) {
124
- page.setGeolocation(geolocation);
118
+ await page.setGeolocation(geolocation);
125
119
  }
126
120
 
127
121
  const raiseOnRequestFailure = options.raiseOnRequestFailure; delete options.raiseOnRequestFailure;
128
122
  if (raiseOnRequestFailure) {
129
123
  page.on('requestfinished', (request) => {
130
- if (request.response() && !request.response().ok() && !request.redirectChain().length > 0) {
124
+ if (request.response() && !(request.response().ok() || request.response().status() == 304) && !request.redirectChain().length > 0) {
131
125
  errors.push(request);
132
126
  }
133
127
  });
@@ -145,11 +139,15 @@ const _processPage = (async (convertAction, urlOrHtml, options) => {
145
139
  // Request is some HTML content. Use request interception to assign the body
146
140
  requestOptions.waitUntil = waitUntil || 'networkidle0';
147
141
  await page.setRequestInterception(true);
148
- page.once('request', request => {
149
- request.respond({ body: urlOrHtml === '' ? ' ' : urlOrHtml });
150
- // Reset the request interception
151
- // (we only want to intercept the first request - ie our HTML)
152
- page.on('request', request => request.continue());
142
+ let htmlIntercepted = false;
143
+ page.on('request', request => {
144
+ // We only want to intercept the first request - ie our HTML
145
+ if (htmlIntercepted)
146
+ request.continue();
147
+ else {
148
+ htmlIntercepted = true
149
+ request.respond({ body: urlOrHtml === '' ? ' ' : urlOrHtml });
150
+ }
153
151
  });
154
152
  const displayUrl = options.displayUrl; delete options.displayUrl;
155
153
  await page.goto(displayUrl || 'http://example.com', requestOptions);
@@ -197,6 +195,12 @@ const _processPage = (async (convertAction, urlOrHtml, options) => {
197
195
  await page.waitForTimeout(waitForTimeout);
198
196
  }
199
197
 
198
+ // Emulate vision deficiency (if provided)
199
+ const visionDeficiency = options.visionDeficiency; delete options.visionDeficiency;
200
+ if (visionDeficiency !== undefined) {
201
+ await page.emulateVisionDeficiency(visionDeficiency);
202
+ }
203
+
200
204
  // If specified, focus on the specified selector
201
205
  const focusSelector = options.focus; delete options.focus;
202
206
  if (focusSelector !== undefined) {
@@ -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.2'
4
+ VERSION = '1.0.6'
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.2
4
+ version: 1.0.6
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-07-21 00:00:00.000000000 Z
11
+ date: 2021-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: combine_pdf