This is because you're trying to pass a string (the dataURL version of the image)
to drawImage when the drawImage function is expecting an image/canvas.
The drawImage function can take in a canvas element as its argument, which will do
what you want.Instead of doing:
img = canvas.toDataURL();