mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
fix: safari data url taints (#1797)
This commit is contained in:
parent
a63cb3c0f1
commit
4e4a231683
@ -27,38 +27,6 @@ const testRangeBounds = document => {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// iOS 10.3 taints canvas with base64 images unless crossOrigin = 'anonymous'
|
|
||||||
const testBase64 = (document: Document, src: string): Promise<boolean> => {
|
|
||||||
const img = new Image();
|
|
||||||
const canvas = document.createElement('canvas');
|
|
||||||
const ctx = canvas.getContext('2d');
|
|
||||||
|
|
||||||
return new Promise(resolve => {
|
|
||||||
// Single pixel base64 image renders fine on iOS 10.3???
|
|
||||||
img.src = src;
|
|
||||||
|
|
||||||
const onload = () => {
|
|
||||||
try {
|
|
||||||
ctx.drawImage(img, 0, 0);
|
|
||||||
canvas.toDataURL();
|
|
||||||
} catch (e) {
|
|
||||||
return resolve(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return resolve(true);
|
|
||||||
};
|
|
||||||
|
|
||||||
img.onload = onload;
|
|
||||||
img.onerror = () => resolve(false);
|
|
||||||
|
|
||||||
if (img.complete === true) {
|
|
||||||
setTimeout(() => {
|
|
||||||
onload();
|
|
||||||
}, 500);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const testCORS = () => typeof new Image().crossOrigin !== 'undefined';
|
const testCORS = () => typeof new Image().crossOrigin !== 'undefined';
|
||||||
|
|
||||||
const testResponseType = () => typeof new XMLHttpRequest().responseType === 'string';
|
const testResponseType = () => typeof new XMLHttpRequest().responseType === 'string';
|
||||||
@ -135,15 +103,6 @@ const FEATURES = {
|
|||||||
return value;
|
return value;
|
||||||
},
|
},
|
||||||
// $FlowFixMe - get/set properties not yet supported
|
// $FlowFixMe - get/set properties not yet supported
|
||||||
get SUPPORT_BASE64_DRAWING() {
|
|
||||||
'use strict';
|
|
||||||
return (src: string) => {
|
|
||||||
const value = testBase64(document, src);
|
|
||||||
Object.defineProperty(FEATURES, 'SUPPORT_BASE64_DRAWING', {value: () => value});
|
|
||||||
return value;
|
|
||||||
};
|
|
||||||
},
|
|
||||||
// $FlowFixMe - get/set properties not yet supported
|
|
||||||
get SUPPORT_FOREIGNOBJECT_DRAWING() {
|
get SUPPORT_FOREIGNOBJECT_DRAWING() {
|
||||||
'use strict';
|
'use strict';
|
||||||
const value =
|
const value =
|
||||||
|
@ -129,12 +129,11 @@ export default class ResourceLoader {
|
|||||||
this.logger.log(`Added image ${key.substring(0, 256)}`);
|
this.logger.log(`Added image ${key.substring(0, 256)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const imageLoadHandler = (supportsDataImages: boolean): Promise<Image> =>
|
this.cache[key] = new Promise((resolve, reject) => {
|
||||||
new Promise((resolve, reject) => {
|
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
img.onload = () => resolve(img);
|
img.onload = () => resolve(img);
|
||||||
//ios safari 10.3 taints canvas with data urls unless crossOrigin is set to anonymous
|
//ios safari 10.3 taints canvas with data urls unless crossOrigin is set to anonymous
|
||||||
if (!supportsDataImages || useCORS) {
|
if (isInlineBase64Image(src) || useCORS) {
|
||||||
img.crossOrigin = 'anonymous';
|
img.crossOrigin = 'anonymous';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,11 +159,6 @@ export default class ResourceLoader {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.cache[key] =
|
|
||||||
isInlineBase64Image(src) && !isSVG(src)
|
|
||||||
? // $FlowFixMe
|
|
||||||
FEATURES.SUPPORT_BASE64_DRAWING(src).then(imageLoadHandler)
|
|
||||||
: imageLoadHandler(true);
|
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
[Safari]/tests/reftests/acid2.html
|
|
||||||
[Safari]/tests/reftests/background/encoded.html
|
|
Loading…
Reference in New Issue
Block a user