mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
fix: prevent unhandled promise rejections for hidden frames (#1762)
This commit is contained in:
parent
3212184146
commit
5cbe5db351
@ -213,7 +213,12 @@ export class DocumentCloner {
|
|||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
const iframeCanvas = document.createElement('img');
|
const iframeCanvas = document.createElement('img');
|
||||||
iframeCanvas.onload = () => resolve(canvas);
|
iframeCanvas.onload = () => resolve(canvas);
|
||||||
iframeCanvas.onerror = reject;
|
iframeCanvas.onerror = function(event) {
|
||||||
|
// Empty iframes may result in empty "data:," URLs, which are invalid from the <img>'s point of view
|
||||||
|
// and instead of `onload` cause `onerror` and unhandled rejection warnings
|
||||||
|
// https://github.com/niklasvh/html2canvas/issues/1502
|
||||||
|
iframeCanvas.src == 'data:,' ? resolve(canvas) : reject(event);
|
||||||
|
};
|
||||||
iframeCanvas.src = canvas.toDataURL();
|
iframeCanvas.src = canvas.toDataURL();
|
||||||
if (tempIframe.parentNode) {
|
if (tempIframe.parentNode) {
|
||||||
tempIframe.parentNode.replaceChild(
|
tempIframe.parentNode.replaceChild(
|
||||||
|
Loading…
Reference in New Issue
Block a user