html2canvas icon indicating copy to clipboard operation
html2canvas copied to clipboard

generate image no response in IOS 15.4

Open UntilGone opened this issue 2 years ago • 20 comments

Bug reports:

Generated image no response when updated IOS to 15.4. Without error or log. Same code in IOS 15.3 running ok.

Demo

/* the dom */
<div>1111</div>
import html2canvas from 'html2canvas';
html2canvas(dom, {
      width: dom.clientWidth,
      height: dom.clientHeight,
      useCORS: true,
      scale: window.devicePixelRatio,
    })
      .then((canvas) => {
        console.log('test111');
        if (canvas) {
          resolve(canvas.toDataURL());
        } else {
          reject(new Error('something wrong'));
        }
      })
      .catch((err) => {
        console.log('test4');
      })
      .finally(() => {
        console.log('test5');
      });
// this code has no log

Specifications:

  • html2canvas version tested with: 1.4.1
  • Browser & version: Safari
  • Operating system: IOS 15.4

UntilGone avatar Mar 24 '22 08:03 UntilGone

I have the same problem after update IOS 15.4 on Safari and Chrome browser

vendra95 avatar Mar 25 '22 12:03 vendra95

+1

ZhangHang12135 avatar Apr 01 '22 06:04 ZhangHang12135

same problem

j4n17 avatar Apr 01 '22 06:04 j4n17

same

Vstar18 avatar Apr 15 '22 00:04 Vstar18

same problem

TuffyLiu avatar Apr 21 '22 05:04 TuffyLiu

Same problem

osnysantos avatar Apr 25 '22 08:04 osnysantos

same

niniks avatar Apr 25 '22 10:04 niniks

Modify scale: Math.min(window.devicePixelRatio, 2) Can solve this problem.

zhe-he avatar Apr 27 '22 10:04 zhe-he

I found issue with iframeLoader in DocumentCloner. In Safari 15.4 and newest MacOS do not call onload function on iframe, created by script and his readyState is interactive all the time so, condition in setInterval is never truthly.

Temporary soluction is remove onload function, use exist setInterval and modify condition with be checking readyState.

var interval = setInterval(function () {
    if (documentClone.body.childNodes.length > 0 && (documentClone.readyState === 'complete' || documentClone.readyState === 'interactive')) {
        clearInterval(interval);
        resolve(iframe);
    }
}, 50);

Code to replace: https://github.com/niklasvh/html2canvas/blob/6020386bbeed60ad68e675fdcaa6220e292fd35a/src/dom/document-cloner.ts#L542-L550

konradsajdak avatar Apr 27 '22 14:04 konradsajdak

version 1.3.4 works in iOS 15.4.x, but version 1.4.1 do not, either it does not return or it is 10 times slower, no errors! using html2canvas with jsPDF...

jesben avatar May 09 '22 12:05 jesben

I found issue with iframeLoader in DocumentCloner. In Safari 15.4 and newest MacOS do not call onload function on iframe, created by script and his readyState is interactive all the time so, condition in setInterval are never truthly.

Temporary soluction is remove onload function, use exist setInterval and modify condition with be checking readyState.

var interval = setInterval(function () {
    if (documentClone.body.childNodes.length > 0 && (documentClone.readyState === 'complete' || documentClone.readyState === 'interactive')) {
        clearInterval(interval);
        resolve(iframe);
    }
}, 50);

Code to replace:

https://github.com/niklasvh/html2canvas/blob/6020386bbeed60ad68e675fdcaa6220e292fd35a/src/dom/document-cloner.ts#L542-L550

so far this works for me thanks @KonradSajdak

aelbore avatar May 30 '22 09:05 aelbore

I had an issue generating image on IOS 15.4.1 and once I removed a background-image and replaced it with an <img> it was resolved.

toffifeeIt avatar May 31 '22 13:05 toffifeeIt

Same problem with Safari browser on Mac

mattyforth avatar Jun 27 '22 20:06 mattyforth

Since i couldnt get the problem gone i switched to the package > html-to-image Sofar this is running great without problems, i hope this helps more people looking for a quick fix

niniks avatar Jun 28 '22 08:06 niniks

@niniks Is there an easy way to grab a main javascript file for this? Or is the only way to use node/npm, as I am not using either in my project?

ryanatearth avatar Jun 28 '22 18:06 ryanatearth

Modify scale: Math.min(window.devicePixelRatio, 2) Can solve this problem.

This worked for me. Happens when I pass a node thats very long.

5PK avatar Jun 29 '22 01:06 5PK

The problem lies in the picture. I set loading='lazy' and the iframe does not trigger onload. Just delete loading='lazy'.

wyysf123 avatar Jun 29 '22 05:06 wyysf123

If you're using Next/Image, it sets loading="lazy" by default, so it change to loading="eager", then this problem will avoid.

shooooori0128 avatar Mar 31 '23 11:03 shooooori0128

I found issue with iframeLoader in DocumentCloner. In Safari 15.4 and newest MacOS do not call onload function on iframe, created by script and his readyState is interactive all the time so, condition in setInterval is never truthly.

Temporary soluction is remove onload function, use exist setInterval and modify condition with be checking readyState.

var interval = setInterval(function () {
    if (documentClone.body.childNodes.length > 0 && (documentClone.readyState === 'complete' || documentClone.readyState === 'interactive')) {
        clearInterval(interval);
        resolve(iframe);
    }
}, 50);

Code to replace:

https://github.com/niklasvh/html2canvas/blob/6020386bbeed60ad68e675fdcaa6220e292fd35a/src/dom/document-cloner.ts#L542-L550

thank you so much @aelbore . It's worked!

dangngocbinh avatar Nov 27 '23 03:11 dangngocbinh

Hello , is there a version that solves this problem or not yet ?

Mtaylorr avatar Jan 05 '24 14:01 Mtaylorr