4

I have a piece of code in a library that uses the window.Element object. It tries to access it by doing Element.prototype which throws an error of

"cannot read property 'prototype' of undefined"

This only happens with Salesforce LockerService turned on. I would like this to still work while LockerService is still on. I was wondering if anyone has encountered such issue and have a workaround?

Here's a sample code from the library:

var matchesMethod = ( function() {
  //starts to break here
  var ElemProto = Element.prototype;
  // check for the standard method name first
  if ( ElemProto.matches ) {
    return 'matches';
  }
  // check un-prefixed
  if ( ElemProto.matchesSelector ) {
    return 'matchesSelector';
  }
  // check vendor prefixes
  var prefixes = [ 'webkit', 'moz', 'ms', 'o' ];

  for ( var i=0; i < prefixes.length; i++ ) {
    var prefix = prefixes[i];
    var method = prefix + 'MatchesSelector';
    if ( ElemProto[ method ] ) {
      return method;
    }
  }
})();

UPDATE: Adding a screenshot of what's currently available on the window object.

enter image description here

  • 1
    As per the Locker Service API docs looks like window.element should be supported .Sounds like a bug to me .documentation.auraframework.org/lockerApiTest/… – Mohith Shrivastava Oct 19 '16 at 0:58
  • Thanks @MohithShrivastava yeah, afterScriptsLoaded, I added a debugger to see what window.Element or Element would return and it's undefined. – kev_panda Oct 19 '16 at 16:18
3

We have added support for window.Element in the Spring'17 release. We are currently working on bringing it to Winter'17 release as well.

  • [Update]This should be fixed now. Please try you scenario and let us know if its still broken. – Ravi Jayaramappa Oct 28 '16 at 17:07
  • I'm still getting this error in my browser console. Pls advise how to fix it. – JJSHHS Aug 30 '17 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.