2

I have some html/js code I want to display in a utility bar item, and I want to be able to run the Utility Bar API on some events that occur in the js code. The html includes me importing a js file I am storing as a static resource.

The problem seems to be that:

  • You can only run the utility bar api in an aura component
  • You cannot use script tags in aura components

I was able to use ltng:require to include the static resource, but I couldn't access the code from the controller code (the static resource populates a property on the window object, which I couldn't access from the controller for some reason.

Am I missing something here? Is it possible to accomplish this? It seems strange that I wouldn't be able to.

5
  • ltng:require is the correct method; if you're having a problem with the static resource, it might be worth asking a separate question about it. In the general sense, you can indeed attach things to "window" and have them accessible in your main script.
    – sfdcfox
    Sep 1, 2021 at 1:22
  • Will ask another question but here is what is breaking: var global = this; console.log(global.x);. It breaks on the second line of code there.
    – Lee
    Sep 1, 2021 at 15:24
  • It looks like this is because the code is executed in strict mode. (note: the lines of code i pasted are wrapped in an iffe)
    – Lee
    Sep 1, 2021 at 15:31
  • Yes, scripts are always executed in strict mode. You may need to modify it to be strict-mode compatible, or find an alternative that is.
    – sfdcfox
    Sep 1, 2021 at 15:34
  • Unfortunately refactoring the library to use strict mode would be a big effort, and there are no other alternative libraries. Are there any workarounds here that you know of?
    – Lee
    Sep 1, 2021 at 15:44

1 Answer 1

0

You'll need to use a non-strict environment to get this to work without refactoring the original script. In Aura, you could use a lightning:container or Visualforce page in an iframe to host the script. Some additional "boilerplate" code will be necessary to interface the script to the component.

1
  • Thanks for the options, but the visualforce page still ran in strict mode unfortunately, and the lightning:container didn't work either (unless if i am missing something). I posted a new question here: salesforce.stackexchange.com/questions/355677/…
    – Lee
    Sep 1, 2021 at 22:00

You must log in to answer this question.

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