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

Does not show the image on i-phone - Chrome browser.

Open dev-origami opened this issue 4 years ago • 6 comments

domtoimage .toPng(sealImgRef.current, { style: {}, }).then((dataUrl) => { //Does not capture the image }).catch((error)=>{ //Does not throw any error });

The problem is only in i-phone, chrome browser. Safari does not allow.

Please provide the proper solution I am stuck and its a blocker for me. Thanks.

dev-origami avatar Feb 25 '21 11:02 dev-origami

I am facing the same issue. Any help by the author would be appreciated. :)

haris-crewlogix avatar Mar 12 '21 12:03 haris-crewlogix

I managed to solve this problem!

It's not pretty, but it gets the job done. I simply executed domtohtml twice..

    let item = document.getElementById('whiteboard-frame');
    console.log(item)
    domtoimage.toPng(item)
    .then((dataUrl) => {
      domtoimage.toPng(item)
      .then((dataUrl1) => {
          this.savedImage = dataUrl1;
          console.log(this.savedImage)
      })
      .catch((error) => {
          console.error('oops, something went wrong!', error);
      });
    })
    .catch((error) => {
        console.error('oops, something went wrong!', error);
    });

And this now works for me on PC, Android, iPad, and iPhone.

More info in this thread: https://github.com/tsayen/dom-to-image/issues/343#issuecomment-685428224

SimonKomlos avatar Mar 15 '21 02:03 SimonKomlos

@SimonKomlos it worked. thanks. Don't know whats the hack behind calling it two times!

haris-crewlogix avatar Mar 15 '21 13:03 haris-crewlogix

Worked on safari, but does not work on iPhone (Chrome and Safari)

haris-crewlogix avatar Mar 16 '21 08:03 haris-crewlogix

I refactored it to async/await style: `(async() => {

const node = document.getElementById("diploma");

await htmlToImage.toJpeg(node);

const dataUrl2 = await htmlToImage.toJpeg(node);

const link = document.createElement("a");

link.href = dataUrl2;

link.download = "diploma.jpg";

document.body.appendChild(link);

link.click();

document.body.removeChild(link);

})();`

mr4pson avatar Sep 13 '21 19:09 mr4pson

Has anyone tested this hack with react? Can't seem to get it to work.

sabetAI avatar Jul 07 '22 20:07 sabetAI