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') {
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`);
}
}
}