top of page

Create screenshot from DIV in LWC

There are some ways to take screenshot from div in javascript but in LWC, we need to modify to make it LWC compatible.


First write html as follows



in JS you need to import html2canvas.js. you can download this js from this location.




using printDiv function we can create screenshot and display on the page.

Remember we can display image on Canvas as well, but in my case I was getting blurry images on canvas, so instead on canvas i displayed it on img tag.

11 Comments


Divya Ch
Divya Ch
Aug 11, 2025

Facing the same error - caught (in promise) Unable to find element in cloned iframe. Was anyone able to solve it?

Like

Sridhar NareshIT
Sridhar NareshIT
Dec 15, 2023

Thanks for Making my job very easier , very helpful blog Keep sharing more blogs on salesforce

Like

Nevo Harari
Nevo Harari
Jul 03, 2023

and Can't see inside the js lib


Like

Nevo Harari
Nevo Harari
Jul 03, 2023

I also get caught (in promise) Unable to find element in cloned iframe

Like

Souvik Khan
Souvik Khan
May 04, 2023

My requirement is kinda same, want to take screenshot/convert lwc component to img/svg format. Using html2canvas as above, it showing this error: caught (in promise) Unable to find element in cloned iframe Any idea?

Like
Tommy
Tommy
Sep 07, 2023
Replying to

Also, doesn't work in Chrome for me either. would love if the Author could explain their solution!

Like

Subscribe to SFDC BLOGS

©2019 by SFDC Blogs.

bottom of page