Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

211
Visualizações
Can a service worker postMessage() directly to a shared worker client?

In a service worker, the client interface has postMessage() for talking to clients, which can be of type "window", "worker", or "sharedworker".

In "window" clients, the message event is sent to navigator.serviceWorker.controller. Example service worker code:

const windowClients = await clients.matchAll({ type: "window" });
windowClients[0].postMessage('Send this message to window.navigator.serviceWorker.controller');

But in shared worker clients, navigator.serviceWorker does not seem to exist. (This seems to change in a draft spec. Edit: And Safari.)

const sharedWorkerClients = await clients.matchAll({ type: "sharedworker" });
sharedWorkerClients[0].postMessage('Send this message to ???');

So where is the message event dispatched in the shared worker? Or is postMessage() a no-op here?

(There are workarounds like having the document transfer SharedWorker#port to the service worker. I'm wondering if there's a way to send messages directly.)

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda