0

I am trying to use an external JS library for feedback purpose. When I use the library in a VF page using <script> tag by including src="js URL", it works well and I can inspect and see the library.

VF code

<script type="text/javascript" src="https://feedback.smg.com/etrackjslibrary" async="true"></script>
    <apex:includeLightning />
    <div id="LightningComponentid" />
    <script>
$Lightning.use("c:LWCApp", function () {
            $Lightning.createComponent("c:MainPage",
                {
                    "name" : name
                },
                "lwcId",
                function (cmp) {
                });
        });
    </script>

We have embedded LWC inside the VF page and LWC Parent contains a number of child components, Now the ask is to enable the external js library only on a specific child component, so I have made below changes

  1. Removed script tag from VF page.
  2. Created static resource and added js in it.
  3. Child component changes

Parent Component

<template>
<c-childLWC>
</template>

Child Template

<template>
    <div lwc:dom="manual"></div>
{template code}
</template>

Child JS

import { loadScript } from 'lightning/platformResourceLoader';
import surveyFeedback from '@salesforce/resourceUrl/surveyFeedback';

renderedCallback() {
      console.log('inside renderedCallback');
      Promise.all([
          loadScript(this, surveyFeedback)
      ]).then(() => {
          console.log('Feedback called');
      }).catch(error => {
          console.log('Error loading feedback', error);
      });
  }

When navigated to the child component and inside renderedCallback it always goes to catch block and throws error as undefined.

Firefox Network screenshot enter image description here

When using in VF page, the js gets executed by including the script tag and I can see the button which the js adds in the inspector. enter image description here

9
  • there isin't much we can do with the amount of information you have shared, please make sure you include a minimum viable code sample for others to reproduce, and more details on the code.
    – glls
    Commented Feb 9, 2022 at 18:22
  • @glls - Updated the question with more details.
    – Rohit
    Commented Feb 9, 2022 at 19:09
  • are you 100% sure that the path of your script is the right one? and that it is not something like surveyFeedback/fileName.js or something within those lines?
    – glls
    Commented Feb 9, 2022 at 19:16
  • Yes, I am sure of the path, the js has been directly uploaded in the static resource
    – Rohit
    Commented Feb 9, 2022 at 19:23
  • @glls - Tried already without Promise.all, still same. Checked the browser network, I don't see the script name in chrome & incognito both, but in firefox I can see it with status code 200
    – Rohit
    Commented Feb 9, 2022 at 19:45

0

You must log in to answer this question.

Browse other questions tagged .