How can i allow the users of my website to download the content of an HTML canvas as a PNG file?
The problem is, that I am drawing images from different origins onto this canvas. (The user can insert the URL of an image, and that is drawn onto the canvas). Therefore I cannot use toDataURL(), toBlob() or similar, because they will throw a
DOMException: The operation is insecure.
for cross-origin reasons. As far as I know, the goal of this restriction is to prevent the website from sending the canvas data back to the server, which could leak private data of the user, for example if only he had access to the URL of the image that was drawn.
But allowing the user to download the canvas as a png is not a security risk itself, which makes me think there must be a safe way to do it. But how?
Or is there a way to load the image from a public point of view, instead of the users point of view, which would also get rid of the security risk (assuming my understanding for this restriction is right)?