9

My lightning component (V40/SU17) errors out when accessed via MS Edge with LockerService enabled. Is there a different method of accessing the window.location?

WindowLocation.cmp

<aura:component implements="forceCommunity:availableForAllPageTypes" access="global" >
    <aura:attribute name="url" type="String" />
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <p>{!v.url}</p>
</aura:component>

WindowLocationController.js

({
    doInit : function(component, event, helper) {
        component.set("v.url", window.location.href);
    }
})

WindowLocationDemo.app

<aura:application >
    <c:WindowLocation />
</aura:application>

Here's the error when viewed in MS Edge

enter image description here

This page has an error. You might just need to refresh it. Action failed: c:WindowLocation$controller$doInit [WeakMap.prototype.set: 'key' is not an object] Failing descriptor: {c:WindowLocation$controller$doInit}

1
  • I am facing the same problem. When I load jquery2.2.4 in to lightning component and try to open a component page, I got this error from the jquery library, since in the library they are using windows.location. Do you have a work around for this problem?
    – bluecat
    Commented Jul 24, 2017 at 21:54

4 Answers 4

6

Just verified that this is the behavior we see too. It appears to be a bug in MS Edge. See related discussion and link to MS Edge bug. https://github.com/emberjs/ember.js/issues/15249 https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/12112572/

8
  • I'll remove my answer, since it's incorrect. Thanks for the info!
    – sfdcfox
    Commented Jun 1, 2017 at 20:24
  • 1
    What did you think it was originally, @sfdcfox?
    – Jan J
    Commented Jun 2, 2017 at 20:05
  • @jmrjulian I thought it was a bug with LS. This answer says it's a browser bug, which makes sense.
    – sfdcfox
    Commented Jun 2, 2017 at 21:33
  • Does anybody know any temporary workaround or any alternative way for this?
    – Sarang
    Commented Sep 7, 2017 at 12:32
  • ^ bump. Could it be an issue with how redirects are implemented such that a workaround is linking to a URL in a different way? Commented Sep 11, 2017 at 17:16
0

Instead of using window.location.href , you can just define an attribute in your component

    <aura:component implements="forceCommunity:availableForAllPageTypes" access="global" > <aura:attribute name="url" type="String" /> <aura:handler name="init" value="{!this}" action="{!c.doInit}" /> <p>{!v.url}</p>
<aura:attribute name ="url" type="String"/>
 </aura:component

>

And also add an attribute to push URL variable from your lightning app and set in your component.

    <aura:application >
<aura:attribute name ="url" type="String"/>
 <c:WindowLocation  url="{!v.url}/>
 </aura:application>

*I've used this approach to get URL parameters and instead of splitting URL from getting it using location.href. while in your case you can try to get URL using $A.get('$Resource.SLDSv2') *

0

If you use window.location or location.href or anything to do with the window location object, there is a good chance Lightning will throw this error back at you - [WeakMap.prototype.set: 'key' is not an object].

If you wish to fetch the URL, use document.URL.

If you wish to set the URL (redirect), use document.location = https://your-url.com.

These 2 solutions for getting and fetching the URL should work in all browsers, so you do not need to do any browser / feature detection and write separate code for separate browsers.

-1

Use "window.document.URL" instead of "window.location". That was the only way I could solve a similar problem.

You must log in to answer this question.

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