How to use Fabric.js to save a canvas as an image

The following must be true:

  1. Your cross-domain <img> elements must contain a crossorigin attribute.
  2. The server hosting the images must return an Access-Control-Allow-Origin header in the response with either a wildcard, or your specific domain as the value.
  3. The browser must support CORS on HTMLMediaElements, specifically HTMLImageElements. This is only currently possible in Chrome, Firefox, and Opera 15+

This works well for me

function convertToImagen() {
  canvas.deactivateAll().renderAll();  
  window.open(canvas.toDataURL('png')); 
}

As a side note, remember that if you're developing on your local computer rather on a server, you will probably see this security error message.