Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVG numberOfItems property not working

Our website suddenly stopped working on Chrome (just chrome) after the latest update...

The error given is

Uncaught TypeError: Cannot read property 'numberOfItems' of undefined

This is where the numberOfItems property is used:

// Absolutize and parse path to array
  , parse: function(array) {
      /* if it's already is a patharray, no need to parse it */
      if (array instanceof SVG.PathArray) return array.valueOf()

      /* prepare for parsing */
      var i, il, x0, y0, x1, y1, x2, y2, s, seg, segs
        , x = 0
        , y = 0

      /* populate working path */
      SVG.parser.path.setAttribute('d', typeof array === 'string' ? array : arrayToString(array))

      /* get segments */
      segs = SVG.parser.path.pathSegList


      for (i = 0, il = segs.numberOfItems; i < il; ++i) {
        seg = segs.getItem(i)
        s = seg.pathSegTypeAsLetter
etc. (I didn't put the whole loop)

Why did SVG and Javascript stop being able to read this property after the latest Chrome update? What could be a good fix?

Thanks!!

like image 890
Juanbi Berretta Avatar asked Jan 31 '16 22:01

Juanbi Berretta


1 Answers

Chrome removed the pathSeg interface in version 48.

There's more information in their public issue tracker

There's also an issue tracking the implementation of the replacement API in the meantime there are polyfills available to reinstate support for the old API

like image 88
Robert Longson Avatar answered Oct 26 '22 15:10

Robert Longson