html2canvas icon indicating copy to clipboard operation
html2canvas copied to clipboard

Canvas rendering is too slow on Firefox

Open knokit opened this issue 6 years ago • 7 comments

Canvas renderer seems to take ages to render big images on Firefox (sometimes a couple of minutes), whereas Chrome renders the same image in a fraction of a second.

See below an example of the execution times, printed by the logger, for the same image generated in both browsers.

Chrome:

3931ms Starting renderer 3940ms Canvas renderer initialized (2305x8914 at 220,159) with scale 1 4675ms Finished rendering

Firefox:

2611ms Starting renderer 2638ms Canvas renderer initialized (2308x9069 at 220,159.6666717529297) with scale 1 122802ms Finished rendering

Specifications:

  • html2canvas version tested with: 1.0.0-rc.5 (also reproducible with 1.0.0-alpha.12)
  • Browser & version: Firefox 69.0.1 (64-bit)

knokit avatar Oct 09 '19 13:10 knokit

Even i am facing the same issue in firefox whereas chrome and Edge finishes the rendering in less than 5 seconds.

kpkalwa avatar Oct 21 '19 07:10 kpkalwa

Canvas renderer seems to take ages to render big images on Firefox (sometimes a couple of minutes), whereas Chrome renders the same image in a fraction of a second.

See below an example of the execution times, printed by the logger, for the same image generated in both browsers.

Chrome:

3931ms Starting renderer 3940ms Canvas renderer initialized (2305x8914 at 220,159) with scale 1 4675ms Finished rendering

Firefox:

2611ms Starting renderer 2638ms Canvas renderer initialized (2308x9069 at 220,159.6666717529297) with scale 1 122802ms Finished rendering

Specifications:

  • html2canvas version tested with: 1.0.0-rc.5 (also reproducible with 1.0.0-alpha.12)
  • Browser & version: Firefox 69.0.1 (64-bit)

Did you found any solution for this ?

kpkalwa avatar Oct 21 '19 07:10 kpkalwa

@kpkalwa: Unfortunately, I haven't found any solution for this problem.

knokit avatar Oct 22 '19 12:10 knokit

It is because rendering to canvas with clipping is very expensive on Firefox. html2canvas is using clipping regions to support !overflow.hidden styles.

Can be checked with dirty hack: CanvasRenderingContext2D.prototype.clip = function () { };

before calling html2canvas => works very fast, but with clipping artifacts.

RomanLut avatar Jul 03 '20 21:07 RomanLut

It is because rendering to canvas with clipping is very expensive on Firefox. html2canvas is using clipping regions to support !overflow.hidden styles.

Can be checked with dirty hack: CanvasRenderingContext2D.prototype.clip = function () { };

before calling html2canvas => works very fast, but with clipping artifacts.

You have done a miracle, it's just speed up the rendering from 1 minute to 1 second, I can't thank you enough bro.

devravimori avatar Jul 08 '22 07:07 devravimori

It is because rendering to canvas with clipping is very expensive on Firefox. html2canvas is using clipping regions to support !overflow.hidden styles.

Can be checked with dirty hack: CanvasRenderingContext2D.prototype.clip = function () { };

before calling html2canvas => works very fast, but with clipping artifacts.

Did not work for me :(

TannerS avatar Sep 28 '22 21:09 TannerS