From 5cbe5db35155e3a9790a30de09feb17843053b7a Mon Sep 17 00:00:00 2001 From: earshinov Date: Sun, 7 Apr 2019 09:44:01 +0300 Subject: [PATCH] fix: prevent unhandled promise rejections for hidden frames (#1762) --- src/Clone.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Clone.js b/src/Clone.js index 553e21b..2d8058b 100644 --- a/src/Clone.js +++ b/src/Clone.js @@ -213,7 +213,12 @@ export class DocumentCloner { new Promise((resolve, reject) => { const iframeCanvas = document.createElement('img'); iframeCanvas.onload = () => resolve(canvas); - iframeCanvas.onerror = reject; + iframeCanvas.onerror = function(event) { + // Empty iframes may result in empty "data:," URLs, which are invalid from the '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(); if (tempIframe.parentNode) { tempIframe.parentNode.replaceChild(