var canvas = document.createElement("canvas");
canvas.width = 200;
canvas.height = 200;
var url = canvas.toDataURL();
var a = document.createElement('a');
a.download = 'my.png';
a.href = url;
a.textContent = 'Download PNG';
document.body.appendChild(a);
Run code snippet