I am new to using canvas operations in javascript and came across a functionality in my tool which converts HTML5Canvas to a Blob using the async function toBlob which uses callback as its first argument. Callback receives the converted blob value as input and can be used for further processing. However, for few random cases happening very rarely, the toBlob function is unable to convert to blob and the callback receives null as input. Find the code below
canvases.forEach(canvasObj => {
canvasObj.canvas.toBlob(blob => {
const reader = new FileReader();
reader.readAsDataURL(blob)
reader.onload = function () {
//process reader.result
};
})
})
I am getting following exception in the above code for the failed cases
Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob'
I checked for resources and similar issues that can help me fix the issue but could not find much here. Can anyone help and let me know what are cases where the toBlob function will fail.