Open cheong12001 opened 1 year ago
I have found the code snippet in pica's canvas detection, if "privacy.resistFingerprinting" is set to true, canvas is not usable which can be used to check the setting.
const canUseCanvas = () => {
let usable = false;
try {
let canvas = document.createElement("canvas");
canvas.width = 2;
canvas.height = 1;
let ctx = canvas.getContext("2d");
let d = ctx.createImageData(2, 1);
d.data[0] = 12;
d.data[1] = 23;
d.data[2] = 34;
d.data[3] = 255;
d.data[4] = 45;
d.data[5] = 56;
d.data[6] = 67;
d.data[7] = 255;
ctx.putImageData(d, 0, 0);
d = null;
d = ctx.getImageData(0, 0, 2, 1);
if (
d.data[0] === 12 &&
d.data[1] === 23 &&
d.data[2] === 34 &&
d.data[3] === 255 &&
d.data[4] === 45 &&
d.data[5] === 56 &&
d.data[6] === 67 &&
d.data[7] === 255
) {
usable = true;
}
} catch (err) {}
return usable;
};
Can you check it by the canUseCanvas
in your project directly?
The image upload corrupt when the Firefox setting "privacy.resistFingerprinting" is setting to "true". I would like to handle this error by skipping the resize process before uploading. However, can the library detect the setting and throwing error?