function exportToImage() { if(activeDocument === null) { return null; } return canvas.toDataURL('image/png'); } function downloadImage(name, dataUrl) { const element = document.createElement('a'); element.setAttribute('href', dataUrl); element.setAttribute('download', name); element.style.display = 'none'; document.body.appendChild(element); element.click(); document.body.removeChild(element); } function exportToImageFile() { downloadImage('test.png', exportToImage()); }