Example in Brave, which broke hit detection. Not sure if a bug with Brave or if a new parameter is needed to set up the context.
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.fillStyle = "red";
ctx.fillRect(10, 10, 50, 50);
also tried var ctx = c.getContext("2d", { preserveDrawingBuffer: true, antialias: false, });
Expect ctx.getImageData(30, 30, 1, 1) to return Uint8ClampedArray(4) [255, 0, 0, 255]
But got data: Uint8ClampedArray(4) [254, 1, 0, 255]
Other variations:
ctx.getImageData(30, 30, 10, 10)
data: Uint8ClampedArray(400) [255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 1, 0, 255, 255, 1, 1, 255, 255, 0, 1, 255, 255, 0, 0, 255, 254, 0, 0, 255, 254, 1, 0, 255, 255, 1, 0, 255, 255, 0, 1, 255, 255, 0, 1, 255, 255, 1, 1, 255, 255, 0, 1, 255, 255, 1, 0, 255, 255, 1, 1, 255, 255, 0, 1, 255, 254, 0, 1, 255, 255, 0, 1, 255, 254, 1, 1, 255, 254, 0, 1, 255, 255, 0, 1, 255, 255, 0, 0, 255, 255, 0, 1, 255, 255, 0, 1, 255, โฆ]
ctx.getImageData(30, 30, 5, 5)
ImageData {data: Uint8ClampedArray(100), width: 5, height: 5}
data: Uint8ClampedArray(100) [254, 1, 0, 255, 255, 0, 1, 255, 255, 1, 0, 255, 254, 0, 0, 255, 255, 1, 0, 255, 254, 1, 1, 255, 255, 1, 0, 255, 255, 0, 0, 255, 254, 1, 1, 255, 255, 0, 0, 255, 254, 1, 0, 255, 254, 1, 1, 255, 254, 1, 0, 255, 255, 0, 1, 255, 254, 1, 1, 255, 254, 0, 0, 255, 255, 0, 0, 255, 254, 1, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 254, 0, 1, 255, 254, 0, 1, 255, 255, 0, 1, 255, 255, 1, 1, 255, 255, 1, 1, 255]
ctx.getImageData(30, 30, 1, 4)
ImageData {data: Uint8ClampedArray(16), width: 1, height: 4}
data: Uint8ClampedArray(16) [254, 0, 0, 255, 254, 1, 0, 255, 254, 1, 0, 255, 255, 0, 1, 255]
ctx.getImageData(30, 30, 1, 3)
ImageData {data: Uint8ClampedArray(12), width: 1, height: 3}
data: Uint8ClampedArray(12) [255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255]