Saving an image file with node.js from canvas.toDataURL()
<p>Im making an electron app and I want the user to be able to save a screenshot of the current page as an image file.
For that I am using html2canvas to create a canvas element of the current body and then convert that canvas to a DataURL</p>

<pre><code>html2canvas(document.body, {
    onrendered: function(canvas) {
        var image = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");
</code></pre>

<p>This works as it is should, but I now want to save this to an image file using Node.js FileSystem</p>

<pre><code>        fs.writeFile("testImg.png", image, 'binary', (err) =&gt; {
            if (err) console.log("didnt work", err);
            else console.log("write worked");
        });  
</code></pre>

<p>This writes a file called "testImg.png" onto my harddrive, but the file only contains: "[object HTMLImageElement]", size is 25kb</p>

<pre><code>        window.location.href=image;
</code></pre>

<p>This opens a dialog for me to save the image file, and actually saves the image too, so my question now is how can I save this image I generate to a file without the user dialog.</p>