Setup:
Visualforce Page using lightning out
<apex:page id="Js_Examples" standardStylesheets="false" showHeader="false" sideBar="false"> <apex:includeLightning/> <script> $Lightning.use("c:JS_App", function() { $Lightning.createComponent( "c:JS_Example", { }, "content-div", function(cmp) { var loadingDivElt = document.getElementById("loader"); loadingDivElt.style.display = 'none'; $A.eventService.addHandler({ ....... }); }); }); </script> <div id="content-div"> </div> </apex:page>
Lightning App and Component
App
<aura:application description="JS_App" access="GLOBAL" extends="ltng:outApp">
<aura:dependency resource="c:JS_Example"/>
<aura:dependency resource="markup://force:navigateToURL" type="EVENT"/>
</aura:application>
Component
<aura:component description="JS_Example">
<lightning:spinner size="large" variant="brand"/>
<ltng:require scripts="https://js.braintreegateway.com/js/braintree-2.32.0.min.js"/>
</aura:component>
- CORS and CSP Trusted sites added for both:
https://xxx-dev-ed--c.na30.visual.force.com
https://js.braintreegateway.com
- Lightning Locker service Enabled
When loading the component I get the following error
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://xxx-dev-ed--c.na30.visual.force.com' is therefore not allowed access
Ways it does work
Locker service Disabled keeping
<ltng:require>
on the component- simply disabling locker service works and the resource is loaded
Leave locker service enabled, placing the following on the VF page, and commenting out the
<ltng:require>
<apex:includeScript value="https://js.braintreegateway.com/js/braintree-2.32.0.min.js"/>
So, any idea why I get the No Access origin?
I have reviewed the previous questions containing that message this year and none of them helped.
It is something in this JS and Locker service because jQuery CDN works fine.
So then I guess it boils down to is it a Locker Service Issue or not. Is there any way to load the resource in the component and if not does leaving it on the VF page cause any harm?