#結論
<canvas id="canvas"></canvas>
<a id="download">download</a>
<script>
const filename = "test.png";
document.getElementById("download").onclick = (event) => {
let canvas = document.getElementById("canvas");
let link = document.createElement("a");
link.href = canvas.toDataURL("image/png");
link.download = filename;
link.click();
}
</script>