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

176
Views
Why don't I get client.postMessage on the client?

I have this code in my service worker:

messaging.onBackgroundMessage(function (payload) {
  console.log("onBackgroundMessage email and contact_link:");
  console.log(payload.data.email,payload.data.contact_link);

  self.clients.matchAll().then(clients => {
    clients.forEach(client => client.postMessage({
      msg: "This is a message from the SW",
      email: payload.data.email,
      contact_link: payload.data.contact_link
    }));
})
});

I have this code on the client:

navigator.serviceWorker.addEventListener('message', payload => {
  console.log("Message from ServiceWorker");
  console.log(payload.data.msg, payload.data.email, payload.data.contact_link);
});

I get the data properly on the console from the service worker, however the client's console says all the data is undefined. Why is that, what am I doing wrong?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I still do not know why it does not work, but I used this code on the server:

const channel = new BroadcastChannel('sw-messages');
channel.postMessage(payload.data);

And this code on the client instead:

const channel = new BroadcastChannel('sw-messages');
channel.addEventListener('message', event => {
    console.log('Received:', event.data);
});

It works well.

about 4 years ago · Juan Pablo Isaza Report
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!