Test case details

Preparation Code

var c = document.createElement('canvas');     c.width = 1700;     c.height = 1000;         var ctx = c.getContext('2d');     ctx.fillStyle = '#000';     ctx.fillRect(0, 0, 1700, 1000);         var fill, global;
    var p = ctx.getImageData(0, 0, 1, 1);     if (p.data[3] != 0) throw ("canvas did not clear!");

Test cases

Test #1

ctx.clearRect(0, 0, c.width, c.height);  

Test #2

global = ctx.globalCompositeOperation; fill = ctx.fillStyle; ctx.globalCompositeOperation = 'copy'; ctx.fillStyle = 'rgba(0,0,0,0)'; ctx.fillRect(0, 0, c.width, c.height); ctx.globalCompositeOperation = global; ctx.fillStyle = fill;

Test #3

c.width = c.width;

Test #4

// Store the current transformation matrix ctx.save(); // Use the identity matrix while clearing the canvas ctx.setTransform(1, 0, 0, 1, 0, 0); ctx.clearRect(0, 0, c.width, c.height); // Restore the transform ctx.restore();  

Test #5

ctx.putImageData(ctx.createImageData(c.width, c.height), 0, 0); // clear context by putting empty image data

Test #6

// Use the identity matrix while clearing the canvas ctx.setTransform(1, 0, 0, 1, 0, 0); ctx.clearRect(0, 0, c.width, c.height); // Restore the transform ctx.setTransform(1, 0, 0, 1, 0, 0);