grover 1.0.2 → 1.0.6
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 +20 -16
- data/lib/grover/middleware.rb +9 -2
- 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: b29220f00e289b012a01c83e1ac3a4d7fe70b034589760f3aea045069127e453
         | 
| 4 | 
            +
              data.tar.gz: f90bcb0e42bab405df3d296d4f70221684652d2e523970b9018b3a38737f8694
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 2415a80b468c7bbe454cf622fbae3b2cef2b7450577f92845e30fbef54d602a3f46dbf4594258053f07badc847c7ab1f3ac53c72f04a385d993b85e054295448
         | 
| 7 | 
            +
              data.tar.gz: a928a1f0bc91ba18b7059fd60e44d2348d6727e4cd7d37fbc47e13cf56b1a5e9fa04d6136189a1a3e1a673ab3a86572d5ef58e7e2ca54cc797ab355327c2db37
         | 
    
        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
    
    | @@ -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 | 
            -
                   | 
| 149 | 
            -
             | 
| 150 | 
            -
                    //  | 
| 151 | 
            -
                     | 
| 152 | 
            -
             | 
| 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) {
         | 
    
        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.0. | 
| 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- | 
| 11 | 
            +
            date: 2021-10-12 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: combine_pdf
         |