6

When calling window.onload() and LockerService is enabled, I get this error:

aura_proddebug.js:17569 Uncaught TypeError: Cannot use 'in' operator to search for 'target' in undefined
    at Function.LockerService.SecureObject.$createFilteredProperty$ (https://sitepreview.na40.force.com/clean/s/sfsites/auraFW/javascript/2udAo9HXlgsMA3tZDXLDsg/aura_proddebug.js:17569:23)
    at SecureDOMEvent (https://sitepreview.na40.force.com/clean/s/sfsites/auraFW/javascript/2udAo9HXlgsMA3tZDXLDsg/aura_proddebug.js:16553:58)
    at raw.(anonymous function) (https://sitepreview.na40.force.com/clean/s/sfsites/auraFW/javascript/2udAo9HXlgsMA3tZDXLDsg/aura_proddebug.js:17696:41)
    at Object.SecureFunction (https://sitepreview.na40.force.com/clean/s/sfsites/auraFW/javascript/2udAo9HXlgsMA3tZDXLDsg/aura_proddebug.js:17377:35)
    at eval (eval at evaluate (:85:21), <anonymous>:1:8)
    at onScriptLoaded (components/c/JsSearchTest.js:11:9)
    at Action.$runDeprecated$ (https://sitepreview.na40.force.com/clean/s/sfsites/auraFW/javascript/2udAo9HXlgsMA3tZDXLDsg/aura_proddebug.js:8699:36)
    at Object.Component$getActionCaller [as $handler$] (https://sitepreview.na40.force.com/clean/s/sfsites/auraFW/javascript/2udAo9HXlgsMA3tZDXLDsg/aura_proddebug.js:6879:20)
    at Aura.$Event$.$Event$.$executeHandlerIterator$ (https://sitepreview.na40.force.com/clean/s/sfsites/auraFW/javascript/2udAo9HXlgsMA3tZDXLDsg/aura_proddebug.js:8329:15)
    at Aura.$Event$.$Event$.$executeHandlers$ (https://sitepreview.na40.force.com/clean/s/sfsites/auraFW/javascript/2udAo9HXlgsMA3tZDXLDsg/aura_proddebug.js:8307:8)
    at https://sitepreview.na40.force.com/clean/s/sfsites/auraFW/javascript/2udAo9HXlgsMA3tZDXLDsg/aura_proddebug.js:8359:10
    at AuraInstance.$run$ (https://sitepreview.na40.force.com/clean/s/sfsites/auraFW/javascript/2udAo9HXlgsMA3tZDXLDsg/aura_proddebug.js:18763:12)
    at Aura.$Event$.$Event$.$fire$ (https://sitepreview.na40.force.com/clean/s/sfsites/auraFW/javascript/2udAo9HXlgsMA3tZDXLDsg/aura_proddebug.js:8357:6)
    at Object.fireAfterScriptsLoaded (https://sitepreview.na40.force.com/components/ltng/require.js:117:48)
    at Object.injectScript (https://sitepreview.na40.force.com/components/ltng/require.js:109:17)
    at Object.<anonymous> (https://sitepreview.na40.force.com/components/ltng/require.js:153:20)
    at https://sitepreview.na40.force.com/clean/s/sfsites/auraFW/javascript/2udAo9HXlgsMA3tZDXLDsg/aura_proddebug.js:16754:24
    at Array.forEach (native)
    at XMLHttpRequest.xhr.onreadystatechange (https://sitepreview.na40.force.com/clean/s/sfsites/auraFW/javascript/2udAo9HXlgsMA3tZDXLDsg/aura_proddebug.js:16753:23)

I think it's a regression because we were able to call window.onload() to run the Jasmine framework. Check this file from this github project.

Anything I can do to simulate an onload event on window without changing the Jasmin Implementation?

2
  • Please note that this is intended to be a simple POC and uses vanilla versions of the corresponding test libraries. Tntent was to see what is possible on the lightning platform without any customization to the libraries. Mocha/Jasmine are not LockerService compliant out of the box, so the POC only works with LockerService disabled. Lightning Test Service MVP should support/run with LockerService. From git bub
    – Suresh
    Mar 15, 2017 at 19:59
  • Ok, it doesn't change the fact that window.onload() doesn't work. Mar 16, 2017 at 16:13

2 Answers 2

0

Here you can see with third parties libraries are compatible with locker service, or do not give problems

LockerService and Lightning Container Component: Securely Using Third-Party Libraries in Lightning Components

EDIT:

In the project in which I work, I've not been able to execute jquery mobile with the locker service on, except for a few methods. So if the library you want to use is based on some of these libraries, try to just include the methods you are going to use, but does not guarantee that they work.

Compatible 3rd party js libraries:

React --> 0.14.8 ChartJS --> 2.1.4 D3 --> 4.4.0 Leaflet --> 0.7.7 / 1.0.2 RxJS --> Latest as of 12/5/16 Numeral.js --> 2.1.4 Underscore.js --> 1.8.3 FullCalendar --> 3.1.0 Gauge.js --> 1.2.1 jQuery -->2.2.2 and 2.2.4 jQuery UI -->1.11.4 DataTables -->1.10.12 Select2 --> 4.0.3

1
  • 2
    If this link answers the question, can you cite some of the relevant content here? Links can go dead over time, so a good answer will stand on its own even if the link stops working.
    – Adrian Larson
    Jun 14, 2017 at 13:14
0

I don't know about Jasmine framework. But there is some alternate of window.onLoad() in lightning framework.

This event is automatically fired if no more components need to be rendered or rerendered due to any attribute value changes. The aura:doneRendering event is handled by a client-side controller. A component can have only one tag to handle this event.

<aura:handler event="aura:doneRendering" action="{!c.doneRendering}"/>

For example, you want to customize the behavior of your app after it’s finished rendering the first time but not after subsequent rerenderings. Create an attribute to determine if it’s the first rendering.

<aura:component>
    <aura:handler event="aura:doneRendering" action="{!c.doneRendering}"/>
    <aura:attribute name="isDoneRendering" type="Boolean" default="false"/>
    <!-- Other component markup here -->
    <p>My component</p>
</aura:component>

This client-side controller checks that the aura:doneRendering event has been fired only once.

({
   doneRendering: function(cmp, event, helper) {
    if(!cmp.get("v.isDoneRendering")){
      cmp.set("v.isDoneRendering", true);
      //do something after component is first rendered
    }
  }
})

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_aura_doneRendering.htm

You must log in to answer this question.

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