Good points from both sides! If you prefer a jQuery approach, you can make this even easier. The jQuery code will ensure that the download action happens only after the user click:
$('#downloadBtn').on('click', function() {
const canvas = $('#myCanvas')[0];
const image = canvas.toDataURL('image/png');
$('<a>')
.attr('href', image)
.attr('download', 'output.png')
.appendTo('body')
.get(0)
.click();
$('a').last().remove();
});
With this method, you’re wrapping everything in a nice jQuery handler. The download is triggered by a genuine click, which browsers are happy to accept, and you won’t run into any issues with user interaction!