html2canvas icon indicating copy to clipboard operation
html2canvas copied to clipboard

Uncaught (in promise) Unable to find element in cloned iframe

Open raana96 opened this issue 4 years ago • 3 comments

How can I fix this error?

my example code:

   const wrapper = document.createElement("div");
   const myHTMLString = "<div>Hello</div>";
   wrapper.insertAdjacentHTML("afterbegin",myHTMLString);
   //console.log(">>>",wrapper);
   html2canvas(wrapper,{useCORS: true}).then((canvas) => {
    wrapper.appendChild(canvas); 
    console.log("canvas>>",wrapper.appendChild(canvas));
    var base64encodedstring = canvas.toDataURL('image/jpeg', 1.0);
     console.log("base6", base64encodedstring );
    });

error : 176e275da87 1ms Starting document clone new:1 Uncaught (in promise) Unable to find element in cloned iframe

raana96 avatar Jan 08 '21 14:01 raana96

Having this issue too. you have to append the wrapper to the dom tree first: document.body.appendChild(wrapper);

the canvas from the promise then does not contain a new canvas element, but an iframe containing it.

ghost avatar Apr 22 '21 14:04 ghost

I also encountered the same problem. Have you solved it?

liuyingjie1130 avatar Oct 28 '21 02:10 liuyingjie1130

+1

qertis avatar Aug 17 '22 19:08 qertis

+1

yairbar avatar Nov 06 '22 17:11 yairbar

+1

baokuanze avatar Aug 11 '23 07:08 baokuanze