My friend well, this question been asked 6 years ago, I think definitely you solve your problem, so for the people who stuck with the same problem you can fix via below tactics.
Updated ClearCanvas Function:
function ClearCanvas(sColour) {
DebugMessage("Clear Canvas");
const context = oCanvas.getContext('2d');
// Clear the canvas
context.clearRect(0, 0, oCanvas.width, oCanvas.height);
// Set the background color
oCanvas.style.background = sColour; // Update the canvas background
}
A few things to be kept in mind
I hope it will help others to get rid of these problem