ten1seven / what-input

A global utility for tracking the current input method (mouse/pointer, keyboard or touch).
https://ten1seven.github.io/what-input
MIT License
1.35k stars 89 forks source link

IE11 - Unable to get property 'length' on classList #69

Closed thebuilder closed 6 years ago

thebuilder commented 6 years ago

I'm using Sentry to monitor a site, and it's been giving me this error a few times in IE11:

TypeError: Unable to get property 'length' of undefined or null reference
  at y(./node_modules/what-input/dist/what-input.js:253:0)

The sourcemap points to the issue being inside this method, e.g. accessing length on classList.

      var setElement = function setElement(event) {
        currentElement = event.target.nodeName.toLowerCase();
        docElem.setAttribute('data-whatelement', currentElement);

        if (event.target.classList.length) {
          docElem.setAttribute('data-whatclasses', event.target.classList.toString().replace(' ', ','));
        }
      };

A quick google reveals that classList is not supported on SVG elements in IE 11, which could cause this issue. Would it make sense to add a simple check to ensure that classList exists before trying to use it?