v160 · dom · svg

Validation & base value

The parts that surprise people. setPathData() follows SVG’s “render what you can” rule: a bad segment does not throw, it ends the path, and the browser keeps the valid prefix. Only a structurally broken argument (a missing type or values, or something that is not a sequence) is a TypeError. And all three methods read the d attribute’s base value, so CSS d: path() and SMIL animation never show up in what they return.

Chrome 160+ ships this by default. Earlier Chrome/Canary: enable chrome://flags/#enable-experimental-web-platform-features, or launch with --enable-blink-features=SVGPathDataAPI (also --enable-features=SVGPathDataAPI or --enable-experimental-web-platform-features).
Probing this browser…

1 · What does setPathData() keep?

Each case runs against a fresh <path d="M 0 0 L 5 5"> and reports whether it threw, then reads back getAttribute("d"). The “expected” line is Chromium’s implementation as read in svg_path_segments_source.cc (main, November 2026), so you can see where a given build agrees or not.

    Run a case to see what the browser kept.

    2 · Base value, not CSS or animation

    The test path. Its d attribute is a triangle; CSS or SMIL may render something else.
    The attribute says triangle. Override it, then compare what renders with what getPathData() returns.

    3 · Migrating off SVGPathSegList and the polyfill

    Probing…
    // load path-data-polyfill only where the native API is missing
    if (!("getPathData" in SVGPathElement.prototype)) {
      await import("/vendor/path-data-polyfill.js");
    }
    
    // old SVGPathSegList code (removed in Chrome 48):
    //   path.pathSegList.appendItem(path.createSVGPathSegLinetoAbs(90, 10));
    // new: plain objects, one write
    const segs = path.getPathData();
    segs.push({ type: "L", values: [90, 10] });
    path.setPathData(segs);

    The native API takes the same {type, values} shape as the polyfill, so polyfill-era code keeps working. Firefox 137 briefly required real SVGPathSegment instances; 138 switched to plain dictionaries (bug 1954044), and Chromium uses a dictionary from the start, so there is no window.SVGPathSegment constructor.

    see also