Skip to content

Commit

Permalink
Prevent unhandled promise rejections for hidden frames
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeny Arshinov committed Feb 24, 2019
1 parent 41eb8ab commit 07091e1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 07091e1

Please sign in to comment.