html2canvas
html2canvas copied to clipboard
html2canvas "Error loading image"
It can download but the image in the downloaded image doesn't the image.
Take a look at this issue :https://github.com/niklasvh/html2canvas/issues/2609
this.context.logger.debug("Added image " + key.substring(0, 256)); return [4 /yield/, new Promise(function (resolve, reject) { var img = new Image(); img.onload = function () { return resolve(img); }; img.onerror = reject; //ios safari 10.3 taints canvas with data urls unless crossOrigin is set to anonymous if (isInlineBase64Image(src) || useCORS) { img.crossOrigin = 'anonymous'; }
// img.src = src;
// ----------------------------------------------------------------------------
// 禁用缓存。否则浏览器会默认从内存去取,导致触发同源策略
img.src = src + `?date=${Date.now()}`
// ----------------------------------------------------------------------------
if (img.complete === true) {
// Inline XML images may fail to parse, throwing an Error later on
setTimeout(function () { return resolve(img); }, 500);
}
if (_this._options.imageTimeout > 0) {
setTimeout(function () { return reject("Timed out (" + _this._options.imageTimeout + "ms) loading image"); }, _this._options.imageTimeout);
}
})];
just change img.src = src; to img.src = src + ?date=${Date.now()}
. cause browser cache trigger CORS even cors enabled.
you could found out by disable cache of your browser.
you can first load img turn to base64 at correct life cycle, then use ref data on img tag
you can around this problem