Search code examples
javascriptgoogle-chromecanvaspathfill

Why does the canvas context.fill(path) not work on Chrome?


This code would have worked on Chrome until recently.

    var canvasB=document.getElementById('b');
    var contextB=canvasB.getContext("2d");
    contextB.width=50;
    contextB.height=50;
    contextB.beginPath();
    contextB.fillStyle="#0A0";
    contextB.fill(contextB.arc(25,25,24,0,7,0));

Notice within the fill method the path is specified to draw a circle. According to whatwg.org this is acceptable. The solution to put the path on it own line and just use fill() without any arguments.

    var canvasA=document.getElementById('a');
    var contextA=canvasA.getContext("2d");
    contextA.width=50;
    contextA.height=50;
    contextA.beginPath();
    contextA.fillStyle="#0A0";
    contextA.arc(25,25,24,0,7,0);
    contextA.fill();

Still why did this stop working or what am I doing wrong?


Solution

  • The fill(Path) argument is not (yet) supported on any released browser.

    It should have never worked. That Path stuff in the WHATWG spec is new as of March 2013 and no browser has implemented the independent Paths yet.

    It's possible (but unlikely) that a mistaken development implementation made that feature possible for a short while, but it does not work right now, even on nightly. You'll get the appropriate type error instead.