The problem line is in the handleLineEnd function.
I ripped off all the lines not necessary to show the problem.
Without the line: I can draw multiple rectangles on the ctx.
With the line: Each rectangle is overwritten by the next rectangle.
The code runs fine in older Chrome (118.0.5993.71) vs not working in version 119.0.6045.106
function handleLineEnd(evt) {
{
startDrawing = false;
var dummy = ctx.getImageData(3, 3, 5, 5); // problem line
ctx.drawImage(canvaslayer, 0, 0);
ctxlayer.clearRect(0, 0, el.width, el.height);
}
}
var el = document.getElementById("canvasID");
var elcontainer = document.getElementById("containerID");
var ctx = el.getContext('2d');
var startpuntX, startpuntY, eindpuntX, eindpuntY;
var startDrawing = false;
var container = el.parentNode; // Add the temporary canvas.
var containerHandletje = document.getElementById('containerID');
var ongoingTouches = new Array();
var huidigeKleur = 'black';
var huidigeDikte = 2;
var selectie = document.getElementById('drawingtoolID');
elcontainer.setAttribute("style", 'width: ' + (window.innerWidth - 12) + 'px; height: ' + (window.innerHeight - 80) + 'px; overflow: auto;');
el.height = window.innerHeight - 90;
el.width = window.innerWidth - 42;
canvaslayer = document.createElement('canvas');
canvaslayer.id = 'imageTemp';
canvaslayer.width = el.width;
canvaslayer.height = el.height;
canvaslayer.style = 'touch-action:none;';
container.appendChild(canvaslayer);
ctxlayer = canvaslayer.getContext('2d');
ctxlayer.lineCap = 'round';
ctx.lineWidth = 1;
ctx.lineJoin = 'round';
ctx.lineCap = 'round';
ctx.fillStyle = 'white'
ctx.fillRect(0, 0, el.width, el.height);
ctx.lineWidth = huidigeDikte;
canvaslayer.addEventListener('pointerdown', handleLineStart, false);
canvaslayer.addEventListener('pointerup', handleLineEnd, false);
canvaslayer.addEventListener('pointermove', handleLineMove, false);
function handleLineStart(evt) {
startpuntX = evt.clientX - el.offsetLeft + pageXOffset + containerHandletje.scrollLeft;
startpuntY = evt.clientY - container.offsetTop + pageYOffset + containerHandletje.scrollTop;
ctxlayer.lineWidth = huidigeDikte;
ctxlayer.strokeStyle = huidigeKleur;
ctxlayer.fillStyle = huidigeKleur;
startDrawing = true;
ctxlayer.stroke();
ctxlayer.beginPath();
handleLineMove(evt);
}
function handleLineMove(evt) {
var x, y, w, h, hokDx, xi, yi, asX, asY, asXeind, asYeind, fontsize, dzx, dzy, situatie;
if (startDrawing) {
eindpuntX = evt.clientX - el.offsetLeft + pageXOffset + containerHandletje.scrollLeft;
eindpuntY = evt.clientY - container.offsetTop + pageYOffset + containerHandletje.scrollTop;
ctxlayer.clearRect(0, 0, el.width, el.height);
ctxlayer.beginPath();
ctxlayer.moveTo(startpuntX, startpuntY);
x = Math.min(startpuntX, eindpuntX);
y = Math.min(startpuntY, eindpuntY);
w = Math.abs(startpuntX - eindpuntX);
h = Math.abs(startpuntY - eindpuntY);
ctxlayer.strokeRect(x, y, w, h);
ctxlayer.stroke();
ctxlayer.beginPath();
}
}
function handleLineEnd(evt) {
{
startDrawing = false;
var dummy = ctx.getImageData(3, 3, 5, 5); // problem line
ctx.drawImage(canvaslayer, 0, 0);
ctxlayer.clearRect(0, 0, el.width, el.height);
}
}
#containerID {
position: relative;
}
#canvasID {
border: 1px solid #000;
}
#imageTemp {
position: absolute;
top: 1px;
left: 11px;
}
<div id="containerID" style="touch-action:none; width: 100px; height: 500px; overflow: auto;">
<canvas id='canvasID' width='80' height='80' style='margin-left:10px;background:white;border:solid black 1px; touch-action:none; '>
Your browser does not support canvas element.
</canvas>
</div>

getImageDatashould not affect subsequent render calls. I could reproduce bug on Chrome V119.0.6045.160 (64-bit) Win11. Note when I moved the last 3 lines ofhandleLineEndto bottom ofhandleLineMovethe bug disappeared if one dragged a box for about a second. BTW you don't need any of the callsctxlayer.stroke(,ctxlayer,.beginPath(, orctxlayer.moveTo(they do nothing (Nor do they affect the bug)