Skip to content

Conversation

@Yazaar
Copy link

@Yazaar Yazaar commented Oct 11, 2025

Goal

Primary goal is to fix the issue where base64 strings incorrectly gets wrapped within a Buffer object.

On top of that providing some additional fixes with the typing to make the user experience better.

I did also notice that apps exit with code 1 (error). This would be a problem for most use cases of the library and therefore removed this from the catch clause of the function call.

To futher increase the user experience also added JS Doc for the exposed function, to give code editors context on the function and what parameters mean what.

Related issue

This PR does not only fix some issues that I have ran into, but after reviewing the code also found some other pitfalls which I have fixed.

#230
Issue raised by me regarding the base64 string issue, where it is always wrapped in a Buffer object instead of returning the base64 string similar to v4 of node-html-to-image

#228
Issue describing that the exposed nodeHtmlToImage function is missing handlebarsHelpers. In order to provide handlebarsHelpers you have to pass it without typing and mark it as i.e @ts-expect-error.

#165 | #221
These issues both describe an issue where they are unable to handle try-catch. This is due to the process.exit(1) leading a force close of the parent process.

Changes

  • Fix typing errors and warnings in spec files (test cases)
    • Update rimraf package since the current one didn't include typing declarations, but never versions does
  • Add "--no-sandbox" option to puppeteerArgs.args within all test cases since a lot of systems and enclosed systems doesn't support this sandboxing environment. The processed data is test case controlled and therefore safe either way so no negatives for the test cases
  • Fix case where base64 strings during encoding mode base64 gets wrapped in a Buffer object. By this change following the same spec as v4.0.0 and the existing typing conventions.
  • More advanced and dynamic typing according to provided options payload
    • Content option deep typing
    • Exposing apis properly via options (i.e handlebarsHelpers were missing). Via interface inheritance getting rid of duplicated declarations which prevents conflicts and missing options.
    • Dynamic return type recognition according to options payload. Previously the return type no matter what was a union return type string | Buffer | (string | Buffer)[]. Now it will be one of the following and always only one which is declared via the provided options payload: string, Buffer, string[], Buffer[]
    • JS Doc on the exposed function (nodeHtmlToImage), leading to easier use for end users
  • Remove the case where throws close down the entire app entirely, leading to parent applications unexpectedly shutting down without any type of feedback. Now it will simply throw, but safely close down the cluster via a catch still.

Thank you for providing us all this open source library!

Best regards and wishes,
Yazaar / Jesper

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant