For that you will need a reference to the canvas, a reference to the drawing context of that canvas and choose when to update the percentage:
1) retrieve the canvas (for instance with getElementById):
var canvas = document.getElementById('id_of_the_canvas');
2) retrieve the drawing context
var ctx = canvas.getContext('2d');
3) retrieve the image data (all the image data)
var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
4) decide at which point you consider a pixel transparent (transparency threshold) and compute the ratio between transparent and non transparent pixel, use imageData.data for faster computation:
var pixelCount = canvas.width * canvas.height;
var arrayElemsCount = pixelCount * 4; // for components (rgba) per pixel.
var dataArray = imageData.data;
// 0 is completely transparent, set to 0.5 to
// allow for instance semi transparent pixels to be accounted for
var threshold = 0;
var transparentPixelCount = 0;
// remember fourth (index = 3) byte is alpha
for (var i = 3; i < arrayElemsCount; i+= 4) {
var alphaValue = dataArray[i];
if (alphaValue <= threshold) {
transparentPixelCount++;
}
}
var transparencyPercentage = (transparentPixelCount / pixelCount) * 100;
This operation is computationaly intensive so choose well when to execute it: either after some time ellapsed since the last drawing operation (debounce during drawing) or at regular interval during drawing (throttle during drawing).