Skip to content

SVG clip-path attribute slows down html2canvas #3243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tsairinius opened this issue May 7, 2025 · 1 comment
Open

SVG clip-path attribute slows down html2canvas #3243

tsairinius opened this issue May 7, 2025 · 1 comment

Comments

@tsairinius
Copy link

I'm working on an application that involves drawing a few hundred group elements (with a few other elements nested inside each), each with their own clipPath. There's also a user feature for taking a snapshot of the SVG and downloading it as a PNG. However, there is a noticeable performance decline in taking snapshots in Firefox.

I've boiled down to the below JSFiddle example. I'm drawing a bunch of SVG shapes, each nested inside of a group element. Each group element has its clip-path attribute set to a clipPath that does not exist. It doesn't matter whether the clipPath elements exist. Either way, the slowdown occurs.

On click of a button, the color of the shapes changes, and html2canvas is called to take a snapshot of the shapes. The color change forces the SVG to change on each click. I noticed that if the SVG remains the same after multiple clicks, html2canvas is much faster. I'm guessing there's some sort of caching going on.

If you comment out the line where I set the clip-path attribute and then click the button, html2canvas will be a lot faster.

https://jsfiddle.net/mo59cawd/41

@tsairinius
Copy link
Author

After some debugging, the slowdown seems to occur when executing ctx.drawImage in renderReplacedElement of html2canvas.js (v1.4.1). The call to renderReplacedElement is happening under case 10 of the switch statement in renderNodeContent

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

No branches or pull requests

1 participant