From c62cbbd65b930b7294990c010165e12a7493dcfe Mon Sep 17 00:00:00 2001 From: MoyuScript Date: Sun, 3 Sep 2017 21:24:17 +0800 Subject: [PATCH] Improve logging --- src/Clone.js | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/Clone.js b/src/Clone.js index 77a2644..dec96b1 100644 --- a/src/Clone.js +++ b/src/Clone.js @@ -37,7 +37,12 @@ export class DocumentCloner { if (backgroundImage.method === 'url') { return this.imageLoader .inlineImage(backgroundImage.args[0]) - .then(img => (img ? `url("${img.src}")` : 'none')); + .then(img => (img ? `url("${img.src}")` : 'none')) + .catch(e => { + if (__DEV__) { + this.logger.log(`Unable to load image`, e); + } + }); } return Promise.resolve( `${backgroundImage.prefix}${backgroundImage.method}(${backgroundImage.args.join( @@ -54,14 +59,20 @@ export class DocumentCloner { }); if (node instanceof HTMLImageElement) { - this.imageLoader.inlineImage(node.src).then(img => { - if (img && node instanceof HTMLImageElement && node.parentNode) { - node.parentNode.replaceChild( - copyCSSStyles(node.style, img.cloneNode(false)), - node - ); - } - }); + this.imageLoader + .inlineImage(node.src) + .then(img => { + if (img && node instanceof HTMLImageElement && node.parentNode) { + const parentNode = node.parentNode; + const clonedChild = copyCSSStyles(node.style, img.cloneNode(false)); + parentNode.replaceChild(clonedChild, node); + } + }) + .catch(e => { + if (__DEV__) { + this.logger.log(`Unable to load image`, e); + } + }); } } } @@ -73,7 +84,9 @@ export class DocumentCloner { img.src = node.toDataURL(); return img; } catch (e) { - this.logger.log(`Unable to clone canvas contents, canvas is tainted`); + if (__DEV__) { + this.logger.log(`Unable to clone canvas contents, canvas is tainted`); + } } }