bubkoo / html-to-image

✂️ Generates an image from a DOM node using HTML5 canvas and SVG.
MIT License
5.4k stars 505 forks source link

Error when the ownerDocument has no styleSheets attribute #370

Open Arthurk12 opened 1 year ago

Arthurk12 commented 1 year ago

toPNG function throws an error when there is no styleSheets attribute in the ownerDocument node. It tries to iterate over a non-existent attribute.

Expected Behavior

The image should bypass the stylesheets when there is no styleSheets attribute.

Current Behavior

Throws an error and fails.

Possible Solution

Add an extra check inside the parseWebFontRules

let styleSheets=[];
if (node.ownerDocument.hasOwnProperty('styleSheets')) {
  styleSheets = toArray<CSSStyleSheet>(node.ownerDocument.styleSheets)
}
const cssRules = await getCSSRules(styleSheets, options)

Steps To Reproduce

Error Message & Stack Trace

```txt error ReferenceError: __spreadArray is not defined getCurrentValue https://.../html5client/join line 259351 > injectedScript:144 proxyDocumentStyleSheets https://.../html5client/join line 259351 > injectedScript:161 parseWebFontRules https://.../html5client/packages/modules.js parseWebFontRules https://.../html5client/packages/modules.js __awaiter https://.../html5client/packages/modules.js __awaiter https://.../html5client/packages/modules.js parseWebFontRules https://.../html5client/packages/modules.js component.jsx:207:22 ```

Additional Context

This happens when I enable dark mode in the website and then try to generate the image.

vivcat[bot] commented 1 year ago

👋 @Arthurk12

Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. To help make it easier for us to investigate your issue, please follow the contributing guidelines.

We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.