Fix chrome issue with the crossOrigin images

In Chrome browser if the image loaded before without crossorigin it will be cached and used later even if the next usage has crossorigin so it will fail with CORS error.
so add a random query parameter just to prevent the Chrome from using the cached image.

see more info about the Chrome issue in this link: https://stackoverflow.com/a/49503414
This commit is contained in:
alaa-alshamy 2022-01-24 22:55:04 +03:00 committed by GitHub
parent 6020386bbe
commit 7aab59b3e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -96,6 +96,10 @@ export class Cache {
//ios safari 10.3 taints canvas with data urls unless crossOrigin is set to anonymous
if (isInlineBase64Image(src) || useCORS) {
img.crossOrigin = 'anonymous';
// in chrome if the image loaded before without crossorigin it will be cached and used later even if the next usage has crossorigin
// so it will fail with CORS error, so add a random query parameter just to prevent the chrome from using the cached image
// see more info about the chrome issue in this link: https://stackoverflow.com/a/49503414
src = src + (src.indexOf('?') === -1 ? '?' : '&') + 'cacheBusting=1';
}
img.src = src;
if (img.complete === true) {