最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - SVG numberOfItems property not working - Stack Overflow

programmeradmin0浏览0评论

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!!

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!!

Share Improve this question edited Feb 2, 2016 at 15:57 Robert Longson 125k27 gold badges267 silver badges253 bronze badges asked Jan 31, 2016 at 22:58 Juanbi BerrettaJuanbi Berretta 1155 bronze badges 5
  • Check the value of segs in debugger. – pratikpawar Commented Jan 31, 2016 at 23:24
  • Their is a working draft that's being implemented at the moment around SVG 'path' elements. It's possible their is a bug (svgwg/svg2-draft/paths.html#InterfaceSVGPathElement). I'd try Canary and see if the issue is present in it or not. – Todd Moore Commented Jan 31, 2016 at 23:28
  • Unrelated: don't omit ;s. This will bite you. Hard. – jcaron Commented Feb 1, 2016 at 0:15
  • See stackoverflow./questions/34919405/svgpathdata-chrome-48 – Robert Longson Commented Feb 1, 2016 at 2:44
  • This issue was solved in svg.js as soon as it was known (released 30.11.2015). So you just have to update your version – Fuzzyma Commented Feb 14, 2016 at 21:27
Add a ment  | 

1 Answer 1

Reset to default 9

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

发布评论

评论列表(0)

  1. 暂无评论