On the Mozilla Developer Network page, there's an example where you can create a color picker with the help of getImageData(). You can check out the code at https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Pixel_manipulation_with_canvas#A_color_picker.
It seems to work fine on the MDN page. But on CodePen or JSFiddle, it's broken. I tried to follow the instruction with a similar problem, and I get this error when setting img.src to an url: Uncaught TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(CSSImageValue or HTMLImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)'. Hope someone can help me.