Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

90
Views
Messageports does not post Message

I have a webworker which does some long computing. to be able to get the Progress of the worker I want to send the progress from the webworker via MessageChannel to the main script. so in the main file I start and listen to the webworker like that.

var channel=new MessageChannel();
sunAnalysisWorker.onmessage = function (e) {
  console.log("messageport message", e.ports)
  setSensorValues(e.data)
}


  sunAnalysisWorker.postMessage({
    meshPlanes: meshPlanesTransferable,
    sceneMesh: inputContextCopy,
    scenarioMesh: inputScenarioCopy,
    hours: hours,
    days: days,
    months: months,
    rays: {
      origins,
      directions,
    },
  },[channel.port1]))

the webworker looks like that:

self.addEventListener(
  'message',
  async function (e) {

      let normalizedValues = 0
   // do a lot of work ---> 
    e.ports[0].postMessage("test")
    self.postMessage(normalizedValues)
  }
)

doing that gives me two Problems I don't know how to solve:

  1. I do not get a response in the main file in the console log e.ports (it is an empty array)
  2. I can only run this once. running it a second time (its in a react component) gives me that error:

Uncaught DOMException: Failed to execute 'postMessage' on 'Worker': Port at index 0 is already neutered.

so there is something quite wrong, but I cannot figure out what. is there anyone with an idea? Thank you so much!

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!