forked from ppfun/pixelplanet
try to fix tainted canvas in historical view
This commit is contained in:
parent
c16c427ebd
commit
e93ddd0576
|
@ -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;
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user