2

I am new to Lightning. I have created Lightning component and a controller.

Lightning component code:

<aura:component >
<ui:button press="{!c.doInit}">
    <div class="testClass">Click Me</div>
</ui:button>    

Controller:

({
doInit: function(component, event, helper) {
    console.log(window.toString());
    console.log(document.toString());        
    var div = document.querySelector(".testClass");
    console.log(div.toString());
    console.log(div.parentNode.innerHTML);
}

})

But on saving controller, it throws the error: FIELD_INTEGRITY_ERROR

Failed to save LLServiceOnController.js: ESLINT_ERROR: {c:LLServiceOn - CONTROLLER} line:col [3:21] --> Invalid SecureWindow API, toString was blacklisted : Source

how can i rectify this error. Can anybody help me on this!!

2 Answers 2

3

You can't take everything in the window and output it in the console as a string. It's referring to this line:

console.log(window.toString());
2
  • above controller will be saving on 39 version. but why current(43) version getting error. how can i solve this error Commented Jun 20, 2018 at 13:28
  • The issue is because of Locker Service. You're constrained to staying within your own memory space and not trying to get outside of it by touching the larger DOM of the Window. Remove that line and you should be fine.
    – crmprogdev
    Commented Jun 20, 2018 at 14:02
3

The function toString() is exposed on window by Locker Service. The new linting rules are probably too strict, we'll need to double-check.

You can force a toString() by concatenation, something eslint will not catch:

console.log(window + '');

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .