JSFiddle - React, Tailwind, and code Playground
HTML
<canvas width="400" height="400" id="cv"></canvas>
JavaScript
var cv = $('#cv').get(0),
ctx = cv.getContext('2d');
ctx.moveTo(0,0);
ctx.lineTo(10,10);
ctx.stroke();
var decoded = atob(cv.toDataURL().substr(22));
alert(decoded.substr(0, 20)); // part of png file
alert(decoded.length); // length of png file