You can probably use getImageData, iterate over the data property, and check each pixel to see if it is close enough to white.
Pixel data is stored in groups of four: RGBA. So your loop will probably increment i += 4 to check each value of each pixel. You can adjust how much tolerance you want; 255 in RGB is white, so maybe you can check to see that data[i] >= 255 - tolerance where tolerance is some fairly small number, maybe 5. If data[i], data[i+1], and data[i+2] are all acceptably high, set the pixel in the new image to transparent. Otherwise, set it equal to the value of the original image.
This page has some examples of similar operations: https://pictureelement.github.io/html5tech/canvas-pixel-manipulation-and-animations.html