<svg style="display: block; width: 0; height: 0">
<defs>
<filter id="floodFilter">
<feFlood x="0" y="0" width="100" height="100" flood-color="rgb(255,0,0)"/>
</filter>
</defs>
</svg>
<canvas id="canvas" width="100" height="100"></canvas>
<script>
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var feFlood = document.getElementById("floodFilter").firstElementChild;
ctx.filter = 'url(#floodFilter)';
feFlood.setAttribute("flood-color", "rgb(0,255,0)");
ctx.filter = 'url(#floodFilter)';
ctx.fillRect(10, 10, 10, 10);
</script>