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

118
Visualizações
Why Shouldn't WebExtensions runtime.onMessage.addListener Function be Async?

I'm new to writing browser extensions and am working on some changes to a Firefox extension. While reading the documentation for browser.runtime.onMessage.addListener() I came across this note:

Note: If you pass an async function to addListener(), the listener will return a Promise for every message it receives, preventing other listeners from responding:

// don't do this
browser.runtime.onMessage.addListener(
  async (data, sender) => {
    if (data.type === 'handle_me') { return 'done'; }
  }
);

Despite this, however, async addListener() functions seem to be used somewhat commonly from what I can tell (at least, I've seen them in code for widely-used and well-known extensions as well as in examples provided by people on various forums threads, etc.).

Can somebody provide some details on why this should be avoided and/or whether it is only a problem in certain scenarios? It says returning a Promise for every message received will prevent other listeners from responding... does that mean this is only an issue if you have multiple listeners attached? Or is it something that should always be avoided no matter what?

Any insight is appreciated!

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