Browser canvas size is overwritten

Author: siikasmaaCreated Feb 26, 2025Updated Mar 11, 2026

When rendering the QR code on a canvas in the browser the existing canvas size is overwritten. This is problematic when rendering more than the QR code in the canvas.

In the file lib/renderer/canvas.js:

function clearCanvas (ctx, canvas, size) {
  ctx.clearRect(0, 0, canvas.width, canvas.height)

  if (!canvas.style) canvas.style = {}
  canvas.height = size
  canvas.width = size
  canvas.style.height = size + 'px'
  canvas.style.width = size + 'px'
}

The function clearCanvas should conditionally set the size for the canvas.