1
votes

I have written basic code in lwc js and it's not working any help would be appreciated.

here's my code -

////main js.

   var worker = new Worker("/resource/webWorker");
      worker.onmessage = function(e) {
        alert('Message received from worker: ' + e.data);
    };
    worker.postMessage([2, 3]);

//// webWorker js.

onmessage = function(e) {
  console.log('Message received from main script');
  var workerResult = 'Result: ' + (e.data[0] * e.data[1]);
  console.log('Posting message back to main script');
  postMessage(workerResult);
}
1
what is your error?charly1212

1 Answers

0
votes

I wouldn't have much hope, https://developer.salesforce.com/docs/component-library/tools/locker-service-viewer search for "worker", says it's not supported.

What do you need the worked for? Check if you upload your React app as "static resource" and then reference it on page using lightning:container. It'd have to be Aura component though, I don't see LWC version. Effectively on the page it'll be shown in iframe. You could achieve similar thing with Visualforce.

If you need the worked to make calls to 3rd party APIs - see if you can make the callout from Apex (server-side code) and then use that in your component (@wire for example).