<svg style="display: block; width: 0; height: 0">
<defs>
<filter id="grayscale">
<feColorMatrix type="matrix" values="0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0"/>
</filter>
</defs>
</svg>
<canvas id="canvas" width="100" height="100"></canvas>
<script>
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
ctx.filter = 'url(#grayscale)';
ctx.fillStyle = '#0f0';
ctx.fillRect(20, 20, 20, 20);
ctx.filter = 'none';
ctx.fillRect(60, 20, 20, 20);
</script>