try to fix tainted canvas in historical view

This commit is contained in:
HF 2020-06-21 05:23:38 +02:00
parent c16c427ebd
commit e93ddd0576

View File

@ -1,5 +1,15 @@
/* @flow */
/*
* check if cross-origin request
* see:
* https://medium.com/@albertogasparin/manipulating-cross-origin-images-with-html-canvas-1e3e8780964c
*/
const corsRegEx = /^([\w]+:)?\/\//;
function isCors(url) {
return corsRegEx && url.indexOf(window.location.host) === -1;
}
/*
* general function for async loading images
* @param url url of image
@ -12,6 +22,9 @@ export function loadImage(url) {
img.addEventListener('error', () => {
reject(new Error(`Failed to load image's URL: ${url}`));
});
if (isCors(url)) {
img.crossOrigin = 'anonymous';
}
img.src = url;
});
}