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.
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.
2 · Base value, not CSS or animation
3 · Migrating off SVGPathSegList and the polyfill
// 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.