Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firefox setting "privacy.resistFingerprinting" to true will corrupt the image resize #177

Open
cheong12001 opened this issue Jul 13, 2023 · 2 comments
Labels

Comments

@cheong12001
Copy link

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?

@cheong12001
Copy link
Author

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;
};

@cheong12001 cheong12001 changed the title Firefox setting "privacy.resistFingerprinting" to true will corrupt the image upload Firefox setting "privacy.resistFingerprinting" to true will corrupt the image resize Jul 13, 2023
@fengyuanchen
Copy link
Owner

Can you check it by the canUseCanvas in your project directly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants