1

When LockerService is enabled, execute the following code:

var test = document.createElement('script');
test.setAttribute('data-field-test', 'myTest');
console.log(test.dataset);

The test.dataset is undefined.

Try the same with a div element instead of a script tag. It works. Try the same without LockerService enabled, it works.

I know you cannot inject script in LockerService to be executed, but at least, we should be able to use the script tag like any other DOM Element.

Any one have any workaround?

3

The workaround is to use getAttribute(), for example test.getAttribute("data-field-test") which might be a little cumbersome if you want to get the entire set of data attributes on the element.

The underlying cause seems to be this: SecureScriptElement does not have a dataset property defined on it. On the other hand SecureElement has it defined. I will file a bug on our team to investigate if we can allow reading of "dataset" attribute on SecureScriptElement. Certainly SecureScriptElement is one of objects that has a very locked down api cause of security.

  • Thanks Ravi! The solution kind of don't work for me because I don't have the data attributes names in advance. A customer can put whatever field he wants in the data-field-XYZ. – Marc-Antoine Veilleux Feb 27 '17 at 14:18
  • Also @RaviJayaramappa , could you give me your bug tracking number. Thanks! – Marc-Antoine Veilleux Feb 27 '17 at 14:31
  • Ravi is on holiday and I just saw this - here is the bug W-3538484 tracking this work. – Doug Chasman Feb 28 '17 at 15:40
  • Thanks @DougChasman! When should we get the full support? Without this fix, I'll have to make multiple hacks (with the associated risk) in my code base for the Summer '17 release. – Marc-Antoine Veilleux Feb 28 '17 at 16:40

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.