Improve logging

This commit is contained in:
Niklas von Hertzen 2017-09-03 21:24:17 +08:00
parent 906a66eec7
commit 1a53643457

View File

@ -37,7 +37,12 @@ export class DocumentCloner {
if (backgroundImage.method === 'url') { if (backgroundImage.method === 'url') {
return this.imageLoader return this.imageLoader
.inlineImage(backgroundImage.args[0]) .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( return Promise.resolve(
`${backgroundImage.prefix}${backgroundImage.method}(${backgroundImage.args.join( `${backgroundImage.prefix}${backgroundImage.method}(${backgroundImage.args.join(
@ -54,14 +59,20 @@ export class DocumentCloner {
}); });
if (node instanceof HTMLImageElement) { if (node instanceof HTMLImageElement) {
this.imageLoader.inlineImage(node.src).then(img => { this.imageLoader
if (img && node instanceof HTMLImageElement && node.parentNode) { .inlineImage(node.src)
node.parentNode.replaceChild( .then(img => {
copyCSSStyles(node.style, img.cloneNode(false)), if (img && node instanceof HTMLImageElement && node.parentNode) {
node 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(); img.src = node.toDataURL();
return img; return img;
} catch (e) { } 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`);
}
} }
} }