niklasvh / html2canvas

Screenshots with JavaScript
https://html2canvas.hertzen.com/
MIT License
30.54k stars 4.8k forks source link

IFrame with no width/height fails #1892

Open daniel-hauser opened 5 years ago

daniel-hauser commented 5 years ago

Bug reports:

Trying to export an element with iframe with no width/height fails.

v1.0.0-rc.0: works as expected see here. v1.0.0-rc.3: will fail with Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The image argument is a canvas element with a width or height of 0. see here.

Specifications:

daniel-hauser commented 5 years ago

1887 is probably related but has no code to confirm

daniel-hauser commented 5 years ago

@niklasvh A possible fix is to use getComputedStyle(iframe).width here instead of iframe.width (and same for height)

Would you want me to open a PR?

val1984 commented 5 years ago

PR #1863 has been merged in master recently so next release will hopefully solve your issue.

daniel-hauser commented 5 years ago

The code added in #1863 will result in not adding the iframe to the canvas. This is not good - as iframe width and height have default values (300 x 150px)

val1984 commented 5 years ago

Sorry, I didn't check everything. You can definitely open a PR, that's what I did for the issue I had opened (#1865) and my PR has been merged.