fix: prevent unhandled promise rejections for hidden frames (#1762)

This commit is contained in:
earshinov 2019-04-07 09:44:01 +03:00 committed by Niklas von Hertzen
parent 3212184146
commit 5cbe5db351

View File

@ -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 <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();
if (tempIframe.parentNode) {
tempIframe.parentNode.replaceChild(