happy-dom icon indicating copy to clipboard operation
happy-dom copied to clipboard

Add support for Canvas

Open steel opened this issue 3 years ago • 22 comments

e.g. document.createElement('canvas').getContext('2d')

steel avatar Apr 07 '21 22:04 steel

Thanks for reporting @steel! :slightly_smiling_face:

I will look into adding support for Canvas as soon as possible. However, being able to render graphics might be a bit challenging, but at least we can get support for the API.

capricorn86 avatar Apr 12 '21 10:04 capricorn86

@capricorn86 Just use https://www.npmjs.com/package/canvas :D

taye avatar Jan 29 '22 18:01 taye

@taye

@capricorn86 Just use npmjs.com/package/canvas :D

Are you saying that you can use that package to add in canvas support to happy-dom?

Sparticuz avatar Jun 07 '22 14:06 Sparticuz

@Sparticuz I need to evaluate the package first. I am a bit worried that it is depended on OS system libraries to work, but on the other hand it seems quite popular :sweat_smile:

capricorn86 avatar Jun 08 '22 20:06 capricorn86

FYI, adding canvas might mean impacting running tests in parallel for solutions using happy-dom for that:

https://github.com/Automattic/node-canvas/issues/2019

For example:

https://github.com/vitest-dev/vitest/issues/740

I just wanted to point it out, no real opinion otherwise (maybe some config can control these "if there is a peer I will depend on it" cases to give control over them, or maybe that is too much config... idk)

webChannelN avatar Jun 10 '22 08:06 webChannelN

As @webChannelN said, node-canvas does not support workers environment

huang-julien avatar Jul 15 '22 14:07 huang-julien

And also consider that node-canvas doesn't have prebuilt binaries for ARM64 https://github.com/Automattic/node-canvas/issues/1662

markov00 avatar Jul 25 '22 18:07 markov00

What about use jimp to implement a basic getContext('2d') support?

aurium avatar Apr 07 '23 22:04 aurium

https://github.com/google/skia/tree/main/modules/canvaskit runs completely on WASM

Roosteridk avatar Apr 29 '23 14:04 Roosteridk

Also we could at least add a canvas element as a stub for a future implementation

Roosteridk avatar Apr 29 '23 14:04 Roosteridk

would like this implemented too. seems like node-canvas might have issues with things like lambda's. would recommend skia or napi-rs

jeevanpillay0000 avatar May 24 '23 17:05 jeevanpillay0000

Please don't use node-canvas for this 👍

codepunkt avatar Jul 17 '23 08:07 codepunkt

I'm thinking about picking this up soon. I think that going with something like Skia seems like the best bet as performance is an important aspect here. I can imagine this being used in some applications for server side rendering and then we don't want any performance bottlenecks. However, it probably has to be an optional dependency or a plugin.

capricorn86 avatar Aug 07 '23 22:08 capricorn86

Hi @capricorn86 Any update on this and/or ETA on a resolution to this issue?

weastaughscottlogic avatar Dec 11 '23 11:12 weastaughscottlogic

@weastaughscottlogic the update is that this is still high priority, but it is not a small task. It will probably be the next thing after going through the queue of pull requests and major bugs.

capricorn86 avatar Feb 25 '24 21:02 capricorn86

Is there an workaround for this, while happy-dom still doesn't support the Canvas AP ?

KreutzVinicius avatar Apr 24 '24 17:04 KreutzVinicius