Studiosity / grover

A Ruby gem to transform HTML into PDFs, PNGs or JPEGs using Google Puppeteer/Chromium
MIT License
946 stars 107 forks source link

Undefined method `#pack` for nilClass on latest puppeteer release (23.0.0) #252

Closed taylorthurlow closed 2 months ago

taylorthurlow commented 3 months ago

puppeteer 23.0.0 looks to have broken Grover.

I was able to fix the issue by changing line 24 in lib/grover/processor.rb from:

result['data'].pack('C*')

to:

result.values.pack('C*')

The result value was expected to be a hash with a 'data' key, and now it appears to be a hash between a String and an integer (one example k/v pair is "135890"=>52). It's not immediately obvious where the breaking change was that causes this, perhaps it is this PR?

rud commented 3 months ago

!!I'm just a rando using the library!!

@taylorthurlow I know it's just a single line change, but would you mind making it into a patch, along with a comment for the README that puppeteer has to be 23.x to work with the next release of grover?

Kay-pet commented 3 months ago

Hi,

I am on

puppeteer 23.1.0

grover 1.1.9

node v18.16.1

And i am getting this same error even though I locally made the change in processor.rb on line 24 to result["data"]&.pack("C*") || result.values.pack("C*") line you have in the open PR.

[5] pry(main)> grover = Grover.new('<html><p>Foo</p></html>')
#<Grover:0x102580 @uri="<html><p>Foo</p></html>">
[6] pry(main)> grover.to_pdf
NoMethodError: undefined method `pack' for nil:NilClass
from /Users/kayla.peters/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/grover-1.1.9/lib/grover/processor.rb:24:in `convert'

Just curious if you have any insight on why this is still failing after I made the change to result["data"]&.pack("C*") || result.values.pack("C*") since this is just in the rails console.

Let me know if you need more information. Thank you

taylorthurlow commented 3 months ago

@Kay-pet Hard to say exactly, would be easier to tell if we knew what result is in your case. I wouldn't expect the first half of the double-pipe-or expression to raise the exception because of the safe navigation operator so my best guess at this point would be that result.values is returning nil, but why that would be the case I'm not sure.

Best thing would probably be to stick a debugger in there and inspect the variables there to see what value isn't as it is expected to be. What should be happening is that #pack is called on an array of integers.

Kay-pet commented 3 months ago

@taylorthurlow on me, my environment just hadn't reloaded fully. With the change coming in your PR mine works. Thank you

Ted-Tash commented 2 months ago

I am also having this error; @taylorthurlow thank you for the PR!

abrom commented 2 months ago

Hey folks, yes it looks like Puppeteer v23.x switch from using Buffer to Uint8Array when returning the PDF/image result to better support other platforms (besides Node). Issue has been fixed in #256 and released in v1.1.10